#cs ------------------------------------------------------------------------------------------- Scripted in ....: AutoIt v3.3.14.5 Scripted on ....: Windows 10 Home Version: 1803 (DOS VER: 10.0.17134.860) Date Started ...: [06.19.2019] Last Updated ...: [06.29.2019] Author .........: Jeffrey Lee Treat Script Function: Testing way to detect left double click in a ListView in x86 & x64. Also testing way to detect [Enter] key pressed in x86 and x64 mode. Script Notes: Program can be ran in (x86) or (x64) mode. x86 = 32-bit mode x64 = 64-bit mode MS-Windows User32.dll file can be used in either (x86) or (x64) mode. #ce ------------------------------------------------------------------------------------------- #include #include ;-------------------------- Global $GetMessage = 0 Global $WindHandle = 0 Global $ViewCtrlID = 0 Global $ViewCtrlHd = 0 Global $RowNumPick = 0 ;--------------------- Global $Element001 = 0 Global $Element002 = 0 Global $Element003 = 0 Global $FuncParam1 = 0 Global $FuncParam2 = 0 Global $FuncParam3 = 0 Global $FuncParam4 = 0 ;--------------------- Global $DoublClick = False Global $User32Dll1 = @WindowsDir& "\System32\user32.dll" ;---------------------------------------------------------------------------------------------- $WindHandle = GUICreate("ListView Selection Demo", 400, 300) $ViewCtrlID = GuiCtrlCreateListView("List Column|ze", 10, 20, 380, 250) $ViewCtrlHd = GUICtrlGetHandle($ViewCtrlID) ;----------------->> Get WinHandle of Control ID For $i = 1 To 20 GuiCtrlCreateListViewItem("Item|ze " & $i, $ViewCtrlID) ;->> Populate ListView with Data Next GUISetState(@SW_SHOW) $HUser32DLL = DllOpen($User32Dll1) ;-------------------------->> Open MS-Win User32.dll File GUIRegisterMsg($WM_NOTIFY, "_WMsgNotify01") ;----------------->> Register WM: Window Message While 1 $GetMessage = 0 $GetMessage = GUIGetMsg() If $GetMessage = -3 Then ExitLoop ;----------------------->> -3 = $GUI_EVENT_CLOSE If _IsPressed("0D", $HUser32DLL) Then ;------------------->> OD = The [Enter] key Do Sleep(10) ;--------------------------------------->> Loop Until IsPressed Resets Until _IsPressed("0D", $HUser32DLL) = 0 If WinActive($WindHandle) <> 0 Then $DoublClick=True ;>> If Active Set D-Click = TRUE EndIF If $DoublClick = True Then _LDoubleClick() ;------------------------------------->> If True run _LDoubleClick Func $DoublClick = False ;--------------------------------->> Reset D-Click back to False Do Sleep(10) ;--------------------------------------->> Loop Until IsPressed Resets Until _IsPressed("0D", $HUser32DLL) = 0 EndIf WEnd GUIRegisterMsg($WM_NOTIFY, "") ;------------------------------>> De-Register Window Messages DllClose($HUser32DLL) ;--------------------------------------->> Close MS-Win User32.dll File MsgBox(64, "$TagStruct1 Elements", "$TagStruct1 Elements [1-3] = ["&$Element001&"] ["&$Element002&"] ["&$Element003&"]", 90, $ViewCtrlHd) MsgBox(64, "Control-ID / Win-Handle", "Control ID = ["&$ViewCtrlID&"] / Control's Window Handle = ["&GUICtrlGetHandle($ViewCtrlID)&"]", 90, $ViewCtrlHd) MsgBox(64, "Function Parameters", "Parameters [1-4] = ["&$FuncParam1&"] ["&$FuncParam2&"] ["&$FuncParam3&"] ["&$FuncParam4&"]", 90, $ViewCtrlHd) MsgBox(64, "Main Window Handle", "Main Window Handle = ["&$WindHandle&"]", 90, $ViewCtrlHd) GUIDelete() MsgBox(64, "Exit", "End of Program", 5) Exit ;-------------------------------------------------------->> Terminate the script (-Exit-) ;********************************************************************************************** ;---------------------------------------------------------------------------------------------- Func _LDoubleClick() $RowNumPick = GUICtrlRead(GUICtrlRead($ViewCtrlID)) MsgBox(64, "Window Message Detected", "Left-Button was D-Clicked or [Enter] was pressed", 10, $ViewCtrlHd) MsgBox(64, "Row Data Selected", "Row data selected = " &$RowNumPick, 10, $ViewCtrlHd) EndFunc ;==>_LDoubleClick ;---------------------------------------------------------------------------------------------- Func _WMsgNotify01($hWnd, $iMsg, $wParam, $lParam) $FuncParam1 = $hWnd ;------------------------------------->> Gets Func Parameter Number 1 $FuncParam2 = $iMsg ;------------------------------------->> Gets Func Parameter Number 2 $FuncParam3 = $wParam ;----------------------------------->> Gets Func Parameter Number 3 $FuncParam4 = $lParam ;----------------------------------->> Gets Func Parameter Number 4 Local $TagStruct1 = 0 ;----------------------------------->> Declares the struct variable #cs --------------------------------------------------------------------------------------- The $wParam and $lParam parameters hold exactly what the notification message is and the Child-Control-Window-Handle that it was sent from. NMHDR: N = Notification / M = Message / HDR = HeaDeR (Header) $wParam parameter holds the identifier (notification codes) of the Child-Control-Window that the message was sent from. This identifier is not guaranteed to be unique so it needs to use the hwndFrom or idFrom member of the NMHDR structure (passed in the $lParam parameter) to identify the control. $lParam parameter holds the pointer to an NMHDR structure that contains the notification codes, the hwndFrom or idFrom member of the NMHDR structure and other additional information. $tagNMHDR is a AutoIt Keyword that has been pre-set to hold data about a notification message: (Global Const $tagNMHDR = "struct; hwnd hWndFrom; uint_ptr IDFrom; INT Code; endstruct") $TagStruct1 = DllStructCreate($tagNMHDR, $lParam): Struct will contain hwndFrom, idFrom & code $hWndFrom = HWnd(DllStructGetData($TagStruct1, "hWndFrom")) Extracts the WinHandle of Ctrl-ID $IDFrom = BitAND($wParam, 0xFFFF) LoWord - Extracts the ID of the Control sending a message $Code = BitShift($wParam, 16) HiWord - Extracts the Notification Code Number: like a -3 Note: If a DOUBLE left button click is detected then the Notification Code will = -3 Note: Some other MOUSE BUTTON CODES are listed at the very bottom of this script. Pointer is being supplied (by $lParam) so the struct variable will not be allocating memory #ce --------------------------------------------------------------------------------------- $TagStruct1 = DllStructCreate($tagNMHDR, $lParam) ;------->> Setup Var for DllStruct calls If @error Then Exit ;------------------------------------->> If Error terminate the script $hWndFrom = HWnd(DllStructGetData($TagStruct1, "hWndFrom")) $IDFrom = DllStructGetData($TagStruct1, "IDFrom") $Code = DllStructGetData($TagStruct1, "Code") $Element001 = $hWndFrom ;--------------------------------->> Holds Struct Element Number 1 $Element002 = $IDFrom ;----------------------------------->> Holds Struct Element Number 2 $Element003 = $Code ;------------------------------------->> Holds Struct Element Number 3 ;; The following is another way to get the same results... ;; ------------------------------------------------------- ;; $Element001 = DllStructGetData($TagStruct1, 1) ;---------->> Gets Struct Element Number 1 ;; $Element002 = DllStructGetData($TagStruct1, 2) ;---------->> Gets Struct Element Number 2 ;; $Element003 = DllStructGetData($TagStruct1, 3) ;---------->> Gets Struct Element Number 3 If $Element001 = $ViewCtrlHd Then ;---------->> If the Windows Handles match THEN... If $Element003 = -3 Then ;--------------->> If Notify code = Left-Double-Click THEN... $DoublClick = True ;----------------->> Set the Double-Click-Flag variable to TRUE EndIf EndIf $TagStruct1 = 0 ;--------------------------------------->> Clears the -DllStruct- variable Return $GUI_RUNDEFMSG ;--------------------------------->> Tells AutoIt to process message EndFunc ;==>_WMsgNotify01 ;---------------------------------------------------------------------------------------------- ;********************************************************************************************** #cs ------------------------------------------------------------------------------------------- *** MOUSE BUTTON CODES *** ----------------------------------------------------------------------------------------------- $NM_CLICK = -2 Left mouse button clicked once $NM_DBLCLK = -3 Left mouse button double-clicked $NM_RCLICK = -5 Right mouse button clicked once $NM_RDBLCLK = -6 Right mouse button double-clicked #ce -------------------------------------------------------------------------------------------