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

    • siva1612
      By siva1612
      I would like to create a window like the one shown below. The requirements are as below
      1. The title bar should be opaque.
      2. The parent window/Main screen will be below the side menu/child window
      3. The left side of the side menu window should be opaque.
      4. The right side should be semi-transparent. 

       
      Any idea to help?
    • Lights_On
      By Lights_On
      Hi all,

      I am having a little trouble with ‘GUICtrlSetResizing’ an hoping someone could push me in the direction of best practice.

      I have a basic GUI created to a set size with the enabled abilities to resize it:

      GUICreate("Test", 500, 450, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

      Inside this I have an image and label:

      GUICtrlCreateLabel($Image1StampInfo, 10, 395, 480, 20, $SS_CENTER) GUICtrlCreatePic($TheImage, 25, 25, 450, 350)

      Using:

      Case ($GUI_EVENT_MAXIMIZE or $GUI_EVENT_RESTORE or $GUI_EVENT_RESIZED)

      I activate:

       
      GUICtrlSetResizing($TheImageBox, $GUI_DOCKAUTO) GUICtrlSetResizing($Image1Stamp, $GUI_DOCKAUTO)

      This works fine with the image but not with the label – the label after a bit of resizing seems to get stuck in different places in the GUI as if the $GUI_DOCKAUTO has not worked properly.

      So 2 questions if I may. 

      1)    Have I used $GUI_DOCKAUTO incorrectly for use with lables?

      2)    I am happy to manually set new sizes dynamically but how? I can get the size of the window with ‘WinGetPos()’ but how do I set new size parameters for the ‘label’ and ‘image’?

      Thank you in advance.

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys ( almost good night here in Italy )  
      How are you? Hop you're fine  
      I'm trying to do a Login Form ( I did, but I'm missing something in the management ), that allows the user to login when the script is launched, and, when the main GUI is opened, the user can Logout and Login with another username and password.
      The username and password "checking" I do is done by a text file, which in there are username and password, crypted through _Crypt_EncryptData().
      The "issue" I'm having at the moment, is to manage the Login form when the user hasn't already done the login, and so, the main GUI is not visible, but is created...
      I create the main GUI after the Login form... I tried with WinActive, WinGetState, but nothing changed ( even at the first Login, the script says ( through a MsgBox ) that the Win does exists ( or is active... ) and, as I want, it is not shown again...

      I really don't know If I missed something, or, I don't know...
      I'm going crazy for this thing...
      If someone could help me, I'd really appreaciate it!
      Thanks for the reading
      #Region ### START Koda GUI section ### Form=C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione_Magazzino_v2\form_Login.kxf Global $form_Login = GUICreate("Effettua il Login per continuare:", 405, 120, @DesktopWidth/2 - 202.5, @DesktopHeight/2 - 150) ; 302, 218 GUISetOnEvent($GUI_EVENT_CLOSE, "GUIDeleteLogin") Global $combo_Username = GUICtrlCreateCombo("Di Muro Francesco", 104, 64, 217, 25) GUICtrlSetFont(-1, 10, 400, 0, "Arial") GUICtrlSetData($combo_Username, "somedata") Global $input_Password = GUICtrlCreateInput("", 104, 89, 217, 25, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) GUICtrlSetFont(-1, 10, 400, 0, "Arial") $button_VerificaDati = GUICtrlCreateButton("", 328, 66, 42, 42, $BS_ICON) GUICtrlSetImage(-1, "C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione_Magazzino_v2\Icone\icon_check.ico", -1) GUICtrlSetOnEvent($button_VerificaDati, "CheckLogin") $label_Titolo = GUICtrlCreateLabel("Login", 167, 14, 71, 33) GUICtrlSetFont(-1, 18, 800, 0, "Arial") $label_Username = GUICtrlCreateLabel("Username :", 24, 64, 76, 20) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $label_Password = GUICtrlCreateLabel("Password :", 24, 89, 73, 20) GUICtrlSetFont(-1, 10, 800, 0, "Arial") #EndRegion ### END Koda GUI section ### Func CheckLogin() Local $sUsername = GUICtrlRead($combo_Username) Local $sPassword = GUICtrlRead($input_Password) MsgBox($MB_ICONINFORMATION, "", "Username: " & $sUsername & @CRLF & "Password: " & $sPassword) Local $sFileUtenti = @ScriptDir & "\utenti.txt" If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante la lettura del file!") Exit Else Local $hFileUtenti = FileOpen($sFileUtenti, $FO_READ) If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file " & $sFileUtenti & "." & @CRLF & "Errore: " & @error) Else Local $sDatiUtente, $aDatiUtente Local $bUtenteTrovato = False Local $iLinea = 1 Local $sControlloWin = "" Local $sWin = WinGetState($form_GestioneMagazzino) MsgBox($MB_ICONINFORMATION, "", $sWin) If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante la verifica della GUI attiva." & @CRLF & "Errore: " & @error) EndIf If($sWin == 5) Then MsgBox($MB_ICONINFORMATION, "", "La GUI esiste!") Do $sDatiUtente = FileReadLine($hFileUtenti, $iLinea) $aDatiUtente = StringSplit($sDatiUtente, "|", $STR_NOCOUNT) If(BinaryToString(_Crypt_DecryptData($aDatiUtente[0], "CRYPT", $CALG_RC4)) = $sUsername And BinaryToString(_Crypt_DecryptData($aDatiUtente[1], "CRYPT", $CALG_RC4)) = $sPassword) Then $sControlloWin = "ESISTE" $bUtenteTrovato = True ExitLoop Else $iLinea+=1 If($sDatiUtente = "" And $bUtenteTrovato = False) Then MsgBox($MB_ICONWARNING, "Attenzione!", "Username o Password errati.") ExitLoop EndIf EndIf Until $bUtenteTrovato = True Else MsgBox($MB_ICONINFORMATION, "", "La GUI esiste!") Do $sDatiUtente = FileReadLine($hFileUtenti, $iLinea) $aDatiUtente = StringSplit($sDatiUtente, "|", $STR_NOCOUNT) If(BinaryToString(_Crypt_DecryptData($aDatiUtente[0], "CRYPT", $CALG_RC4)) = $sUsername And BinaryToString(_Crypt_DecryptData($aDatiUtente[1], "CRYPT", $CALG_RC4)) = $sPassword) Then $sControlloWin = "NON ESISTE" $bUtenteTrovato = True ExitLoop Else $iLinea+=1 If($sDatiUtente = "" And $bUtenteTrovato = False) Then MsgBox($MB_ICONWARNING, "Attenzione!", "Username o Password errati.") ExitLoop EndIf EndIf Until $bUtenteTrovato = True EndIf If($sControlloWin = "ESISTE") Then MsgBox($MB_ICONINFORMATION, "Login effettuato!", "Hai effettuato l'accesso come: " & @CRLF & $sUsername & ".") ; Setta come "non-cliccabile" il bottone di Login GUICtrlSetState($button_Login, $GUI_DISABLE) GUICtrlSetState($button_VisualizzaGiacenze, $GUI_ENABLE) GUICtrlSetState($button_AggiungiProdotto, $GUI_ENABLE) GUICtrlSetState($button_PrelevaProdotto, $GUI_ENABLE) GUICtrlSetState($button_RicercaProdotto, $GUI_ENABLE) GUICtrlSetState($button_CreaDDT, $GUI_ENABLE) GUICtrlSetState($button_MostraGiacenzeAZero, $GUI_ENABLE) GUICtrlSetState($combo_Magazzino, $GUI_ENABLE) GUICtrlSetState($button_Logout, $GUI_ENABLE) ; Setta come "non-cliccabile" il bottone di Login GUICtrlSetState($button_Login, $GUI_DISABLE) ; Setta l'utente che ha effettuato l'accesso nella label $label_CaptionUtente GUICtrlSetData($label_CaptionUtente, $sUsername) ; "Distruggi" la GUI Login GUIDelete($form_Login) FileClose($hFileUtenti) Else MsgBox($MB_ICONINFORMATION, "", "La GUI non esiste!") MsgBox($MB_ICONINFORMATION, "Login effettuato!", "Hai effettuato l'accesso come: " & @CRLF & $sUsername & ".") ; Mostra la GUI Principale GUISetState(@SW_SHOW, $form_GestioneMagazzino) ; Setta come "non-cliccabile" il bottone di Login GUICtrlSetState($button_Login, $GUI_DISABLE) ; Setta l'utente che ha effettuato l'accesso nella label $label_CaptionUtente GUICtrlSetData($label_CaptionUtente, $sUsername) ; "Distruggi" la GUI Login GUIDelete($form_Login) FileClose($hFileUtenti) EndIf EndIf EndIf EndFunc Func Logout() GUICtrlSetData($label_CaptionUtente, "") MsgBox($MB_ICONINFORMATION, "Logout effettuato!", "Effettua nuovamente il Login per utilizzare il programma.") ; Disabilita tutti i bottoni della GUI Principale GUICtrlSetState($button_VisualizzaGiacenze, $GUI_DISABLE) GUICtrlSetState($button_AggiungiProdotto, $GUI_DISABLE) GUICtrlSetState($button_PrelevaProdotto, $GUI_DISABLE) GUICtrlSetState($button_RicercaProdotto, $GUI_DISABLE) GUICtrlSetState($button_CreaDDT, $GUI_DISABLE) GUICtrlSetState($button_MostraGiacenzeAZero, $GUI_DISABLE) GUICtrlSetState($combo_Magazzino, $GUI_DISABLE) GUICtrlSetState($button_Logout, $GUI_DISABLE) ; Abilita il Login GUICtrlSetState($button_Login, $GUI_ENABLE) EndFunc EDIT:
      Solved, making an "integrated" Login form... 
    • AnonymousX
      By AnonymousX
      Hello, 
      I'm wondering if it is possible to read a radio button off a GUI running by another program? 
      Someone created these Outlook emails that when open appear to be in a GUI format. I could easily come up with a way of navigating these fields by using tab inputs, and then copying specific fields that I need. However there is a spot on the form that has 4 choices of radio buttons, asking for what the status of the task is, and I have no idea how to store which one of these was pressed. 
      End game is to be able to go through thousands of these forms, take input from specific fields from this GUI form in outlook and copy into cells in an excel spreadsheet. I believe I could create a script to do everything I need, if I could just obtain the value from which radio button was pressed.
      Any advice on how to obtain which radio button was press in this outlook form would be appreciated.
      Thanks,
      If I knew VBA better Outlook might have its own functions for figuring this out.
       
      Example:

      In this example I'd want to be able to know that the 2nd or Assigned radio button was selected. Only 1 button is able to be selected at a time. I'm assuming the way to do this would be to tab through the form get to the first box and then run some command to check if pressed then if no, keep checking till I find which of the 4 were pressed.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      How are you? Hope you're fine
      I'm doing some field checking...
      Can you suggest me something? Something like: If the user doesn't prompt anything in a field, MsgBox and focus on the "blank" field, else, keep up with the script.
      I thought on a nested If...Else, but I have something like 10+ edit to control...
      Thanks guys! 
      EDIT:
      And I would like to know either how to retrieve all listview item ( 2 columns ) from a ListView...
      Column A|Column B
      abcd         | 1234
      bcda         | 1432
      How can I retrieve an array with abcd|1234|bcda|1432 ?
      Thanks