Sign in to follow this  
Followers 0
Artisan

Input control and WM_COMMAND [SOLVED]

4 posts in this topic

#1 ·  Posted (edited)

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
Edited by Artisan

Share this post


Link to post
Share on other sites



You can use it just like this:

$GUI_EVENT_CLOSE = -3

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)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $input Then ConsoleWrite('Event from input control, value: ' & GUICtrlRead($input) & @CRLF)
WEnd

But this event is fired also when you change focus from input control to other control (and only when Enter is pressed on focused input control).

1 person likes this

Share this post


Link to post
Share on other sites

You may look here at example of WM_COMMAND for input control

Thanks. I've already got a decent handle on WM_COMMAND, so this wasn't quite what I was looking for. (I just wanted to know when the user finished inputting.)

You can use it just like this:

$GUI_EVENT_CLOSE = -3

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)

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
If $msg = $input Then ConsoleWrite('Event from input control, value: ' & GUICtrlRead($input) & @CRLF)
WEnd

But this event is fired also when you change focus from input control to other control (and only when Enter is pressed on focused input control).

That's PERFECT! ALso, *facepalm* for not thinking to try that myself. That's exactly what I needed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • algiuxas
      GUI Show/Hide Cursor [SOLVED]
      By algiuxas
      Hello,
      I want that when mouse cursor is in GUI, cursor would hide, and when cursor is outside GUI it would appear again.

      (Sorry for my bad English)
    • Tirk
      How can I move a GUI wiindow
      By Tirk
      How can I move a GUI window? How can I adjust the gui's position (coordinates) ?
      ... When I click to the green four-way arrow and move the mouse --> move the gui window.

    • PINTO1927
      png with background transparent into gui without border
      By PINTO1927
      Hi guys, I would like to make a gui borderless viewing a png image with transparent background.
       
      pretty much has to be visible only the png image with no background..you have any simple example?
      Thank's
      GUICtrlCreatePic  
      still it provides the image with the background...
    • OldGuyWalking
      Identifying Button in Toolbar When There is no ControID
      By OldGuyWalking
      I want to click on a button that is inside a custom ToolBar on a nonAutoIT created form.  I've been using MouseClick but that fails if the toolbar is detached or if the form is resized.
      There is no ID associated with the toolbar but there is a handle.  I'm thinking that to get the handle I need a ControlID but that only gets me to the toolbar and I'd then need to have a way to identify the position of a button in order to click on it.  
      I'd found a discussion about identifying the position of a noname button by, I believe, it's Tip text back in December but I can't find it now.  Memory is a bit fuzzy on how I even got to the topic because at the time I was searching for something else.   I'll continue to search but if anyone has seen the topic, or knows of another solution could you please point me in that direction. 
      Thank you.
    • rootx
      Best way to play little video inside a Gui
      By rootx
      I would like to insert a video player inside the gui Autoit, preferably one with a free license such as Media Player Classic or VLC, I saw in the forum but I found examples of many years ago.
      Some examples links or advice would be much help