Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/10/2016 in all areas

  1. Your script works for me on Windows 7. Please note that WinWaitActive only works if the Notepad window is actually the window which is currently focused. You might want to use WinWait() instead, which checks all existing windows for the one you're looking for. Example: MsgBox(0,"##Debug##", "script started" ) ShellExecute("Notepad.exe") $h = WinWait("[CLASS:Notepad]", "", 3) ; Wait 3 seconds for the Notepad window to exist If $h = 0 Then MsgBox(0,"##Debug##", "no notepad window") Else Sleep( 2000 ) MsgBox(0,"##Debug##", "notepad window found") EndIf MsgBox(0,"##Debug##", "script ended") Another one using ShellExecute and the Process ID that is returned: Global $ProcessID = ShellExecute("notepad.exe") Global $SecondsToTimeout = 3 Global $ProcessList Global $Timer = TimerInit() While 1 $ProcessList = ProcessList() If TimerDiff($Timer) > $SecondsToTimeout * 1000 Then MsgBox(0,"##Debug##", "nothing found - timeout") Exit EndIf If Not IsArray($ProcessList) Then ContinueLoop For $i = 1 To $ProcessList[0][0] If $ProcessID = $ProcessList[$i][1] Then MsgBox(0,"##Debug##", "process found") Exit EndIf Next WEnd Just to give you some ideas
    2 points
  2. UEZ

    Inline Assembler Snippets

    I will try to maintain this topic by inserting links in the first post (here) to the snippets to keep track of the snippets. My examples are using AndyG's AssembleIt UDF / AssembleIt2 UDF which is here: AssembleIt.au3 (needs FASM.au3 -> see link below (ward)) ;AssembleIt by Andy @ www.autoit.de ;BIG thx to progandy for the "Buttons" in the debugger ;see examples how to call _AssembleIt() ;Listview changed in Debugger 12.05.2012 ;SSE-Register are nor in the right direction (bitwise from right to left) 20.02.2012 ;Debugger included 07.04.2011 ;modified by UEZ 05.03.2015 #include-once #include "FASM.au3" #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> ;#include <GUIListBox.au3> #include <GuiStatusBar.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <array.au3> #include <GuiListView.au3> #include <WinAPI.au3> ;Opt("MustDeclareVars", 1) If @AutoItX64 Then MsgBox(0, "_AssembleIt Error", "Sorry, 64Bit is not supported. Program will be terminated!") Exit EndIf Global $_ASSEMBLEIT_FLAG = 1 Global $Fasm = FasmInit() If @error Then MsgBox(0, "_AssembleIt Error", "Not able to FasmInit! Program will be terminated!") Exit EndIf ; #FUNCTION# ====================================================================================== ; Name ..........: _AssembleIt() ; Description ...: "Wrapper" for the FASM.au3 by Ward ; Syntax ........: _AssembleIt($Returntype, $sFunc, $Type1 = "type", $Param1 = 0, $Type2 = "type", $Param2 = 0.... ; Parameters ....: $Returntype - Data type returned by the assembled program ; $sFunc - Name of the function, in which the Assemblercode is contained ; $sType1 - DataType of Parameter1 ; $sParam1 - Parameter1 ; $sType2 - DataType of Parameter2 ; $sParam2 - Parameter2.....and so on, you can pass up to 20 parameters ; ; Return values .: Success depends on $Returntype @error=0 ; Failure @error = -2 FasmReset has failed ; Failure @error = -3 Error in Assemblercode detected by Fasm ; Failure @error = -4 Function with Assemblercode doesn´t exist (i.e. wrong functionname) ; Failure @error = -5 Error while executing MemoryFuncCall ; ; Author ........: Andy @ www.autoit.de ; Modified ......: ; Remarks .......: _AssembleIt() instructs MemoryFuncCall with cdecl-convention, so only a RET is necessary at the end of the ASM-code ; If $_ASSEMBLEIT_FLAG = 0 is set before calling AssembleIt(), an AutoIt-code to call the opcodes without the need of FASM.au3 is created ; Related .......: Fasm.au3 by Ward http://www.autoitscript.com/forum/index.php?showtopic=111613&view=findpost&p=782727 ; Link ..........: ; Example .......: ; ================================================================================================= Func _AssembleIt($Returntype, $sFunc, $Type1 = "int", $Param1 = 0, $Type2 = "int", $Param2 = 0, $Type3 = "int", $Param3 = 0, $Type4 = "int", $Param4 = 0, $Type5 = "", $Param5 = 0, $Type6 = "", $Param6 = 0, $Type7 = "", $Param7 = 0, $Type8 = "", $Param8 = 0, $Type9 = "", $Param9 = 0, $Type10 = "", $Param10 = 0, $Type11 = "", $Param11 = 0, $Type12 = "", $Param12 = 0, $Type13 = "", $Param13 = 0, $Type14 = "", $Param14 = 0, $Type15 = "", $Param15 = 0, $Type16 = "", $Param16 = 0, $Type17 = "", $Param17 = 0, $Type18 = "", $Param18 = 0, $Type19 = "", $Param19 = 0, $Type20 = "", $Param20 = 0) ;assembles the code FasmReset($Fasm) If @error Then MsgBox(0, "_AssembleIt Error", "Error in Function FasmReset()") Return SetError(-2, 0, "ERROR -2") EndIf If $sFunc <> "" Then Call($sFunc) ;extract Assemblercode from function $sFunc() If @error = 0xDEAD Then MsgBox(0, "_AssembleIt Error", "The called function " & $sFunc & " doesn´t exist or contains errors!") Return SetError(-4, 0, "ERROR -4") EndIf Local $bytecode = FasmGetBinary($Fasm) ;assemble ASM-code to opcodes If @extended Then ;shows errors during assembling Local $Error = FasmGetLastError() ;gets errors MsgBox(0, "FASM-ERROR in function " & $sFunc & "()", "Error Code:" & $Error[0] & _ @CRLF & "Error Message:" & $Error[1] & @CRLF & "Error Line:" & $Error[2] & @CRLF) Return SetError(-3, 0, "ERROR -3") Else ;no errors during assembling the code FileDelete("asm_test.bin") ;creates binary file with opcodes, in the case that someone wants to use an external debugger^^ FileWrite("asm_test.bin", BinaryToString(String(FasmGetBinary($Fasm)))) ; ConsoleWrite($bytecode & @CRLF) ;opcodes, can easily be copied and inserted somewhere.... If $_ASSEMBLEIT_FLAG = 0 Then ;if less then 4 parameters, CallWindowProcW is possible If @NumParams > 10 Then ;only a maximum of 4 parameters in CallWindowProcW posssible MsgBox(0, "_AssembleIt Error", "The $_ASSEMBLEIT_FLAG is set to 0, but more than 4 Parameters are used in the Function " & $sFunc & @CRLF & _ "Please reduce the number of parameters to a maximum of 4 if you want an AutoItscript with a CallWindowProcW-call!") Exit Else ;all is ready to create an AutoItscript which can execute the opcodes without FASM.au3 Local $scriptstring = 'Local $iRet, $tCodeBuffer = DllStructCreate("byte ASM[' & StringLen($bytecode) / 2 - 1 & ']") ;reserve memory for ASM opcodes' & @CRLF & _ '$tCodeBuffer.ASM = "' & $bytecode & '" ;write opcodes into memory (struct)' & @CRLF $scriptstring &= '$iRet = DllCall("user32.dll", "' & $Returntype & '", "CallWindowProcW", "ptr", DllStructGetPtr($tCodeBuffer)' Local $n = 1 For $i = 3 To 9 Step 2 ;CallWindowProcW must be called with 4 parameters... $scriptstring &= ', "' & Eval("Type" & $n) & '", ' If Eval("Param" & $n) <> 0 Or Eval("Param" & $n) <> "" Then $scriptstring &= "Param" & $n Else $scriptstring &= '0' EndIf $n += 1 Next $scriptstring &= ')' & @CRLF ClipPut($scriptstring) ;puts the AutoItcode into Clipboard MsgBox(0, "_AssembleIt() Info!", "The following code was created and written into the Clipboard:" & _ @CRLF & @CRLF & $scriptstring & @CRLF & @CRLF & @CRLF & _ "This code can now be inserted into an AutoIt-Script, please adapt the parameters in the Dll-call to the used AutoIt-variables!" & _ @CRLF & "The Program will be terminated!") FasmExit($Fasm) Exit EndIf ElseIf $_ASSEMBLEIT_FLAG = 2 Then $scriptstring = '$tCodeBuffer.ASM = "' & $bytecode & '" ;write opcodes into memory (struct) / length: ' & StringLen($bytecode) / 2 - 1 ClipPut($scriptstring) MsgBox(0, "_AssembleIt() Info!", "ONLY the byte code line was created and written into the Clipboard:" & _ @CRLF & @CRLF & $scriptstring) FasmExit($Fasm) Exit EndIf ;MemoryFuncCall Local $scriptstring = 'MemoryFuncCall("' & $Returntype & ':cdecl",' & FasmGetFuncPtr($Fasm) ;cdecl instructs the function to clean the stack, only a simple RET at the end is necessary ;Local $scriptstring = 'MemoryFuncCall("' & $Returntype & '",' & FasmGetFuncPtr($Fasm) ;if "compatible" mode to existing programs is required, please commend out this line Local $n = 1 For $i = 3 To @NumParams Step 2 ;all parameters $scriptstring &= ',"' & Eval("Type" & $n) & '", $Param' & $n $n += 1 Next $scriptstring &= ')' Local $a = Execute($scriptstring) ;do the MemoryFuncCall, execute the opcodes If @error Then MsgBox(0, "_AssembleIt Error", "Error executing the MemoryFuncCall!") Return SetError(-5, 0, "ERROR -5") EndIf ;_arraydisplay($a) Return SetError(0, 0, $a[0]) EndIf EndFunc ;==>_AssembleIt Func _($str) ;short version of Fasmadd Fasmadd($Fasm, $str) EndFunc ;==>_ ;debug-Fenster Dim $_DBG_LABEL[170] Global $hwnd_weiterbutton, $_DBG_closebutton Global $_DBG_firstcall = True, $_DBG_buttonID Global $_DBG_GUI = GUICreate("AssembleIt Debug-Info 1.0", 670, 550, 10, 10, 0, $WS_EX_DLGMODALFRAME) Global $_DBG_winpos = WinGetPos($_DBG_GUI) Global $_DBG_Window_posold_x = $_DBG_winpos[0] ;fensterposition merken Global $_DBG_Window_posold_y = $_DBG_winpos[1] + $_DBG_winpos[3] ;$WM_MOVING = 0x0216 Global $_DBG_BUTTONSGUI = -1 GUIRegisterMsg(0x0216, "_DBG_WM_MOVING") ; $WM_MOVING GUIRegisterMsg(0x0232, "_DBG_WM_MOVING") ; $WM_EXITSIZEMOVE GUIRegisterMsg($WM_MOVE, "_DBG_WM_MOVING") ;~ GUIRegisterMsg($WM_MOVING, "_DBG_WM_MOVING") ;~ GUIRegisterMsg($WM_SIZE, "_DBG_WM_SIZE") ;GUIRegisterMsg($WM_COMMAND, "_DBG_WM_COMMAND") $_DBG_LABEL[18] = GUICtrlCreateLabel("FPU-Register showed as DOUBLE!", 10, 175, 290, 16) GUICtrlSetFont(-1, -1, -1, 4) ;GUICtrlSetResizing ( -1, 32+ 2 ) $_DBG_LABEL[17] = GUICtrlCreateLabel("EFlags", 580, 16, 102, 16) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[38] = GUICtrlCreateLabel("CF =", 580, 32 + 16 * 0, 30, 16);CF $_DBG_LABEL[59] = GUICtrlCreateLabel("DF =", 580, 32 + 16 * 1, 30, 16) $_DBG_LABEL[39] = GUICtrlCreateLabel("PF =", 580, 32 + 16 * 2, 30, 16) $_DBG_LABEL[68] = GUICtrlCreateLabel("OF =", 580, 32 + 16 * 3, 30, 16) $_DBG_LABEL[48] = GUICtrlCreateLabel("AF =", 580, 32 + 16 * 4, 30, 16) $_DBG_LABEL[49] = GUICtrlCreateLabel("ZF =", 580, 32 + 16 * 6, 30, 16) $_DBG_LABEL[58] = GUICtrlCreateLabel("SF =", 580, 32 + 16 * 7, 30, 16) For $i = 0 To 7 $_DBG_LABEL[10 + $i] = GUICtrlCreateLabel("ST" & $i & " = ", 10 + Mod($i, 2) * 180, 195 + 16 * Int($i / 2), 30, 16) $_DBG_LABEL[80 + $i] = GUICtrlCreateLabel("", 50 + Mod($i, 2) * 180, 195 + 16 * Int($i / 2), 100, 16) $_DBG_LABEL[30 + $i] = GUICtrlCreateLabel("XMM" & $i & " = ", 10, 400 + 15 * $i, 40, 16);XMM0-XMM7 $_DBG_LABEL[90 + $i] = GUICtrlCreateLabel("", 60, 400 + 15 * $i, 300, 16);XMM $_DBG_LABEL[40 + $i] = GUICtrlCreateLabel("", 60, 32 + 16 * $i, 400, 16);hex $_DBG_LABEL[50 + $i] = GUICtrlCreateLabel("", 150, 32 + 16 * $i, 400, 16);int $_DBG_LABEL[60 + $i] = GUICtrlCreateLabel("", 230, 32 + 16 * $i, 300, 16);float $_DBG_LABEL[70 + $i] = GUICtrlCreateLabel("", 320, 32 + 16 * $i, 240, 16);bin $_DBG_LABEL[100 + $i] = GUICtrlCreateLabel("", 610, 32 + 16 * $i, 40, 16) ;eflags $_DBG_LABEL[110 + $i] = GUICtrlCreateLabel("", 280, 400 + 15 * $i, 250, 16);XMM-2xdouble $_DBG_LABEL[120 + $i] = GUICtrlCreateLabel("", 440, 400 + 15 * $i, 250, 16);XMM-4xfloat Next GUICtrlSetPos($_DBG_LABEL[105], 590, 32 + 16 * 5, 1, 1) ;platz machen für ungenutztes label $_DBG_LABEL[20] = GUICtrlCreateLabel("FPU-Flags", 10, 270, 55, 16) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[21] = GUICtrlCreateLabel("CO= C1= C2=", 520, 200, 135, 20) $_DBG_LABEL[25] = GUICtrlCreateLabel("Stack", 370, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[26] = GUICtrlCreateLabel("HEX", 450, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[27] = GUICtrlCreateLabel("INT", 550, 175, 130, 20) GUICtrlSetFont(-1, -1, -1, 4) For $i = 40 To 0 Step -4 $_DBG_LABEL[129 + $i / 4] = GUICtrlCreateLabel(StringFormat("[esp %+02.2d]", 40 - $i), 370, 195 + 16 * $i / 4, 50, 16);129-140 $_DBG_LABEL[141 + $i / 4] = GUICtrlCreateLabel("", 450, 195 + 16 * $i / 4, 100, 16);141-152 $_DBG_LABEL[155 + $i / 4] = GUICtrlCreateLabel("", 550, 195 + 16 * $i / 4, 100, 16);155-161 Next $_DBG_LABEL[108] = GUICtrlCreateLabel("SSE-Register HEX", 10, 375, 150, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[109] = GUICtrlCreateLabel("2x Double", 280, 375, 100, 20) GUICtrlSetFont(-1, -1, -1, 4) $_DBG_LABEL[118] = GUICtrlCreateLabel("4x Float", 450, 375, 100, 20) GUICtrlSetFont(-1, -1, -1, 4) ;GUIRegisterMsg($WM_COMMAND, "MyWM_COMMAND") Global $listviewitem_reg32[8] Global $reg_32[8] = ["EAX", "EBX", "ECX", "EDX", "ESI", "EDI", "ESP", "EBP"] Global $Listview_reg32 = GUICtrlCreateListView("REG32|HEX|INT|FLOAT|BIN [BIT31....Bit0]", 10, 2, 560, 172, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOSORTHEADER));,$GUI_BKCOLOR_LV_ALTERNATE ) GUICtrlSetFont(-1, 8.5, -1, -1) GUICtrlSetBkColor($Listview_reg32, 0xF0f0f0) ; Grau GUICtrlSetBkColor($Listview_reg32, $GUI_BKCOLOR_LV_ALTERNATE) _GUICtrlListView_BeginUpdate($Listview_reg32) For $i = 0 To 7 $listviewitem_reg32[$i] = GUICtrlCreateListViewItem($reg_32[$i] & "|0xDDDDDDDD|88888888888|9.99999999E999|00000000 00000000 00000000 00000000 ", $Listview_reg32) GUICtrlSetBkColor($listviewitem_reg32[$i], 0xFFFFFF) ; weiss Next For $i = 0 To 4 _GUICtrlListView_SetColumnWidth($Listview_reg32, $i, $LVSCW_AUTOSIZE_USEHEADER);$LVSCW_AUTOSIZE) Next _GUICtrlListView_EndUpdate($Listview_reg32) ;thx progandy für den "button" ! Global Const $tagDLGTEMPLATE = "align 2 ;DWORD style; DWORD dwExtendedStyle; WORD cdit; short x; short y; short cx; short cy;" Global Const $tagDLGITEMTEMPLATE = "align 2 ;DWORD style; DWORD dwExtendedStyle; short x; short y; short cx; short cy; WORD id;" Global $_DBG_noshowflag = 0 Global $dlgproc = DllCallbackRegister("_DlgProc", "bool", "hwnd;uint;wparam;lparam") Global $_DBG_ = DllCallbackRegister("_DBG_MSGBOX", "dword", "dword;dword;dword;dword;dword;dword;dword;dword;dword") ;speicher reservieren für datenbereich Global $ptr_dbgmem = Number(_MemGlobalAlloc(600, 0)) ;512 byte + 8 byte weil nur 8byte-align Local $mod = Mod($ptr_dbgmem, 16) ;benötigt wird für SSE-Register abe 16-byte-align If $mod <> 0 Then $ptr_dbgmem += (16 - $mod) ;16 byte align EndIf Global $_dbg_string[100], $_DBG_nr = 0, $_DBG_command[2] Global $struct_FXSAVE = DllStructCreate("byte[512]", $ptr_dbgmem);platz für Daten aus FXSAVE Global $struct_STACK = DllStructCreate("dword[11]", $ptr_dbgmem + 520);platz für Daten aus STACK [esp-20] bis [esp+20] Global $ptr_STACK = DllStructGetPtr($struct_STACK) ;http://siyobik.info/index.php?module=x86&id=128 ;ob ich diese flags noch einbaue, weiss ich nicht Local $struct = DllStructCreate("" & _ "word FCW;" & _ ;FPU control word 0+1 "word FSW;" & _ ;FPU statusword 2+3 "byte FTW;" & _ ;FPU ag word 4 "byte;" & _ ;reserved 5 "word FOP;" & _ ;FPU opcode 6+7 "dword FIP;" & _ ;FPU instruction pointer 8-11 "word CS;" & _ ; 12-13 "word ;" & _ ;reserved 14-15 "dword FDP;" & _ ; 16-19 "word DS;" & _ ; 20+21 "word ;" & _ ;reserved 22-23 "dword MXCSR;" & _ ;MXCSR 24-27 "dword MXCSR_MASK;" & _ ;MXCSR_MASK 28-31 "byte[10] ST0;") ;ST0 32-41 Global $struct_double = DllStructCreate("double[8]") ;platz für 8 doubles der FPU register st0-st7 Global $struct_128SSE = DllStructCreate("byte[128]", Ptr($ptr_dbgmem + 160));platz für 16 byte SSE Global $struct_EFLAGS = DllStructCreate("dword EFLAGS", Ptr($ptr_dbgmem + 512));platz 32 bit eflags Global $ptr_SSE = DllStructGetPtr($struct_128SSE) ;pointer Global $ptr_EFLAGS = DllStructGetPtr($struct_EFLAGS) Global $struct_SSE64x2int = DllStructCreate("uint64[16]", $ptr_SSE) ;platz für 2x 64byte SSE Global $struct_SSE32x4int = DllStructCreate("uint[32]", $ptr_SSE) ;platz für 4x 32byte SSE Global $struct_SSE16x8int = DllStructCreate("word[64]", $ptr_SSE) ;platz für 8x 16byte SSE Global $struct_SSE64x2dbl = DllStructCreate("double[16]", $ptr_SSE) ;platz für 2x 64byte DOUBLE SSE Global $struct_SSE32x4flt = DllStructCreate("float[32]", $ptr_SSE) ;platz für 4x 32byte FLOAT SSE ;debug-funktion, aus dem asmcode per call an die callback-adresse aufgerufen Func _DBG_MSGBOX($anz, $edi, $esi, $ebp, $esp, $ebx, $edx, $ecx, $eax);aus asm übergebene register If $_DBG_noshowflag = 1 Then Return 0 GUISetState(@SW_SHOW, $_DBG_GUI) _WinAPI_UpdateWindow($_DBG_GUI) ;_DBG_WM_SIZE($_DBG_GUI,0,0,0) Dim $reg[8] = [$eax, $ebx, $ecx, $edx, $esi, $edi, $esp, $ebp] _GUICtrlListView_BeginUpdate($Listview_reg32) For $i = 0 To 7 ;fenster mit Werten füllen GUICtrlSetData($listviewitem_reg32[$i], "|" & Ptr($reg[$i]) & "|" & _ String($reg[$i]) & "|" & _ StringFormat(" %2.6G", int2float($reg[$i])) & "|" & int2bin($reg[$i])) ;hex GUICtrlSetData($_DBG_LABEL[$i + 80], DllStructGetData($struct_double, 1, $i + 1));FPU st0-st7 ;SSE $struct_temp = DllStructCreate("byte[16]", $ptr_SSE + 16 * $i) $struct = DllStructCreate("byte[16]") For $z = 1 To 16 DllStructSetData($struct, 1, DllStructGetData($struct_temp, 1, 17 - $z), $z) Next GUICtrlSetData($_DBG_LABEL[$i + 90], DllStructGetData($struct, 1)) GUICtrlSetData($_DBG_LABEL[$i + 100], BitAND(2 ^ $i, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ $i));eflags $struct = DllStructCreate("double[2]", $ptr_SSE + 16 * $i); 2x 64byte DOUBLE SSE GUICtrlSetData($_DBG_LABEL[$i + 110], StringFormat("%6s %6s", DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 1))) $struct = DllStructCreate("float[4]", $ptr_SSE + 16 * $i); 4x 32byte FLOAT SSE GUICtrlSetData($_DBG_LABEL[$i + 120], StringFormat("%10.5f %10.5f %10.5f %10.5f", DllStructGetData($struct, 1, 4), DllStructGetData($struct, 1, 3), DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 1))) Next GUICtrlSetData($_DBG_LABEL[101], BitAND(2 ^ 10, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ 10));eflags DF GUICtrlSetData($_DBG_LABEL[103], BitAND(2 ^ 11, DllStructGetData($struct_EFLAGS, 1)) / (2 ^ 11));eflags OF For $i = 0 To 10 ;stack GUICtrlSetData($_DBG_LABEL[141 + $i], Ptr(DllStructGetData($struct_STACK, 1, $i + 1)));stack hex GUICtrlSetData($_DBG_LABEL[155 + $i], Int(DllStructGetData($struct_STACK, 1, $i + 1)));stack int Next _GUICtrlListView_EndUpdate($Listview_reg32) If $anz = 0 Or Execute($_dbg_string[$anz]) Then Switch __GET_MSGBOX_BUTTON() Case 0, 1 Case 2 $_DBG_noshowflag = True Case 3 DllCall("kernel32.dll", "none", "ExitProcess", "int", 0xDEADBEEF) EndSwitch EndIf Return 0 EndFunc ;==>_DBG_MSGBOX Func __GET_MSGBOX_BUTTON() Local Static $tDLG, $aOldPos[4] = [0, 0, -1, -1] Local $pos_DBB_Window = WinGetPos($_DBG_GUI) ;Positionsdaten der GUI holen If $aOldPos[0] <> $pos_DBB_Window[0] Or $aOldPos[1] <> $pos_DBB_Window[1] Or $aOldPos[2] <> $pos_DBB_Window[2] Or $aOldPos[2] <> $pos_DBB_Window[2] Then $aOldPos = $pos_DBB_Window Local $x = Int($pos_DBB_Window[0] / 2) Local $y = Int(($pos_DBB_Window[1] + $pos_DBB_Window[3]) / 2) ;es folgen die Daten für den "...NEXT"-Button, der muss ein modales Fenster sein, wer da eine andere Idee hat, bitte melden Local $w = Int($pos_DBB_Window[2] / 2) ;breite Button Local $h = 30 ;höhe Button Local $bTitle = StringToBinary("Next....", 2) ;text Button Local $bXY = BinaryMid(Binary($x), 1, 2) & BinaryMid(Binary($y), 1, 2);Buttondaten Local $bWH = BinaryMid(Binary($w), 1, 2) & BinaryMid(Binary($h), 1, 2) Local $bWhalfH = BinaryMid(Binary(Int($w / 2 - 15)), 1, 2) & BinaryMid(Binary($h), 1, 2) Local $bDIALOG = Binary("0x00000090400000040300") & $bXY & $bWH & Binary("0x000000000000") & Binary("0x000000500000000000000000") & $bWhalfH & Binary("0x0100FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") ; |Style ||ExStyl||cdit| |Empty "Arrays"| |Style ||ExStyl||x ||y | |id||BUTTON| |Chr0| |irgend welche anderen Arrays $x = Mod(BinaryLen($bDIALOG), 4) If $x Then $bDIALOG &= BinaryMid(Binary("0x000000"), 1, $x) $bTitle = StringToBinary("End Debugging", 2) ;text Button $bDIALOG &= Binary("0x0000005000000000") & BinaryMid(Int($w / 2 - 15), 1, 2) & Binary("0x0000") & $bWhalfH & Binary("0x0200FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") $x = Mod(BinaryLen($bDIALOG), 4) If $x Then $bDIALOG &= BinaryMid(Binary("0x000000"), 1, $x) $bTitle = StringToBinary("Kill", 2) ;text Button $bDIALOG &= Binary("0x0000005000000000") & BinaryMid(Int($w - 30), 1, 2) & Binary("0x0000") & BinaryMid(30, 1, 2) & BinaryMid($h, 1, 2) & Binary("0x0300FFFF8000") & $bTitle & Binary("0x0000") & Binary("0x0000") $tDLG = DllStructCreate("byte[" & BinaryLen($bDIALOG) & "]") DllStructSetData($tDLG, 1, $bDIALOG) ;Button-Daten in struct schreiben EndIf Local $aRet = DllCall("user32.dll", "int", "DialogBoxIndirectParamW", "ptr", 0, "ptr", DllStructGetPtr($tDLG), "hwnd", 0, "ptr", DllCallbackGetPtr($dlgproc), "lparam", 0) If @error Then Return 0 Return $aRet[0] EndFunc ;==>__GET_MSGBOX_BUTTON ;Alle Register, Flags, Stack usw werden in einen Speicherbereich geschrieben und von dort mit ;der Funktion _DBG_MSGBOX() ausgelesen Func _asmdbg_($_DBG_command = "") ;Register _("push dword[esp+40]") ;stack in memory _("pop dword[" & $ptr_STACK & "]") _("push dword[esp+36]") ;stack in memory _("pop dword[" & $ptr_STACK + 4 & "]") _("push dword[esp+32]") ;stack in memory _("pop dword[" & $ptr_STACK + 8 & "]") _("push dword[esp+28]") ;stack in memory _("pop dword[" & $ptr_STACK + 12 & "]") _("push dword[esp+24]") ;stack in memory _("pop dword[" & $ptr_STACK + 16 & "]") _("push dword[esp+20]") ;stack in memory _("pop dword[" & $ptr_STACK + 20 & "]") _("push dword[esp+16]") ;stack in memory _("pop dword[" & $ptr_STACK + 24 & "]") _("push dword[esp+12]") ;stack in memory _("pop dword[" & $ptr_STACK + 28 & "]") _("push dword[esp+08]") ;stack in memory _("pop dword[" & $ptr_STACK + 32 & "]") _("push dword[esp+04]") ;stack in memory _("pop dword[" & $ptr_STACK + 36 & "]") _("push dword[esp+00]") ;stack in memory _("pop dword[" & $ptr_STACK + 40 & "]") _("pushfd") ;eflags sichern _("pop dword[" & Ptr($ptr_EFLAGS) & "]") ;eflags speichern in struct _("pushfd") ;eflags sichern _("push eax") _("mov eax," & $ptr_dbgmem) ;alle FPU+SSE Registerinhalte und flags sichern _("FXSAVE [eax]") _("fstp qword[" & DllStructGetPtr($struct_double) & "]") ;alle FPU-Register sichern _("fstp qword[" & DllStructGetPtr($struct_double) + 8 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 16 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 24 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 32 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 40 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 48 & "]") _("fstp qword[" & DllStructGetPtr($struct_double) + 56 & "]") ; _("fwait") _("pop eax") _("pushad") ;alle Register sichern _("pushad") ;auf den stack für für die msgbox If $_DBG_command <> "" Then ;falls kein Befehl übergeben wurde $_DBG_nr += 1 $_dbg_string[$_DBG_nr] = $_DBG_command _("push " & Ptr($_DBG_nr)) ;anzahl der Else _("push " & Ptr(0)) EndIf _("call " & DllCallbackGetPtr($_DBG_)) ;in autoit-callbackroutine springen _("mov eax," & $ptr_dbgmem) ;alle FPU+SSE registerinhalte und flags restore _("FXRSTOR [eax]") ;restore alle FPU-Register ; _("fwait") _("popad") ;alle register wieder zurücksetzen _("popfd") ;eflags setzen EndFunc ;==>_asmdbg_ Func bin2ascii($bin_string) ;string aus nullen und einsen in 8-bit-ascii text string umwandeln Local $step = 8 ;8-Bit ASCII Buchstaben Local $ascii_string = "" ;Rückgabestring For $f = 1 To StringLen($bin_string) Step $step ;string von Vorne nach hinten 8-bitweise durchsuchen Local $t = StringMid($bin_string, $f, $step) ; 8-Bit-Wort, ein ASCII-Buchstabe Local $bin = 0 ;startwert für For $i = 1 To $step ;jedes Bit suchen If StringMid($t, $i, 1) = "1" Then $bin += (2 ^ ($step - $i)) ;wenn Bit=1 dann binärzahl=binärzahl+2^(8-Bitposition) Next $ascii_string &= Chr($bin) Next Return $ascii_string EndFunc ;==>bin2ascii Func int2bin($integer) ;32Bit in binärstring darstellen Local $bin_string = "" For $i = 31 To 0 Step -1 ;asciicode in bits If Mod($i + 1, 8) = 0 Then $bin_string &= " " If BitAND($integer, 2 ^ $i) Then $bin_string &= "1" Else $bin_string &= "0" EndIf Next Return $bin_string EndFunc ;==>int2bin Func int2float($integer) Local $struct = DllStructCreate("int") Local $struct2 = DllStructCreate("float", DllStructGetPtr($struct)) DllStructSetData($struct, 1, $integer) Local $ret = DllStructGetData($struct2, 1) $struct = 0 $struct2 = 0 Return $ret EndFunc ;==>int2float Func _DlgProc($hwnd, $uMsg, $wParam, $lParam) ;thx to progandy! If $uMsg = $WM_INITDIALOG Then $_DBG_BUTTONSGUI = $hwnd ElseIf $uMsg = $WM_CLOSE Then DllCall("user32.dll", "bool", "EndDialog", "hwnd", $hwnd, "int_ptr", 0) Return True ElseIf $uMsg = $WM_COMMAND Then DllCall("user32.dll", "bool", "EndDialog", "hwnd", $hwnd, "int_ptr", BitAND($wParam, 0xFFFF)) Return True ElseIf $uMsg = $WM_DESTROY Then $_DBG_BUTTONSGUI = -1 EndIf Return False EndFunc ;==>_DlgProc Func _DBG_WM_MOVING($hwnd, $uMsg, $wParam, $lParam) If $hwnd = $_DBG_GUI And IsHWnd($_DBG_BUTTONSGUI) Then Local $pos = WinGetPos($hwnd) WinMove($_DBG_BUTTONSGUI, "", $pos[0], $pos[1] + $pos[3]) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_DBG_WM_MOVING Func _DBG_WM_SIZE($hwnd, $message, $wParam, $lParam);fenstergrösse wird verändert Local $posgui = WinGetPos($_DBG_GUI) $_DBG_Window_posold_x = $posgui[0] ;fensterposition merken $_DBG_Window_posold_y = $posgui[1] ;WinMove($hwnd_weiterbutton, "", $pos[0], $pos[1] + $pos[3], 200, 60);buttonposition anpassen WinMove($hwnd_weiterbutton, "", $posgui[0], $posgui[1] + $posgui[3], $posgui[2], 60);fensterposition anpassen WinMove($_DBG_GUI, "", $posgui[0], $posgui[1], $posgui[2], $posgui[3]);fensterposition anpassen _WinAPI_SetWindowPos($_DBG_buttonID, 0, 0, 0, $posgui[2], 60, 0x0020);buttonpos im fenster resze EndFunc ;==>_DBG_WM_SIZE You can use also different inline assembler UDFs, e.g. Extended Flat Assembler (by Beege) or the originaly by Ward The Embedded Flat Assembler (FASM) UDF Without the help of AndyG and Eukalyptus I wouldn't be able to create ASM code - many thanks!!! Many thanks dudes - you rock! I'm a novice in assembler coding - please don't blame me. Feel free to post your snippets here! Categories String _ASM_StringLFCharCount (counts the line feeds within a string) _ASM_StringReplaceWChar (replaces a unicode char within a string) _StringReverse / _StringReverse2 (reverse a string coded by AndyG) Graphic _ASM_DrawRectFilled (draws a filled rectangle) _ASM_ImageInvert (inverts (negative) an image) _ASM_BitmapCreateBitmapWithAlpha (merges an image with an alpha blend image) _ASM_ImageCreateNegativeMMX (inverts (negative) an image using MMX) _ASM_DrawLineUsingGDIPlus (draws a line using the GDIPlus lib) _ASM_BitCompareBitmapsMMX (bitwise bitmap compare) _ASM_BitmapGetAverageColorValue / _ASM64_BitmapGetAverageColorValue.au3 (gets the average color of a bitmap)
    1 point
  3. Danyfirex

    Base64 Image post

    it Works correctly using WInHttp 1.6.3.9. and autoit v3.3.14.1 @trancexx I never get tired of seeing your photo. lol Saludos
    1 point
  4. This is just a little helpful script, that I started using a month or so ago (one program so far), with this version having a Restore ability added (so now using with two programs of mine, as of tonight). You can find other alternatives or similar scripts here, the most recent being - _SingleScript guinness also has something much more elaborate, that is well worth checking out - _SingletonHWID. Just place the following at the beginning of your script, and adjust where needed and wanted (including Scriptname, variable names and MsgBox magic numbers, etc). Perhaps you should read and use the following - Best coding practices ... unlike my slack hobby programmer self (not always). #include <Misc.au3> Global $ans, $exe, $handle, $pid, $script, $Scriptname, $status, $w, $wins ; Assign the program name (window title). $Scriptname = "Update Mp3 Artwork v7.9 (updated December 2015)" ; The following line both sets the unique ID of the current program, plus queries if a program with the same ID is running already. $status = _Singleton("update-mp3artwork-thsaint", 1) If $status = 0 Then ; A program with the same ID is already running. ; Assign a PID for previous script, based on current executable name, whether current script is compiled or not, and assign the executable name. If @Compiled = 1 Then $pid = ProcessExists(@ScriptName) $exe = @ScriptName Else $pid = ProcessExists("AutoIt3.exe") $exe = "AutoIt3.exe" EndIf ; Assign a PID for current script. $script = @AutoItPID ; $ans = MsgBox(262177, "Close Running Instance Query", _ "'Update Mp3 Artwork' program is already running." & @LF & @LF & _ "Do you want to close it for another instance?" & @LF & @LF & _ "NOTE - If all work has been saved, and you are" & @LF & _ "trying to work on another album, then a click on" & @LF & _ "OK is recommended, else just click CANCEL, to" & @LF & _ "attempt a restore or re-activate of original." & @LF & @LF & _ $pid & " (" & $exe & ") " & $script & @LF & @LF & _ "(will default to CANCEL in 30 seconds)", 30) If $ans = 1 Then ; Attempt to close original instance, and continue with new. If $pid <> $script Then ProcessClose($pid) Else MsgBox(262192, "Close Error", "OK process failed!", 0) Exit EndIf ElseIf $ans = 2 Or $ans = -1 Then ; Attempt to retore and activate a non-active or minimized window. ; Get a list of all running programs with the same name. $wins = WinList($Scriptname, "") ; Loop through found instances and compare PID's, restoring or re-activating any match. For $w = 1 to $wins[0][0] $handle = $wins[$w][1] If WinGetProcess($handle, "") = $pid Then WinSetState($handle, "", @SW_RESTORE) WinActivate($handle, "") ExitLoop EndIf Next Exit EndIf EndIf Enjoy! P.S. I have a couple of programs that I regularly forget are minimized while working with another related one, so this saves me some mucking around to close and restart or restore etc. Pretty basic, but does the job well so far.
    1 point
  5. Just implemented this and it works flawlessly thanks
    1 point
  6. I found something interesting on the web about using net use with the /user: and /savecred options. Hit the link below for the full source, but the meat of the conversion is copied below in italics From: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/8fc5d667-c1f9-4670-a6e1-3ba2c5e8603d/net-use-savcred-user-conflicting-switches?forum=ITCG Maybe that will help.
    1 point
  7. Hi regg, welcome to the forum. Just in case something else is taking the focus and interfering, you should incorporate WinActivate just prior to WinWaitActive. You could even incorporate a Sleep and or loop if necessary. Have a look at the Help file example for the WinActivate command. P.S. Note, that the Editor has a Code button <> which you should use when posting code, as it makes it much easier for helpers to read.
    1 point
  8. Declaring globals inside a func is not something I normally do.. I would chalk this up to a point of weakness for me haha. Commenting those lines out did work, but the seconds seem to keep counting, which is no worry, I just have to get creative with that part. the reason for so many functions like that is, I plan on making them transferable to other scripts easily. Might not be the most efficient, but I never really learned to code, just picked it up as I went along. I'll learn one day, haha. _TimerDiff and _TimerRunningDiff were initially supposed to be used separate, one while the clock was running, and one while its not. I'm seeing now that I'm not super tired that they really can just be merged into one. I will look into that sleep idea. the only reason I have been avoiding them is on a rare occasion, people hit that button on a sleep cycle and it seems to not do anything. In a perfect world, I would be using OnEvent tricks. I cant find a good example, but its when you declare a button, then right after it, you have an 'OnClick' type call that will cause the gui to keep an eye out for that click. I will play with this and try to make that work.. thanks!!
    1 point
  9. @LarsJ I wanted to see who will be interested in the code and ask for it and as Andy said I used a very simple ASM version for the summation: Func _ASM_BitmapCountARGBColors() _("use32") ;32Bit! _("mov esi, dword[esp+4]") ;points to beginning of the bitmap in the memory _("mov edi, dword[esp+8]") ;points to the beginning of the struct in the memory _("mov ecx, dword[esp+12]") ;amount of pixels to read (width * height) _("_loop1:") _("mov dword eax, [esi]") ;copy the current AARRGGBB value to eax _("mov ebx, eax") ;make a copy of eax for "faster" access _("and ebx, 0x000000FF") ;mask the blue channel _("add dword[edi + 12], ebx") ;add blue value which is saved in the struct -> each struct value is 4 bytes long and blue starts at memory + 12 _("mov dword ebx, eax") _("and ebx, 0x0000FF00") ;now the same with green channel _("shr ebx, 8") ;shift the green value to the right -> 0000GG00 - > 000000GG _("add dword[edi + 8], ebx") ;add green value _("mov dword ebx, eax") _("and ebx, 0x00FF0000") ;and red channel _("shr ebx, 16") ;-> 00RR0000 - > 000000RR _("add dword[edi + 4], ebx") ;add red value _("mov dword ebx, eax") _("and ebx, 0xFF000000") ;and finally with alpha channel _("shr ebx, 24") ;-> AA000000 - > 000000AA _("add dword[edi], ebx") ;add alpha value _("add esi, 4") ;get next color word from bitmap _("sub ecx, 1") ;decrease pixel count _("ja _loop1") ;if pixel count = zero then exit loop _("ret") ;finished EndFunc The code is straightforward and doesn't need much comments. If you have any question then please ask. I will try tomorrow to implement it as x64. Well Andy, if I were able to code how you code in ASM I would do it regardless whether it makes sense for a particular case. My ASM code is the result being a ASM rookie.
    1 point
  10. You certainly can. Your code is well structured. Easy to read and understand. I like that. There are a few minor issues and one major issue. A virtual listview must include the $LVS_OWNERDATA style. GUICtrlSendMsg works only with control IDs. Not handles. The parameters for GUICtrlSendMsg must be of the proper type. $aResult[2] is a string. It must an integer. When it's a string the listview gets really confused and thinks that there are millions of rows. The major issue is about the caching technique. The iFrom and iTo fields in the $tagNMLVCACHEHINT structure are simply row indices in the listview. When the listview is filled with rows from the SQL select statement the first time immediately after a click in the treeview, the value of iFrom is 0 and the value of iTo is 29 (the height of the listview matches aproximately 30 rows). This means that the first 30 rows from the select statement is loaded into the $aResult array. This is done in the $LVN_ODCACHEHINT section. $aResult is the cache. When the rows are shown in the listview they are extracted from the cache, $aResult, and displayed. This is done on $LVN_GETDISPINFO events. There are 30 events to display an entire page on the listview. If you select the last visible row on the first page in the listview and press Page Down, a new $LVN_ODCACHEHINT event is generated with iFrom = 30 and iTo = 59. This means that the next 30 rows from the select statement is loaded into $aResult. And these 30 rows are displayed on the next page of the listview with 30 $LVN_GETDISPINFO events. For all this to work the result rows of the SQL select statement must be numbered in an uninterrupted sequence from first to last row in such a way that it's possible to create a 1-1 relation between the result row numbers and listview row indices. This 1-1 relation must ensure that it's possible to extract a result row with a specific number. In my databases in the examples the tables are extremely simple. The item_id field can simply be used to establish this relation. The result rows of your SQL select statements are not that simple. We have to establish this relation manually. Schematically it looks like this. My simple tables: Your more complicated select statements: The relation can be established with a few SQL statements: ; Create memory database ATTACH DATABASE ':memory:' AS DisplayMemDb; ; Create temp view CREATE TEMP VIEW DisplayView AS SELECT Name,Time,Category FROM SSDB WHERE Title IS $TreeView_SelTitle; ; Create table in memory database CREATE TABLE DisplayMemDb.RowRelation AS SELECT Name FROM DisplayView; ; The $LVN_ODCACHEHINT select statement SELECT RowRelation.rowid,DisplayView.Name,Time,Category FROM DisplayView INNER JOIN RowRelation ON DisplayView.Name = RowRelation.Name WHERE RowRelation.rowid BETWEEN $iFrom + 1 And $iTo + 1; Deprecated code because of missing primary key. See post 43. #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <SQLite.au3> #include <Math.au3> Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo" Global $aListView, $hListView, $TreeView_SelTitle Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 881, 516, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") Global $TreeView = GUICtrlCreateTreeView(8, 16, 319, 489, BitOR($GUI_SS_DEFAULT_TREEVIEW,$TVS_FULLROWSELECT,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) Global $TreeView_Root_1 = GUICtrlCreateTreeViewItem("root - 1", $TreeView) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_1 = GUICtrlCreateTreeViewItem("111", $TreeView_Root_1) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_2 = GUICtrlCreateTreeViewItem("222", $TreeView_Root_1) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_3 = GUICtrlCreateTreeViewItem("333", $TreeView_Root_1) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_Root_2 = GUICtrlCreateTreeViewItem("root - 2", $TreeView) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_4 = GUICtrlCreateTreeViewItem("444", $TreeView_Root_2) GUICtrlSetOnEvent(-1, "TreeView1Click") Global $TreeView_5 = GUICtrlCreateTreeViewItem("555", $TreeView_Root_2) GUICtrlSetOnEvent(-1, "TreeView1Click") ;Global $ListView = GUICtrlCreateListView("Rowid|Name|Time|Category", 336, 16, 538, 486, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_ALIGNLEFT,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_FULLROWSELECT)) Global $ListView = GUICtrlCreateListView("Rowid|Name|Time|Category", 336, 16, 538, 486, $LVS_OWNERDATA, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) ; $LVS_OWNERDATA must be included for a virtual listview _GUICtrlListView_SetExtendedListViewStyle( $ListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 200) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 88) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 112) GUICtrlSetOnEvent(-1, "ListViewClick") GUIRegisterMsg($WM_NOTIFY, "LWS_WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### DBInit() $hListView = GUICtrlGetHandle($ListView) _GUICtrlTreeView_Expand($TreeView, $TreeView_Root_1, True) While 1 Sleep(100) WEnd Func Form1Close() GUIRegisterMsg( $WM_NOTIFY, "" ) ; Exit EndFunc ;========================================================================================== Func ListViewClick() EndFunc ;========================================================================================== Func TreeView1Click() Local $sQuery, $aResult, $iRows, $iColumns Static Local $TreeView_SelTitlePRE = "", $bFirst = True If $TreeView_SelTitlePRE == "" Then $TreeView_Selected = _GUICtrlTreeView_GetFirstChild($TreeView, $TreeView_Root_1) _GUICtrlTreeView_ClickItem($TreeView, $TreeView_Selected, "left") Else $TreeView_Selected = _GUICtrlTreeView_GetSelection($TreeView) EndIf $TreeView_SelTitle = _GUICtrlTreeView_GetText($TreeView, $TreeView_Selected) If $TreeView_SelTitle == $TreeView_SelTitlePRE Then Return Else $TreeView_SelTitlePRE = $TreeView_SelTitle EndIf ConsoleWrite($TreeView_SelTitle & @CRLF) $sQuery = "SELECT count(Title) FROM SSDB WHERE Title IS '" & $TreeView_SelTitle & "'" _SQLite_GetTable(-1, $sQuery, $aResult, $iRows, $iColumns) ;GUICtrlSendMsg( $hListView, $LVM_SETITEMCOUNT, $aResult[2], 0 ) ConsoleWrite("Rows = " & $aResult[2] & @CRLF) If Not $bFirst Then _SQLite_Exec( -1, "DROP VIEW DisplayView;" ) _SQLite_Exec( -1, "DROP TABLE DisplayMemDb.RowRelation;" ) Else $bFirst = False EndIf _SQLite_Exec( -1, "CREATE TEMP VIEW DisplayView AS SELECT Name,Time,Category FROM SSDB WHERE Title IS '" & $TreeView_SelTitle & "';" ) _SQLite_Exec( -1, "CREATE TABLE DisplayMemDb.RowRelation AS SELECT Name FROM DisplayView;" ) GUICtrlSendMsg( $ListView, $LVM_SETITEMCOUNT, Int($aResult[2]), 0 ) ; GUICtrlSendMsg works with control IDs only, $aResult[2] (string) must be an integer EndFunc ;========================================================================================== Func DBInit() Local $aResult, $iRows, $iColumns ;------------------------------------------------------------------------------------------ Local $sPathTo_SSDB = @ScriptDir & "\SSDB.sqlite" Local $sPathTo_SQLiteDLL = @ScriptDir & "\sqlite3.dll" Global $sSqlBuild_Table = "(Title, Name, Time, Category, column_05, column_06, column_07, column_08)" ;------------------------------------------------------------------------------------------ If FileExists($sPathTo_SSDB) Then FileDelete($sPathTo_SSDB) _SQLite_Startup($sPathTo_SQLiteDLL) $hSSDB = _SQLite_Open($sPathTo_SSDB) ;------------------------------------------------------------------------------------------ _SQLite_GetTable($hSSDB, "PRAGMA page_size;", $aResult, $iRows, $iColumns) If Not @error And IsArray($aResult) Then $DBCacheSize = _Max(2*FileGetSize($sPathTo_SSDB)/$aResult[2],64*1024) _SQLite_Exec($hSSDB, "PRAGMA cache_size = " & $DBCacheSize & ";" ) ConsoleWrite("...SQLite DB Set Cache Size = 2 x DB file size = " & $DBCacheSize & " Pages of " & $aResult[2] & " Bytes" & @CRLF) EndIf ;------------------------------------------------------------------------------------------ _SQLite_Exec($hSSDB, "CREATE TABLE IF NOT EXISTS SSDB " & $sSqlBuild_Table & ";") ;------------------------------------------------------------------------------------------ _SQLite_Exec($hSSDB, "CREATE INDEX IF NOT EXISTS index_Title ON SSDB (Title);" ) _SQLite_Exec($hSSDB, "CREATE INDEX IF NOT EXISTS index_Name ON SSDB (Name);" ) _SQLite_Exec($hSSDB, "CREATE INDEX IF NOT EXISTS index_Time ON SSDB (Time);" ) ;------------------------------------------------------------------------------------------ $sQuery = "" For $i = 1 To 5 $sQuery &= 'INSERT INTO SSDB ' & $sSqlBuild_Table & ' VALUES ' $sTitle = String($i) & String($i) & String($i) For $j = 0 To 6200 $sQuery &= "('" & StringRegExpReplace($sTitle, "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace($sTitle & "_" & $j, "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace("12345", "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace("123", "'", "''") & "'" $sQuery &= ",'','','','')," Next $sQuery &= "('" & StringRegExpReplace($sTitle, "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace($sTitle & "_" & $j, "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace("12345", "'", "''") & "'" $sQuery &= ",'" & StringRegExpReplace("123", "'", "''") & "'" $sQuery &= ",'','','','');" Next If Not (_SQLite_Exec(-1, $sQuery) = $SQLITE_OK) Then Return SetError(2) _SQLite_Exec( -1, "ATTACH DATABASE ':memory:' AS DisplayMemDb;" ) ; <<<<<<<<<<<<<<<<<<< EndFunc ;========================================================================================== Func LWS_WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local Static $tText = DllStructCreate( "wchar[512]" ) Local Static $pText = DllStructGetPtr( $tText ) Local Static $aResult, $iRows, $iFrom Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $VKey $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item If Mod( $dwItemSpec, 2 ) = 0 Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) Else DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xF8FFF8 ) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" ) - $iFrom + 1 If $iIndex > 0 And $iIndex < $iRows + 1 Then Local $sItem = $aResult[$iIndex][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf EndIf Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ), $iColumns $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) ;Local $sSQL = "SELECT Name,Time,Category FROM SSDB WHERE Title IS '" & $TreeView_SelTitle & "' AND item_id >= " & $iFrom & " AND item_id <= " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) & ";" Local $sSQL = "SELECT RowRelation.rowid,DisplayView.Name,Time,Category FROM DisplayView INNER JOIN RowRelation ON DisplayView.Name = RowRelation.Name WHERE RowRelation.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" _SQLite_GetTable2d( -1, $sSQL, $aResult, $iRows, $iColumns ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Deprecated code because of missing primary key. See post 43.
    1 point
  11. Hi, with a little help of AssembleIt64(), i wrote an ASM-function to calculate the average colour of the screen. The function returns the same result as Melba23´s script, (no wonder, i am add up all single color components and devide this result by the sum of all pixel ) It´s a little bit faster than Melba23´s script...a little....(500-600 times). 90% of the runtime of this function takes the BitBlt() because of M$-AERO, this could be dramatically improved by switch off AERO (improvement factor 10!!! ) so the whole function takes only a handful milliseconds. The script could be easily adapt to calculate parts of the screen or windows/controls, but I leave it to others to post scripts which can be easily copy&pasted ;#include <assembleit2_64.au3> #include <WinAPI.au3> #include <Memory.au3> #AutoIt3Wrapper_UseX64=n #cs _averagepixel Use32 ;32Bit! mov edi,dword[esp+4] ;pointer bitmap mov ecx,dword[esp+8] ;width bitmap mov ebx,dword[esp+12] ;height bitmap mov eax,ebx ;h mul ecx ;w*h mov ecx,eax ;w*h=number of pixel movd xmm3,ecx ;0,0,0,w*h pshufd xmm3,xmm3,0 ;w*h,w*h,w*h,w*h sub ecx,1 ;from 0 to (w*h)-1 shl ecx,2 ;w*h*4 bytes mov edx,0 movd xmm1,edx ;xmm1 ARGB every pixel movd xmm2,edx ;xmm2 sumn all A,R,G,B ;_asmdbg_() @pixel_count: ;loop all pixel movd xmm0,[edi+ecx] ;pixel ARGB into xmm PUNPCKLBW xmm0,xmm1 ;000000000A0R0G0B PUNPCKLBW xmm0,xmm1 ;000A000R000G000B PADDD xmm2,xmm0 ;add all A,R,G,B Integer sub ecx,4 jnz @pixel_count ;loop all pixel movdqa xmm6,xmm2 ;save xmm2 A,R,G,B PSRLDQ xmm2,8 ;shift right 8 bytes = 0,0,A,R CVTDQ2PD xmm4,xmm2 ;convert int to double CVTDQ2PD xmm5,xmm3 ;convert int to double DIVPD xmm4,xmm5 ;divide sum_all_pixel / number_all_pixel CVTPD2DQ xmm7,xmm4 ;convert double to integer PSLLDQ xmm7,8 ;shift left 8 bytes = 000A000R00000000 ;_asmdbg_() MOVDQA xmm2,xmm6 ;restore xmm2 A,R,G,B CVTDQ2PD xmm4,xmm2 ;convert to double 0,0,G,B CVTDQ2PD xmm5,xmm3 ;convert to double DIVPD xmm4,xmm5 ;divide sum_all_pixel / number_all_pixel CVTPD2DQ xmm6,xmm4 ;convert double to integer = 00000000000G000B ORPS xmm7,xmm6 ;xmm7=000A000R000G000B =average colour all pixel PACKUSWB xmm7,xmm7 ; PACKUSWB xmm7,xmm7 ;ARGBARGBARGBARGB movd eax,xmm7 ;return average ARGB ret #ce $t = TimerInit() $average = Screen_Average_Colour() $m = Int(1000 * TimerDiff($t) / 1000) MsgBox(0, "Average Colour", "Average colour ARGB of screen = " & $average & @CRLF & "in " & $m & " milliseconds") Func Screen_Average_Colour() ;get desktop width and height local $hDLL_User32 = DllOpen("user32.dll") local $DesktopWidth = DllCall($hDLL_User32, "int", "GetSystemMetrics", "int", 78) ;sm_virtualwidth $DesktopWidth = $DesktopWidth[0] local $DesktopHeight = DllCall($hDLL_User32, "int", "GetSystemMetrics", "int", 79) ;sm_virtualheight $DesktopHeight = $DesktopHeight[0] Local $ptr_bitmap, $hbmp ;byref _CreateNewBmp32($iwidth, $iheight, ByRef $ptr, ByRef $hbmp) $hdc_bitmap = _CreateNewBmp32($DesktopWidth, $DesktopHeight, $ptr_bitmap, $hbmp) ;create empty bitmap $hdc_desktop = _WinAPI_GetDC(0) ;hdc desktop (or window/control if you want) _WinAPI_BitBlt($hdc_bitmap, 0, 0, $DesktopWidth, $DesktopHeight, $hdc_desktop, 0, 0, 0xCC0020);bitblt desktop into bitmap ;$binarycode = _AssembleIt2("retbinary", "_averagepixel") ;gibt nur den assemblierten code zurück $binarycode = "0x8B7C24048B4C24088B5C240C89D8F7E189C1660F6ED9660F70DB0083E901C1E102BA00000000660F6ECA660F6ED2660F6E040F660F60C1660F60C1660FFED083E90475EA660F6FF2660F73DA08F30FE6E2F30FE6EB660F5EE5F20FE6FC660F73FF08660F6FD6F30FE6E2F30FE6EB660F5EE5F20FE6F40F56FE660F67FF660F67FF660F7EF8C3" ;nur für dllcalladdress() benötigt, den binarycode braucht man nur ein mal erstellen $tCodeBuffer = dllstructcreate("byte[" & StringLen($binarycode) / 2 - 1 & "]") ;reserve Memory for opcodes DllStructSetData($tCodeBuffer, 1, $binarycode) ;set asm-code into memory ;call asm-code $ret = DllCallAddress("uint:cdecl", DllStructGetPtr($tCodeBuffer), "ptr", $ptr_bitmap, "int_ptr", $DesktopWidth, "int_ptr", $DesktopHeight) _DeleteBitmap32($hdc_bitmap, $ptr_bitmap, $hbmp) ;Ressourcen freigeben Return Hex($ret[0], 8);get average colour EndFunc ;==>Screen_Average_Colour Func _CreateNewBmp32($iwidth, $iheight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe $HDC und $ptr und handle auf die Bitmapdaten $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette DllStructSetData($tBMI, 2, $iwidth) DllStructSetData($tBMI, 3, -$iheight) ;minus =standard = bottomup DllStructSetData($tBMI, 4, 1) DllStructSetData($tBMI, 5, 32) ;32 Bit = 4 Bytes => AABBGGRR $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0) $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC Return $hcdc ;DC der Bitmap zurückgeben EndFunc ;==>_CreateNewBmp32 Func _DeleteBitmap32($DC, $ptr, $hbmp) _WinAPI_DeleteDC($DC) _WinAPI_DeleteObject($hbmp) $ptr = 0 EndFunc ;==>_DeleteBitmap32
    1 point
  12. czardas

    Odd Math Results

    I fail to understand this. It's not possible for me to reproduce your error for two reasons. Firstly you haven't provided the code which causes this problem (or is the message box code you posted not working when compiled and exported to a new system - I'm confused). Secondly I don't have two Dell Optiplex 7020's available to test it. However it is plausible that the discrepancy is caused by a Windows bug. You seem to have narrowed down the problem to a numeric expression, but that might not be the issue. I didn't see a problem with the expression you provided, which returns 2876127461106515968. You might want to take a look at operator64 in my signature: which may provide a little insight, but then again it might not. There are some inconsistencies occurring when using standard operators, especially with large integers (ODD MATH RESULTS). Please be aware that the functions in operator64 are a lot slower than standard operators, so they should only be used sparingly. If you get an unexpected result from a mathematical expression - it might be worth testing the same expression using the UDF functions to see if there is a difference. I'm still doubtful that this is a maths error - you haven't given enough details. The code you posted works fine on my machine.
    1 point
  13. I've got some coordinate from IE which is relative to browser's client area. However, it seems that _ScreenCapture_CaptureWnd() is expecting window-relative coordinate. How can I convert my client area relative coord to the one _ScreenCapture_CaptureWnd() needed?
    1 point
×
×
  • Create New...