Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/06/2014 in all areas

  1. A while back, a few of us came up with a method to move the MsgBox window and to change button text. It was rather clumsy. I wrote a dll solution for moving the MsgBox to the center of the parent GUI window that owned it for most of my personal work. I decided to port it over to AutoIt rather continue to port the dll with all my AutoIt work, in addition I added the button text changing to the solution as well. The examples should be self explanatory on how to use the functions provided. * Note - I did not take the time to a $MB_OK type of Constant variable, they are there ( eg. $__iMsgBox_IDOK ), but they are designed for internal use only.Example: #include <MsgBoxUDF.au3> #region 3 piece function call ; Regardless of Coords, if a handle is passed, it will center messagebox to window of handle _MsgBox_SetWindowPos(200, 100) ; The same flag passed for buttons 0-6 should be set for both messagebox and setbuttontext _MsgBox_SetButtonText(4, "Button1", "Button2") _MsgBox(4 + 262144, "Title", "Hello World One") Sleep(250) ; See now that it reset back to default _MsgBox(4 + 262144, "Title", "Hello World Two") #endregion 3 piece function call #region stand alone all in one call Sleep(250) ; Change buton 1 to Button1; Move to top left corner of desktop _MsgBoxEx(4 + 262144, "Title", "Hello World Three", -1, -1, "Button1", -1, -1, 0, 0) Sleep(250) ; Center to active window _MsgBoxEx(4 + 262144, "Title", "Hello World Four", -1, WinGetHandle(""), -1, "Button2", -1, 0, 0) #endregion stand alone all in one call MsgBoxUDF.au3
    1 point
  2. I searched around on here for some SQL stuff to use with an MSDE database and I ended up getting confused so I tried to simplfy it a bit, there are only a couple of functions so far but I guess someone may find it usefull. I have a database called test and a table called BBKS This has been totally revamped now and it uses very similar syntax to the SQLITE3 functions included with Autoit3 It will break any scripts that used the previous _SQL.au3 file but the new file is much more user friendly See the example below #include <_sql.au3> #include <array.au3> Opt ("trayIconDebug",1) Msgbox(0,"","Start the Script and load the error handler") _SQL_RegisterErrorHandler();register the error handler to prevent hard crash on COM error $oADODB = _SQL_Startup() If $oADODB = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _sql_Connect(-1,"localhost","","sa","Superartcore") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) _SQL_Close() Exit EndIf If _SQL_Execute(-1,"Create database My_SQL_Test;") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) _SQL_Close() Msgbox(0,"","Created datatbase logging out and back in again") $oADODB = _SQL_Startup() If _SQL_Connect(-1,"localhost","My_SQL_Test","sa","Superartcore") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1, "CREATE TABLE BBKS (ID INT NOT NULL IDENTITY(1,1),ComputerName VARCHAR(20) UNIQUE,Status VARCHAR(10),Error VARCHAR(10)Primary Key (ID));") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('"& @computername & "','On;li''ne','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('1"& @computername & "','On;li''ne','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('2"& @computername & "','Online','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) ; this one will cause an error because the computername is not unique! If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('2"& @computername & "','Online','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error","Example Error this was meant to happen!" & @crlf & @crlf & _SQL_GETErrMsg()) Msgbox(0,"","Created table and added data so lets get some data out first as a 2dArray") Local $aData,$iRows,$iColumns;Variables to store the array data in to and the row count and the column count $iRval = _SQL_GetTable2D(-1,"SELECT * FROM BBKS;",$aData,$iRows,$iColumns) If $iRval = $SQL_OK then _arrayDisplay($aData,"2D (" & $iRows & " Rows) (" & $iColumns & " Columns)" ) Msgbox(0,"","Next as a 1dArray") Local $aData,$iRows,$iColumns;Variables to store the array data in to and the row count and the column count $iRval = _SQL_GetTable(-1,"SELECT * FROM BBKS;",$aData,$iRows,$iColumns) If $iRval = $SQL_OK then _arrayDisplay($aData,"1D (" & $iRows & " Rows) (" & $iColumns & " Columns)" ) Msgbox(0,"","And now the same data returned 1 row at a time") $hData = _SQL_Execute(-1,"SELECT * FROM BBKS;") Local $aNames;Variable to store the array data in to $iRval = _SQL_FetchNames ($hData, $aNames); Read out Column Names If $iRval = $SQL_OK then ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CR) _ArrayDisplay($aNames,"Column Names") Local $aRow;Variable to store the array data in to While _SQL_FetchData ($hData, $aRow) = $SQL_OK; Read Out the next Row ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CR) _ArrayDisplay($aRow,"Single Row of Data") WEnd Msgbox(0,"","And now the same data returned as a string") Local $vString If _Sql_GetTableAsString(-1,"SELECT * FROM BBKS;",$vString) = $SQL_OK then Msgbox(0,"Data as a String",$vString) Else Msgbox(0 + 16 +262144,"SQL Error",_SQL_GetErrMsg() ) EndIf Msgbox(0,"","Now just a single row") Local $aRow;Variable to store the row array data in $iRval = _SQL_QuerySingleRow(-1,"SELECT * FROM BBKS;",$aRow) If $iRval = $SQL_OK then _arrayDisplay($aRow,"1 Row" ) Msgbox(0,"","Now drop the tables and the database") If _SQL_Execute(-1, "DROP TABLE BBKS;") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Close() <> $SQL_OK then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg() ) ;Just being lazy and not putting any error checking in now! $oADODB = _SQL_Startup() _SQL_Connect(-1,"localhost","","sa","Superartcore") _SQL_Execute(-1,"DROP database My_SQL_Test;") _SQL_Close() Msgbox(0,"","Example Finished") Previous downloads: 4176 _SQL.au3 updated with some tweaks by eltorro, CarlH and Elias (Thanks) Updated 28/08/2010 Updated 29/04/2011 _sql_Old.au3 _sql.au3
    1 point
  3. What you mean "open" ? You can try to use ShellExecute( mLipok ps. Welcome to the forum
    1 point
  4. Yes, check the help file for $CmdLine and $CmdLineRaw.
    1 point
  5. Ward

    MsgBoxEx and InputBoxEx

    In my new program, I need custom buttons of system dialog. After search on the internet, I found the way. Instead of using GUICreate, this code just hook the system dialog. The hook type is WH_CBT, See MSDN for more information. Except button text, is there any other interesting thing can be modified ? ; ============================================================================= ; MsgBoxEx And InputBoxEx Examples ; Purpose: Custom Buttons Of System Dialog ; Author: Ward ; ============================================================================= #Include <WinAPI.au3> MsgBoxEx("Button1|Button2", 1, "MsgBoxEx", "Test") MsgBoxEx("|Button3||||Button1|Button2", 3, "MsgBoxEx", "Test") InputBoxEx("Button1|Button2", "InputBoxEx", "Prompt") Func MsgBoxEx($CustomButton, $Flag, $Title, $Text, $Timeout = 0, $Hwnd = 0) Assign("MsgBoxEx:CustomButton", $CustomButton, 2) Local $CBT_ProcCB = DllCallbackRegister("MsgBoxEx_CBT_Proc", "long", "int;hwnd;lparam") Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId()) Local $Ret = MsgBox($Flag, $Title, $Text, $Timeout, $Hwnd) Local $Error = @Error _WinAPI_UnhookWindowsHookEx($CBT_Hook) DllCallbackFree($CBT_ProcCB) Assign("MsgBoxEx:CustomButton", 0, 2) Return SetError($Error, 0, $Ret) EndFunc Func MsgBoxEx_CBT_Proc($nCode, $wParam, $lParam) If $nCode = 5 Then ; HCBT_ACTIVATE Local $CustomButton = StringSplit(Eval("MsgBoxEx:CustomButton"), "|") For $i = 1 To $CustomButton[0] ControlSetText($wParam, "", $i, $CustomButton[$i]) Next EndIf Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam) EndFunc Func InputBoxEx($CustomButton, $Title, $Prompt, $Default = "", $Password = "", $Width = Default, $Height = Default, $Left = Default, $Top = Default, $Timeout = Default, $Hwnd = Default) Assign("InputBoxEx:CustomButton", $CustomButton, 2) Local $CBT_ProcCB = DllCallbackRegister("InputBoxEx_CBT_Proc", "long", "int;hwnd;lparam") Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId()) Local $Ret = InputBox($Title, $Prompt, $Default, $Password, $Width, $Height, $Left, $Top, $Timeout, $Hwnd) Local $Error = @Error _WinAPI_UnhookWindowsHookEx($CBT_Hook) DllCallbackFree($CBT_ProcCB) Assign("InputBoxEx:CustomButton", 0, 2) Return SetError($Error, 0, $Ret) EndFunc Func InputBoxEx_CBT_Proc($nCode, $wParam, $lParam) If $nCode = 5 Then ; HCBT_ACTIVATE Local $CustomButton = StringSplit(Eval("InputBoxEx:CustomButton"), "|") For $i = 1 To $CustomButton[0] ControlSetText($wParam, "", $i, $CustomButton[$i]) Next EndIf Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam) EndFunc
    1 point
  6. trancexx

    Memory compression

    Appears that memory compression is in these days. So, to be in, here is another method. This one is called "Native API Compression". Apparently it's LZ1(LZ77) compression algorithm or something very similar and it's available through one or two dll calls. Of course that files can be compressed too by this method. Functions with small example: #NoTrayIcon $sString = "lzwlzwlzwlzwlzwlzwlzwlzwlzwlzwlzwlzw" ConsoleWrite("Before compression: " & Binary($sString) & @CRLF) $BC = _LZNTCompress($sString) ConsoleWrite("Compressed: " & $BC & @CRLF) $CB = _LZNTDecompress($BC) ConsoleWrite("Decompressed: " & $CB & @CRLF) ; #FUNCTION# ;=============================================================================== ; ; Name...........: _LZNTDecompress ; Description ...: Decompresses input data. ; Syntax.........: _LZNTDecompress ($bBinary) ; Parameters ....: $vInput - Binary data to decompress. ; Return values .: Success - Returns decompressed binary data. ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - Error decompressing. ; Author ........: trancexx ; Related .......: _LZNTCompress ; Link ..........; http://msdn.microsoft.com/en-us/library/bb981784.aspx ; ;========================================================================================== Func _LZNTDecompress($bBinary) $bBinary = Binary($bBinary) Local $tInput = DllStructCreate("byte[" & BinaryLen($bBinary) & "]") DllStructSetData($tInput, 1, $bBinary) Local $tBuffer = DllStructCreate("byte[" & 16 * DllStructGetSize($tInput) & "]") ; initially oversizing buffer Local $a_Call = DllCall("ntdll.dll", "int", "RtlDecompressBuffer", _ "ushort", 2, _ "ptr", DllStructGetPtr($tBuffer), _ "dword", DllStructGetSize($tBuffer), _ "ptr", DllStructGetPtr($tInput), _ "dword", DllStructGetSize($tInput), _ "dword*", 0) If @error Or $a_Call[0] Then Return SetError(1, 0, "") ; error decompressing EndIf Local $tOutput = DllStructCreate("byte[" & $a_Call[6] & "]", DllStructGetPtr($tBuffer)) Return SetError(0, 0, DllStructGetData($tOutput, 1)) EndFunc ;==>_LZNTDecompress ; #FUNCTION# ;=============================================================================== ; ; Name...........: _LZNTCompress ; Description ...: Compresses input data. ; Syntax.........: _LZNTCompress ($vInput [, $iCompressionFormatAndEngine]) ; Parameters ....: $vInput - Data to compress. ; $iCompressionFormatAndEngine - Compression format and engine type. Default is 2 (standard compression). Can be: ; |2 - COMPRESSION_FORMAT_LZNT1 | COMPRESSION_ENGINE_STANDARD ; |258 - COMPRESSION_FORMAT_LZNT1 | COMPRESSION_ENGINE_MAXIMUM ; Return values .: Success - Returns compressed binary data. ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - Error determining workspace buffer size. ; |2 - Error compressing. ; Author ........: trancexx ; Related .......: _LZNTDecompress ; Link ..........; http://msdn.microsoft.com/en-us/library/bb981783.aspx ; ;========================================================================================== Func _LZNTCompress($vInput, $iCompressionFormatAndEngine = 2) If Not ($iCompressionFormatAndEngine = 258) Then $iCompressionFormatAndEngine = 2 EndIf Local $bBinary = Binary($vInput) Local $tInput = DllStructCreate("byte[" & BinaryLen($bBinary) & "]") DllStructSetData($tInput, 1, $bBinary) Local $a_Call = DllCall("ntdll.dll", "int", "RtlGetCompressionWorkSpaceSize", _ "ushort", $iCompressionFormatAndEngine, _ "dword*", 0, _ "dword*", 0) If @error Or $a_Call[0] Then Return SetError(1, 0, "") ; error determining workspace buffer size EndIf Local $tWorkSpace = DllStructCreate("byte[" & $a_Call[2] & "]") ; workspace is needed for compression Local $tBuffer = DllStructCreate("byte[" & 16 * DllStructGetSize($tInput) & "]") ; initially oversizing buffer Local $a_Call = DllCall("ntdll.dll", "int", "RtlCompressBuffer", _ "ushort", $iCompressionFormatAndEngine, _ "ptr", DllStructGetPtr($tInput), _ "dword", DllStructGetSize($tInput), _ "ptr", DllStructGetPtr($tBuffer), _ "dword", DllStructGetSize($tBuffer), _ "dword", 4096, _ "dword*", 0, _ "ptr", DllStructGetPtr($tWorkSpace)) If @error Or $a_Call[0] Then Return SetError(2, 0, "") ; error compressing EndIf Local $tOutput = DllStructCreate("byte[" & $a_Call[7] & "]", DllStructGetPtr($tBuffer)) Return SetError(0, 0, DllStructGetData($tOutput, 1)) EndFunc ;==>_LZNTCompress Available in Microsoft Windows XP and later versions of all Windows operating systems. There is $tBuffer there if you look. I'm oversizing it plenty initially (saw this bad example in c++). Probably should be some better way to do that but documentation for this functions on MSDN is not over yet apparently Two compression rates are available. Default COMPRESSION_ENGINE_STANDARD is lightening speedy. Better compression is gained by COMPRESSION_ENGINE_MAXIMUM which is slower.
    1 point
×
×
  • Create New...