Search the Community
Showing results for tags 'WM_COMMDAND'.
-
Hi all, I've been studying WM_NOTIFY and WM_COMMAND for a hobby project I'm working on. At this point, I'm trying to capture the WM_COMMAND event that happens when the focus is on the Input control and the user presses the ENTER key. I know I could do this via _IsPressed(), but I'd really rather do everything from within WM_COMMAND and WM_NOTIFY. It just seems like better coding practice. Anyway, this is probably simpler than I think it is, but I'm really stuck. I made a script that outputs WM_NOTIFY and WM_COMMAND events to the console as they happen. Here's my problem. When I press ENTER while the focus is on the Input control, this is the output I get: ========================================================== Event: WM_COMMAND (unknown) $hWnd: 0x00050408 $iMsg: 273 $WM_COMMAND: 273 $iwParam: 0x00000001 $iIDFrom: 1 $iCode: 0 $ilParam: 0x00000000 11:45:42:740 ========================================================== It looks like a command is coming from nowhere ($ilParam = 0) and doing nothing. Can anyone help me understand this? I've been all over the AutoIt Forums and MSDN and I'm still not understanding. I was expecting to see a key code for the ENTER key somewhere, or some kind of message like $WM_INPUT_CONFIRM or something. Here's the script I wrote to get the output: Global Const $tagNMHDR = "struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct", _ $WM_COMMAND = 0x0111, _ $WM_NOTIFY = 0x004E, _ $GUI_EVENT_CLOSE = -3, _ $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG' Global $gui = GUICreate("ComboBox Listener", 300, 300) Global $combo = GUICtrlCreateCombo("", 10, 10) GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4|Item 5|Item 6") Global $input = GUICtrlCreateInput("", 10, 100) Global $button = GUICtrlCreateButton("Test", 10, 200) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Do Until GUIGetMsg() == $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case GUICtrlGetHandle($combo) WM_Output("WM_NOTIFY", $iCode, "Combo") Case GUICtrlGetHandle($input) WM_Output("WM_NOTIFY", $iCode, "Input") Case GUICtrlGetHandle($button) WM_Output("WM_NOTIFY", $iCode, "Button") Case $gui WM_Output("WM_NOTIFY", $iCode, "GUI") Case Else WM_Output("WM_NOTIFY", $iCode, $hWndFrom) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) Switch $hWndFrom Case GUICtrlGetHandle($combo) WM_Output("WM_COMMAND", $iCode, "Combo") Case GUICtrlGetHandle($input) WM_Output("WM_COMMAND", $iCode, "Input") Case GUICtrlGetHandle($button) WM_Output("WM_COMMAND", $iCode, "Button") Case $gui WM_Output("WM_COMMAND", $iCode, "GUI") Case Else ConsoleWrite("==========================================================" & @LF) ConsoleWrite("Event: WM_COMMAND (unknown)" & @LF) ConsoleWrite("$hWnd: " & $hWnd & @LF) ConsoleWrite("$iMsg: " & $iMsg & @TAB & "$WM_COMMAND: " & $WM_COMMAND & @LF) ConsoleWrite("$iwParam: " & $iwParam & @TAB & "$iIDFrom: " & $iIDFrom & @TAB & "$iCode: " & $iCode & @LF) ConsoleWrite("$ilParam: " & $ilParam & @LF) ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @LF) ConsoleWrite("==========================================================" & @LF & @LF) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_Output( $Event, $iCode, $Control ) ConsoleWrite("==========================================================" & @LF) ConsoleWrite("Event: " & $Event & @LF) ConsoleWrite("$iCode: " & $iCode & @LF) ConsoleWrite("Control: " & $Control & @LF) ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @LF) ConsoleWrite("==========================================================" & @LF & @LF) EndFunc