Search the Community
Showing results for tags 'lvn_keydown'.
-
Hi. Attempting to catch and process a keystroke in a GUI window. Here's the code: ; ---------------------------------------------------------------------- ; | Library includes ; ---------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> #include <WinAPISys.au3> #include <WinAPIvkeysConstants.au3> #include <GuiButton.au3> global $g_MainGUI CreateMainGUI() ; ---------------------------------------------------------------------- func CreateMainGUI() $g_MainGUI = GUICreate("Test", 600, 600, -1, -1) ; $b = _GUICtrlButton_Create($g_MainGUI, "Foo", 10, 10, 100, 30) ; <--- Line #21 $lv = _GUICtrlListView_Create($g_MainGUI, "", 50, 50, 100, 100) ; <--- Line #22 GUISetState(@SW_SHOW, $g_MainGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") do ; until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() endfunc ; ---------------------------------------------------------------------- func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) local $hdr = DllStructCreate($tagNMHDR, $lParam) local $from = HWnd(DllStructGetData($hdr, "hWndFrom")) local $id = DllStructGetData($hdr, "IDFrom") local $event = DllStructGetData($hdr, "Code") ; Exit on [ctrl-Q] if ($event = $LVN_KEYDOWN) then $info = DllStructCreate($tagNMLVKEYDOWN, $lParam) $vkey = DllStructGetData($info, "VKey") if ($vkey = 0x51) and BitAND(_WinAPI_GetKeyState($VK_CONTROL), 0x8000) then ConsoleWrite('[ctrl-Q]' & @CRLF) ; <--- Line #48 _SendMessage($g_MainGUI, $GUI_EVENT_CLOSE) endif endif return $GUI_RUNDEFMSG endfunc There are two things about this code that don't work the way I expected, and I've been unable to figure out why: 1) As it stands, the code creates a GUI window, then a ListView. If I run it then immediately press ctrl-Q, the keystroke triggers WM_NOTIFY(). I know that because if I run in SciTE, '[ctrl-Q]' appears in the console window, so the ConsoleWrite() call on line #48 must have executed. If I comment out the _GUICtrlListView_Create() call on line #22 and uncomment line #21 so that a Button is created instead, then run it, WM_NOTIFY() is never triggered. Why the difference? Doesn't the GUIRegisterMsg() call register WM_NOTIFY on behalf of the parent GUI? Why does it work with one control type, but not the other? 2) In the case with the ListView control, where it does catch the ctrl-Q, it executes _SendMessage($g_MainGUI, $GUI_EVENT_CLOSE). In my simple mind, I'd have thought that would send the $GUI_EVENT_CLOSE message to the main GUI and cause it to exit the do/until loop. But evidently not? Because it doesn't. Thanks in advance. Just when I think I understand ... /John