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

    • rm4453
      Custom Stream GUI Using Autoit Gui Wrap
      By rm4453
      Hey guys! I need to find a way to wrap an autoit gui around a game. I am planning on making a custom gui overlay for interacting with my stream, which will allow me to run giveaways and stuff like that. But I need to find a way to force the steam games to run inside my autoit gui... I have the following code so far credit to those I took code from and modified to suite my needs "can't remember who u are pls post if i owe ty to u" If I select notepad and launch it then it works great! and the notepad window is wrapped inside my gui. However if I try it with teamfortress 2 it won't work...
       
      #include <Array.au3> #include <File.au3> #include <WinAPI.au3> #include <GUIConstants.au3> Local $msg, $hwnd, $WinHwnd ;===> UDV Start $pid = 0 $Hidden = 0 $exe = 0 $sDrive = 0 $sDir = 0 $sFileName = 0 $sExtension = 0 ;===> UDV End $hwnd = GUICreate("hello") $Open = GUICtrlCreateButton("Launch Game", 10, 30, 75, 25) $Select = GUICtrlCreateButton("Select Game", 10,60,75,25) GUISetState() ;===> UDF START Func _GetWinHwnd($pid) $aWinlist = WinList() For $i = 1 To $aWinlist[0][0] If $pid = WinGetProcess($aWinlist[$i][0]) Then Return $aWinlist[$i][0] Next EndFunc ;==>_GetWinHwnd Func _SetParentWindow($pid) $WinInfo = _GetWinHwnd($pid) $WinHwnd = ControlGetHandle($WinInfo, "", "") _WinAPI_SetParent($WinHwnd, $hwnd) _WinAPI_SetWindowLong($WinHwnd, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE) WinMove($WinHwnd, "", 0, 0) EndFunc ;==>_SetParentWindow Func RedrawGui($RedrawMe) If ProcessExists($pid) And $Hidden = 0 Then GUICtrlSetState($RedrawMe, @SW_HIDE) $Hidden = 1 sleep(50) _WinAPI_RedrawWindow($pid) Sleep(50) ElseIf $Hidden = 1 And Not ProcessExists($pid) Then GUICtrlSetState($RedrawMe, @SW_SHOW) $Hidden = 0 EndIf EndFunc ;===> UDF END While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE If ProcessExists($pid) Then ProcessClose($pid) GUICtrlSetState($Open, @SW_SHOW) Else Exit EndIf Case $Open GUICtrlSetState($Open, @SW_HIDE) Sleep(100) $pid = Run('"' & $exe & '" -game tf -steam') #cs This RUN CMD is custom made for testing with TF2 change to just $exe to select any exe you want to test with -game tf specifies to launch tf2 and -steam gets rid of insecure mode error #ce RedrawGui($Open) ProcessWait($pid) Sleep(5500) _GetWinHwnd($pid) _SetParentWindow($pid) Case $Select $exe = FileOpenDialog("Please select your game!", @ScriptDir, "Executable File (*.exe)", "1", "Process Selection") Sleep(50) FileChangeDir(@ScriptDir) _PathSplit($exe, $sDrive, $sDir, $sFileName, $sExtension) EndSwitch WEnd  
    • FrankSchneidewind
      [GUI] Drag&Drop files -> Get filename
      By FrankSchneidewind
      Hi all,
      I got a quick question regarding Drag&Drop with GUIs. I made a little script that does something with files and I need a way to get the name/path of the file when I drag&drop it into the GUI. Is there a quick way to do this?

      Tyvm in advance!
      Neo
    • Comboku
      Recognizing when focus leaves the input field?
      By Comboku
      Hi Guys,
      i am working on a translation app. There are a couple of regular input fields with text that the user is supposed to change to a new language. 
      I want to change the color of the input field  as soon as the user leaves the input field. Is there a way to do that? 
      I know how to do this with a button, but i don't know how i can work with focus. Has any of you done something like this before?
       
      Thanks!
    • Wingens
      Metro style combo
      By Wingens
      Hi all,
      I created a little script we use at work for inputing date and time stamps into our ticket system.
      Now I thought it would look nice in a Metro style GUI, I found an UDF on the forum what does almost everything I want.
      I have but one thing I can't seem to find and don't have the skills to create.
      The gui uses one pulldown menu (GUICtrlCreateCombo) it stays in the older looking style.
      I attached the script and files I have, also in the zip you find an example of what I am looking for.
       
      Hope you guys can help me 
      Hotkey.zip
    • jaberwacky
      GuiBuilderNxt - Reboot [08/18/2016]
      By jaberwacky
      This is an update to GuiBuilder (CyberSlug, Roy, TheSaint, and many others) to run on the latest AutoIt Beta release.
       
      For a chronological history of GuiBuilder and other GUI designers see: >AutoIt GUI Creators (Designers).
      The seed of this effort is >here.
      Note: This is early stage software.  Please help by reporting issues.
      -----------------------------------------------------
      Now for the latest exciting installment!  Tabs are now available!  One tab can be added to the GUI.  Move it, resize it, and right click to add a new tab item!  More context menu items on the way.  Also upcoming is the ability to be able to add controls to each tab item.
      ---------------------------------------------------------
      GUIBuilderNxt - Reboot.zip - Exe included.
      dl: 4286
      Changelog:
      New Features and fixes:
      1) Show or hide control while moving or resizing control. *Currently bugged out*
      2) Option to show controls which have had their state set to hidden.
      3) Properties window for each control as they are selected.  This makes fine tuning a control easier.
      4) A button which will resize a control's width to fit the text.  Uses Melba23's _StringSize library.
      5) Remembers settings from the last session.
      6) GuiOnEvent mode.  CyberSlug made mention of wanting to do this in the early days of GuiBuilder.
      7) Maps rather than multidimensional arrays.
      8) Consistent control naming, (i.e., instead of Group1, Button2, Button3, Radio4 it would now be Group1, Button1, Button2, Radio1).
      9) Restructured the menubar layout per GuiBuilder Resurrected.
      10) Hotkeys switched to accelerators.
      11) Option to wipe the gui clear to the Edit menu.
      12) Select and move multiple controls at once by holding down Ctrl or using a selection rectangle.
      13) Copy, Paste and Delete multiple controls at once.
      14) Solid grid background that now resizes to fit the GUI.
       
      Roadmap:
      1) Get the Tab control to work correctly. *Still in progress*
      2) Finish adding properties settings to the control properties window.
      3) Make the code generation produce code with a better layout.
      4) Common GUI templates.  Ability to make your own templates too.
      5) Select multiple controls and use arrow keys (or other method?) to snap the selected controls to align to the chosen edge.
      6) Visual hints to tell you when you're within so many pixels from the edge of the window or control.  Mimics the gui designer of Visual Basic.
      7) Double click a control to edit the text.
      8) Visual hints to indicate selected controls, etc.
      9) Ability to create and store custom controls.
       
      Known issues:
      1)Many!