kcvinu

How to use all messages in GuiGetMsg()

42 posts in this topic

#1 ·  Posted (edited)

Hi all,
I am using GuiGetMsg(). Assume that i have a combo box in my gui. And when i use this code - 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CMB_NamesList     ; Handle of my Combo box
            CellSelect()     
    EndSwitch
WEnd

This code will call my "CellSelect()" function only when the selection change event occurred. But assume that i need to call this function right after the user clicks on the combo box. So do i need to use GuiRegisterMsg function for that ? Or can i simply do the task with GUIGetMsg() ? If the second option is possible, then i wonder how to do it. 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites



You need GuiRegisterMsg

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

Global $g_hCombo

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20)
    GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2")
    $g_hCombo = GuiCtrlGetHandle($idComboBox)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example


Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
                    _DebugPrint("$CBN_DROPDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
             EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text  & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

 

Share this post


Link to post
Share on other sites

@mikell , So GuiGetMsg is for a few limited messages. May i know what is the reason behind it ? 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,

That is a question that only Jon could answer, but I would hazard a guess that it is based on keeping the code simple for the less-experienced AutoIt user. Being able to use a simple ControlID in a loop to detect the most common events occurring to a control rather than having to create relatively complicated event handlers for every case would seem a pretty sensible design decision.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba23 ,

Thanks for your clarification. But it is an extra power for a programmer to use such messages with easiness. :)

 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,

And hence the introduction of GUIRegisterMsg which allows the more experienced coder to access virtually all of the messages associated with a control. But you definitely need to know what you are doing when you get to that level, so it is probably best that the newer coders are somewhat sheltered.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba23,

Yeah, i agree. New coders needs protection from the internal hazards. Eventhough, i am happy with using GuiRegisterMsg for this purpose, i am searching for easy methods to do these type of tasks. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Then the only way is to use a workaround 
But as GuiGetMsg allows detection of 90%+  of the usual control events  it should not be a great trouble  :)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Combo", 400, 296)
Local $idComboBox = GUICtrlCreateCombo("Item 1", 10, 10, 185, 20)
GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            $a = GUIGetCursorInfo()
            If $a[4] = $idComboBox Then ConsoleWrite("combo just clicked" & @crlf)     
        Case $idComboBox
            ConsoleWrite("combo item selected" & @crlf)      
    EndSwitch
WEnd

 

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

lol forgot about getcursorinfo and just wrote this mess...

Opt("MouseCoordMode", 2)
Local $iLeft = 10, $iTop = 10, $iWidth = 185, $iHeight = 20

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    Local $idComboBox = GUICtrlCreateCombo("Item 1", $iLeft, $iTop, $iWidth, $iHeight)
    GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2")
    $g_hCombo = GUICtrlGetHandle($idComboBox)
    GUISetState(@SW_SHOW)

    Local $msg = 0
    Do
        $msg = GUIGetMsg()
        If $msg = 0 Then ContinueLoop

        If $msg = -7 Then
            _PrimaryClick()
        EndIf

    Until $msg = -3
    GUIDelete()
EndFunc   ;==>Example


Func _PrimaryClick()
    $ix = MouseGetPos(0)
    $iy = MouseGetPos(1)
    ConsoleWrite($ix & @LF)
    ConsoleWrite($iy & @LF)
    If ($ix > $iLeft) And ($ix < ($iLeft + $iWidth)) Then
        If $iy > $iTop And $iy < $iTop + $iHeight Then
            ConsoleWrite("Clicked" & @LF)
        EndIf
    EndIf
EndFunc   ;==>_PrimaryClick

 

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
#include <MsgBoxConstants.au3>

Global Const $JOHN_ONE = "JohnOne"
Global Const $CRAP = "Magic Numbers"

Msgbox($MB_ICONWARNING, $JOHN_ONE, "Really, you used too much " & $CRAP)

:D

2 people like this

Share this post


Link to post
Share on other sites

You could at least extract from include this one

Global Const $GUI_EVENT_PRIMARYDOWN = -7

Just to make the code a little bit more understandable  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

If you compete to use magic numbers, then please comment the full names  for better reading. And you know @JohnOne , when i see the magic nums, i just skipped your script and went to the next.

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@mikell Really, that's a nice workaround for my problem. Thanks a lot. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
1 hour ago, kcvinu said:

If you compete to use magic numbers, then please comment the full names  for better reading. And you know @JohnOne , when i see the magic nums, i just skipped your script and went to the next.

Thanks for the heads up, I'll remember not to waste my time in future.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
2 hours ago, kcvinu said:

... i just skipped your script ...

kcvinu,
This is really not kind. You may dislike magic numbers however JO made the effort to write you an answer ...  :huh:

Share this post


Link to post
Share on other sites

Personally, I appreciate that sort of frankness, and do not take any kind of offense from it.

He does not bother reading a particular style of example, and I do not like wasting my time.

A communication is made, and everyone is happy. :)

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Oops ! I think my half English made a problom.  What i mean to say is - when i load this page, i saw 2 scripts as replys. One is from mikell and one is from johnone. At first glance, i saw the magic numbers in johnone's script and i thought read it later. Then i read mikell's reply. I didn't meant to say that i don't want jo's reply. @JohnOne I am really sorry for to make you think like that. I want your guidance and support in future since you are a senior and experienced member of this forum. I didn't meant to say that i avoid your reply. I just meant to say that i choose mikell's reply first and then yours. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>

Opt( "MustDeclareVars", 1 )

#cs
$CBN_SELCHANGE = 1
$CBN_DBLCLK = 2
$CBN_SETFOCUS = 3
$CBN_KILLFOCUS = 4
$CBN_EDITCHANGE = 5
$CBN_EDITUPDATE = 6
$CBN_DROPDOWN = 7
$CBN_CLOSEUP = 8
$CBN_SELENDOK = 9
$CBN_SELENDCANCEL = 10
#ce

Global $idCBN_FIRST
Global $hCombo1, $hCombo2

Example()


Func Example()
  Local $hGui = GUICreate( "(UDF) ComboBox Create", 400, 300 )

  ; Message IDs
  $idCBN_FIRST = GUICtrlCreateDummy() ; $CBN_SELCHANGE
  For $i = 0 To 8
    GUICtrlCreateDummy()              ; $CBN_DBLCLK to $CBN_SELENDCANCEL
  Next

  ; Combo 1
  Local $hChild1 = GUICreate( "", 396, 30, 2, 2, $WS_CHILD, -1, $hGui )
  GUISetState( @SW_SHOW, $hChild1 )
  $hCombo1 = _GUICtrlComboBox_Create( $hChild1, "", 0, 0, 396, 30 )

  ; Add files
  _GUICtrlComboBox_BeginUpdate( $hCombo1 )
  _GUICtrlComboBox_AddDir( $hCombo1, "", $DDL_DRIVES, False )
  _GUICtrlComboBox_EndUpdate( $hCombo1 )

  ; Combo 2
  Local $hChild2 = GUICreate( "", 396, 30, 2, 52, $WS_CHILD, -1, $hGui )
  GUISetState( @SW_SHOW, $hChild2 )
  $hCombo2 = _GUICtrlComboBox_Create( $hChild2, "", 0, 0, 396, 30 )

  ; Add files
  _GUICtrlComboBox_BeginUpdate( $hCombo2 )
  _GUICtrlComboBox_AddDir( $hCombo2, "", $DDL_DRIVES, False )
  _GUICtrlComboBox_EndUpdate( $hCombo2 )

  ; Callback function
  Local $pComboBoxCallback = DllCallbackGetPtr( DllCallbackRegister( "ComboBoxCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )

  ; Subclassing child windows
  _WinAPI_SetWindowSubclass( $hChild1, $pComboBoxCallback, 1, $hCombo1 ) ; $iSubclassId = 1, $pData = $hCombo1
  _WinAPI_SetWindowSubclass( $hChild2, $pComboBoxCallback, 2, $hCombo2 ) ; $iSubclassId = 2, $pData = $hCombo2
  ; Because we are subclassing the child windows, messages from the combo boxes only, will be handled by the callback function.

  ; Show GUI
  GUISwitch( $hGui )
  GUISetState( @SW_SHOW )

  ; Message loop
  Local $aMsg
  While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
      Case $hGui
        Switch $aMsg[0]
          Case $idCBN_FIRST + 0 ; $CBN_SELCHANGE = 1
            ConsoleWrite( "$CBN_SELCHANGE notificaton from "    & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 1 ; $CBN_DBLCLK = 2
            ConsoleWrite( "$CBN_DBLCLK notificaton from "       & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 2 ; $CBN_SETFOCUS = 3
            ConsoleWrite( "$CBN_SETFOCUS notificaton from "     & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 3 ; $CBN_KILLFOCUS = 4
            ConsoleWrite( "$CBN_KILLFOCUS notificaton from "    & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 4 ; $CBN_EDITCHANGE = 5
            ConsoleWrite( "$CBN_EDITCHANGE notificaton from "   & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 5 ; $CBN_EDITUPDATE = 6
            ConsoleWrite( "$CBN_EDITUPDATE notificaton from "   & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 6 ; $CBN_DROPDOWN = 7
            ConsoleWrite( "$CBN_DROPDOWN notificaton from "     & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 7 ; $CBN_CLOSEUP = 8
            ConsoleWrite( "$CBN_CLOSEUP notificaton from "      & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 8 ; $CBN_SELENDOK = 9
            ConsoleWrite( "$CBN_SELENDOK notificaton from "     & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )
          Case $idCBN_FIRST + 9 ; $CBN_SELENDCANCEL = 10
            ConsoleWrite( "$CBN_SELENDCANCEL notificaton from " & ( GUICtrlRead( $aMsg[0] ) = $hCombo1 ? "Combo1" : "Combo2" ) & @CRLF )

          Case $GUI_EVENT_CLOSE
            ExitLoop
        EndSwitch
    EndSwitch
  WEnd

  ; Cleanup
  _WinAPI_RemoveWindowSubclass( $hChild1, $pComboBoxCallback, 1 )
  _WinAPI_RemoveWindowSubclass( $hChild2, $pComboBoxCallback, 2 )
  GUIDelete()
EndFunc

; Callback function
Func ComboBoxCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $hCombo )
  If $iMsg <> $WM_COMMAND Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]

  Local $iCode = BitShift( $wParam, 16 )
  Switch $iCode
    Case $CBN_SELCHANGE To $CBN_SELENDCANCEL
      GUICtrlSendToDummy( $idCBN_FIRST + $iCode - $CBN_SELCHANGE, $hCombo )
      Return 1 ; Prevents the notifications from being forwarded to other message handlers.
  EndSwitch    ; This includes a user defined GUIRegisterMsg WM_COMMAND message handler.

  ; Call next function in subclass chain (this forwards messages to main GUI)
  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
  #forceref $iSubclassId
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

@LarsJ Thanks for the reply. It seems very helpful to understand a beginner like me. Every block of code is well commented.  Thanks for this great help. I am amused when i see the "_WinAPI_SetWindowSubclass" in this script. Because, i never see such a function in the help file before. May be my negligence. Oh yes, it was in the group of ShellEx Management, that's why i missed it. After reading the help file, my interest in autoit increased. Now i  am reading a book named "Subclassing and Hooking in vb & vb.net". When reading it, i wish to try all the tricks in autoit too. I have wrote some code for it, but didn't complete that program due to the rush. Now, its time to learn something new from your script. I know this script is a treasure for me now. Once i read this, i will sure ask my doubts (if any). I hope you will guide me. Thanks again. :) 

1 person likes this

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

  • Similar Content

    • jimollerhead
      By jimollerhead
      Hello Folks,

      I'm not an AutoIt noob but I am new to the GuiRegisterMsg command.

      What I am trying to do is to pop up a "long string edit" window when user double-clicks. Ideally I wanted it to be a duouble-click in the Input box itself but I couldn't get this to work so I was going to settle for a double-click *near* the input box.

      Here's a severely curtailed version of my almost 1300-line script. From the msgbox "tell-tale" it appears that the GuiRegisterMsg definition interferes with the GuiGetMsg function and it 'remembers' the last GuiGetMsg return value -- is there some way to 'flush' the holding area? Note that there are bits in there from experiments -- if I comment out the While-Wend and replace it with the sleep line you can better see what I am trying to acheive. The list box is just to give a different kind of control than an input field to have the focus, it's contents are not relevant to the snippet, only to the full app.

      All help gratefully acknowledged! Here's the code snippet:


      #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <ListBoxConstants.au3> Dim $InputFileId Dim $OutputFileId Dim $winMain Dim $GUIMsg GUIRegisterMsg($WM_LBUTTONDBLCLK, "EditText") $winMain = GUICreate ("Test for Editing Long Strings", 800, 560, -1, -1) GUICtrlCreateLabel("File to Process", 22,30) GUICtrlCreateLabel("Output File", 40,60) $InputFileId = GUICtrlCreateInput ( "", 100, 25, 400, 20) $OutputFileId = GUICtrlCreateInput ( "", 100, 55, 400, 20) $btnInputFile = GUICtrlCreateButton ( "Browse for File", 520, 22, 110, 25) $btnOPFolder = GUICtrlCreateButton ( "Browse for Location", 520, 53, 110, 25) ; Create the list of actions $ActionList = GUICtrlCreateList( "", 25, 260, 70, 200) GUICtrlSetData($ActionList, "Delete|Exclude|Include|Insert|Kill Blanks|Move|Remove|Replace|Switch", "Delete") GUISetState(@SW_SHOW, $winMain) While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case $GUI_EVENT_CLOSE ExitLoop Case $btnInputFile MsgBox(0, "Info", "Input Button pressed") Case $btnOPFolder MsgBox(0, "Info", "Output Button pressed") EndSwitch WEnd Func EditText($Window, $Caller, $p1, $p2) Dim $winEdit Dim $CtrlName Dim $edtString Dim $btnAccept Dim $btnReject Dim $Response Dim $RetString Dim $CtrlId Dim $ActCode Dim $HasFocus $CtrlName = ControlGetFocus("Test for Editing Long Strings") msgbox(0,"DOUBLE-CLICK!","Control: " & $CtrlId & @CRLF & "Action: " & $ActCode & @CRLF & "CtrlName: " & $CtrlName) If StringInStr($CtrlName,"Edit") > 0 Then $winEdit = GUICreate("Long String Editor", 790, 100, -1, -1, $WS_BORDER) $edtString = GUICtrlCreateEdit("This is a potentially long string", 5, 5, 780, 20, $ES_AUTOHSCROLL) $btnAccept = GUICtrlCreateButton( "Accept String", 240, 33, 100, 30) $btnReject = GUICtrlCreateButton( "Reject String", 440, 33, 100, 30) GUISetState(@SW_SHOW, $winEdit) GUICtrlSetState($edtString, $GUI_FOCUS) ; sleep(5000) ;#cs While 1 $Response = GUIGetMsg() if $Response = $btnAccept Then ExitLoop EndIf Select Case $Response = $btnReject ExitLoop Case $Response = $btnAccept ; GUICtrlSetData($CtrlName, $RetString) ExitLoop Case Else $RetString = GUICtrlRead($edtString) EndSelect WEnd ;#ce Else Return $GUI_RUNDEFMSG EndIf GUICtrlSetData($CtrlName, $RetString) GUIDelete($winEdit) Return $GUI_RUNDEFMSG EndFunc
    • DickWms
      By DickWms
      I'm trying to catch non printing characters (like Delete, F5, Shifte F5, etc) when a user is typing into an Input Control. The sample code below doesn't work (the Input MsgBox only appears when the enter key is pressed and the Key Pressed MsgBox never appears). It appears to me this is because the Input Control doesn't send a GUI message every time a key stroke is received.

      So my question is how can I capture individual key presses, including non printing ones, to an Input Control? Or should I be using a different control?

      Thank you - Dick williams




      #include #include $window = GUICreate("Test", 200, 100) $inputBox = GUICtrlCreateInput ( "Input Box", 50, 50 , 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $inputBox MsgBox(0, "Input Box", "Case Executed") If _IsPressed(75) Then MsgBox(0, "Key Pressed", "F5") EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd
    • Artisan
      By Artisan
      I've been working on a fancy ListView for user input. When a cell is clicked, a temporary Combo or Input control is created. The user does their part, then the temporary control's data is transferred to the ListView and the temporary control is deleted. I'm quite pleased with how it's turned out, except for one puzzling "feature".

      If I use "Switch GUIGetMsg()" in the main loop, then the first time a user clicks on the form causes a temp control to be both created and processed. That only occurs on the first click and not on any subsequent clicks. If I use "$msg = GUIGetMsg(1)" with a Switch command, it works properly on every click. See code below. I have no idea why this is. Does anyone else? I'll use GUIGetMsg(1) if I must, but I prefer my code to be as simple as possible.


      #include #include #include #include #include Global Const $_INCL = 1, $_REGEX = 2, $_FILTER = 3 Global $h_TempCtrl, $TempCtrlStatus[3] = [False, -1, -1], $_ListViewY = 1 Switch @OSVersion Case "WIN_2000", "WIN_XP", "WIN_XPe", "WIN_2003" $_ListViewY = 0 EndSwitch $h_GUI = GUICreate("Form1", 594, 329) $h_ListView = GUICtrlCreateListView("#|Include or Not|Filter Type|Contents ", 24, 24, 545, 279, $LVS_SINGLESEL) $hG_LVitem1 = GUICtrlCreateListViewItem("1.|Include|StringRegExp|", $h_ListView) $hG_LVitem2 = GUICtrlCreateListViewItem("2.|Include|StringRegExp|", $h_ListView) $hG_LVitem3 = GUICtrlCreateListViewItem("3.|Include|StringRegExp|", $h_ListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() ;~ $msg = GUIGetMsg(1) ;~ Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $h_TempCtrl If $h_TempCtrl <> 0 Then _GUICtrlTemp_Apply("$h_TempCtrl") EndIf EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Catch ListView messages Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") If $hWndFrom == GUICtrlGetHandle($h_ListView) And $iCode == $NM_CLICK Then _GUICtrlTemp_Create() Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg ; Catch user input Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) If $TempCtrlStatus[0] Then If $hWndFrom == GUICtrlGetHandle($h_TempCtrl) Then Switch $iCode Case $CBN_SELENDOK _GUICtrlTemp_Apply("$CBN_SELENDOK") Case $CBN_SELENDCANCEL _GUICtrlTemp_Delete("$CBN_SELENDCANCEL") Case $EN_KILLFOCUS _GUICtrlTemp_Apply("$EN_KILLFOCUS") EndSwitch EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlTemp_Create() ; Create a temporary control for user input Local $tempPos, $HitTest $HitTest = _GUICtrlListView_SubItemHitTest(GUICtrlGetHandle($h_ListView)) If $HitTest[0] <> -1 Then $TempCtrlStatus[0] = True $TempCtrlStatus[1] = $HitTest[0] $TempCtrlStatus[2] = $HitTest[1] Switch $HitTest[1] ; Global Const $_INCL = 1, $_REGEX = 2, $_FILTER = 3, $_FREQ = 4 Case $_INCL $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_INCL) $h_TempCtrl = GUICtrlCreateCombo("", $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1], $CBS_DROPDOWNLIST) GUICtrlSetData($h_TempCtrl, "Include|Don't Include") GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP)) _GUICtrlComboBox_ShowDropDown($h_TempCtrl, True) Case $_REGEX $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_REGEX) $h_TempCtrl = GUICtrlCreateCombo("", $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1], $CBS_DROPDOWNLIST) GUICtrlSetData($h_TempCtrl, "String|StringRegExp") GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP)) _GUICtrlComboBox_ShowDropDown($h_TempCtrl, True) Case $_FILTER $tempPos = _GUICtrlListView_GetSubItemRect($h_ListView, $HitTest[0], $_FILTER) Local $hRegion = _WinAPI_CreateRectRgn($tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2], $tempPos[3]) $h_TempCtrl = GUICtrlCreateInput(_GUICtrlListView_GetItemText($h_ListView, $HitTest[0], 3), $tempPos[0] + 24, $tempPos[1] + 24 + $_ListViewY, $tempPos[2] - $tempPos[0], $tempPos[3] - $tempPos[1]) GUICtrlSetState($h_TempCtrl, BitOR($GUI_FOCUS, $GUI_ONTOP, $GUI_SHOW)) _GUICtrlEdit_SetSel($h_TempCtrl, 0, -1) _WinAPI_RedrawWindow($h_GUI, 0, $hRegion, $RDW_UPDATENOW) ; It won't draw the control until mouse-out *** (WHY??) EndSwitch EndIf EndFunc Func _GUICtrlTemp_Apply( $caller ) ; Apply the temporary control's text to the ListView If $TempCtrlStatus[0] Then $TempCtrlStatus[0] = False _GUICtrlListView_SetItemText($h_ListView, $TempCtrlStatus[1], GUICtrlRead($h_TempCtrl), $TempCtrlStatus[2]) $TempCtrlStatus[1] = -1 $TempCtrlStatus[2] = -1 _GUICtrlTemp_Delete($caller & " -> Apply") EndIf EndFunc Func _GUICtrlTemp_Delete( $caller ) ConsoleWrite("Delete called by: " & $caller & @LF & "$h_TempCtrl: " & $h_TempCtrl & @LF & @SEC & ':' & @MSEC & @LF & @LF) ; Get rid of the temporary control GUICtrlDelete($h_TempCtrl) EndFunc
    • LordBoling
      By LordBoling
      Hello everyone! Hope you are having great days.
      I unfortunately am in need of assistance.

      I am in the process of creating a program that will allow me to search 2 systems that my company uses that store customer info.
      At this time if a customer places an order it could be in our online only system, our in-store system, or both at the same time. So instead of searching one manually, then the other, I decided to code a script that would look in both at the same time until it find the order. It has a few issues though.

      Issue #1 (Solved, Thank you BrewManNH!): I have two GUIs that I created, but apparently created wrong as the first one never closes until the script ends completely or if they press the red X, but is supposed to close when the user presses okay, but not end the script. This GUI is called in my code by a function called RefGui().
      Issue #2 (Solved): This same GUI is supposed to return a reference id entered by the user in an input field and what type of reference number it is by selecting a radio button. However, when used like it was intended it only returns the data from the input field. If nothing is put in the input field then it will return both the data in the input field and which radio selection is made.

      I have other issues but will probably deal with them once I have those figured out. If someone could take a look at my code and give me some ideas I would appreciate it.


      #include "CSV.au3" #include "Array.au3" #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> Opt("WinWaitDelay",100) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) Opt("SendCapslockMode",1) $objErr = ObjEvent("AutoIt.Error","MyErrFunc") ;Open Connection to OsCommerce database $oConn = ObjCreate("ADODB.Connection") $oConn.Open(;Connection string to my first database) ;Open Connection to Mas90 database $conn = ObjCreate("ADODB.Connection") $DSN = ;Connection string for my second database $conn.Open($DSN) ;Define var for reference type as global w/ initial value/Moved per BrewManNH's suggestion Global $refType="Internet" ;Loop until user closes first GUI w/ close button While 1 ;~ ;Define var for reference type as global w/ initial value ;~ Global $refType="Internet" ;Ask for order number or invoice number: (This opens first gui) $refNum=RefGui() ;Start text var to display message. $OrderMsg=$refNum & @CRLF & $refType ;If user selected internet search OsCommerce. Otherwise this won't be necessarily. If $refType="Internet" Then ;Query status and comments $rs = $oConn.Execute("SELECT orders.orders_status,orders_status_history.comments FROM orders,orders_status_history WHERE orders.orders_id='"& $refNum &"' AND orders_status_history.orders_status_id=orders.orders_status AND orders_status_history.orders_id=orders.orders_id") ;Make sure a result was returned then get results If IsObj($rs) And $rs.EOF=False Then $osStatus = $rs.GetRows() $rs = $oConn.Execute("SELECT orders_status_name FROM orders_status WHERE orders_status_id ='"& $osStatus[UBound($osStatus)-1][0] &"'") $temp=$rs.GetRows() $osStatus[UBound($osStatus)-1][0]=$temp[0][0] $OrderMsg+="OsCommerce:" & @CRLF $OrderMsg+=@TAB & "Status:" & $osStatus[UBound($osStatus)-1][0] & @CRLF $OrderMsg+=@TAB & "Comments:" & $osStatus[UBound($osStatus)-1][1] & @CRLF Else $osStatus = 0 EndIf EndIf ;If internet or sales were chosen then check if it has been put in Mas90 yet. If $refType="Internet" Or $refType="Sales" Then $rs = $conn.Execute("SELECT OrderType FROM SO_SalesOrderHeader WHERE (SalesOrderNo='"& $refNum &"')") If IsObj($rs) And $rs.EOF=False Then $SOStatus = $rs.GetRows() $OrderMsg+="Sales Order:" & @CRLF $OrderMsg+=@TAB & "Status:" & $SOStatus[0][0] & @CRLF $rs = $conn.Execute("SELECT ItemCode,ItemCodeDesc,QuantityOrdered,QuantityBackordered FROM SO_SalesOrderDetail WHERE (SalesOrderNo='"& $refNum &"' AND ItemType='1')") If IsObj($rs) And $rs.EOF=False Then $SOItems = $rs.GetRows() $OrderMsg+=@TAB & "Items:" & @CRLF $i=0 While $i<UBound($SOItems)-1 $OrderMsg+=@TAB & @TAB & "(" & $SOItems[$i][0] & ") " & $SOItems[$i][1] & @CRLF $rs = $conn.Execute("SELECT TotalQuantityOnHand FROM CI_Item WHERE (ItemCode='"& $SOItems[$i][0] &"')") If IsObj($rs) And $rs.EOF=False Then $item = $rs.GetRows() $OrderMsg+=@TAB & @TAB & "Ordered/Available: " & $SOItems[$i][2] & "/" & $item[0][0] & @TAB & "Backordered: " & $SOItems[$i][3] & @CRLF EndIf $i+=1 WEnd Else $SOItems = 0 EndIf Else $SOStatus = 0 EndIf $rs = $conn.Execute("SELECT InvoiceNo, SalesOrderNo FROM SO_InvoiceHeader WHERE (SalesOrderNo='"& $refNum &"')") If IsObj($rs) And $rs.EOF=False Then $InvStatus = $rs.GetRows() $rs = $conn.Execute("SELECT InvoiceNo,ItemCode,ItemCodeDesc,QuantityOrdered,QuantityBackordered FROM SO_InvoiceDetail WHERE (InvoiceNo='"& $InvStatus[0][0] &"' AND ItemType=1)") If IsObj($rs) And $rs.EOF=False Then $InvItems = $rs.GetRows() Else $InvItems = 0 EndIf Else $InvStatus = 0 EndIf $rs = $conn.Execute("SELECT InvoiceNo, SalesOrderNo FROM AR_InvoiceHistoryHeader WHERE (SalesOrderNo='"& $refNum &"')") If IsObj($rs) And $rs.EOF=False Then $InvHst = $rs.GetRows() $rs = $conn.Execute("SELECT InvoiceNo,ItemCode,ItemCodeDesc,QuantityOrdered,QuantityBackordered FROM AR_InvoiceHistoryDetail WHERE (InvoiceNo='"& $InvHst[0][0] &"' AND ItemType=1)") If IsObj($rs) And $rs.EOF=False Then $InvItems = $rs.GetRows() Else $InvItems = 0 EndIf Else $InvHst = 0 EndIf ElseIf $refType="Invoice" Then $rs = $conn.Execute("SELECT InvoiceNo, SalesOrderNo FROM AR_InvoiceHistoryHeader WHERE (InvoiceNo='"& $refNum &"')") If IsObj($rs) And $rs.EOF=False Then $InvHst = $rs.GetRows() $rs = $conn.Execute("SELECT InvoiceNo,ItemCode,ItemCodeDesc,QuantityOrdered,QuantityBackordered FROM AR_InvoiceHistoryDetail WHERE (InvoiceNo='"& $refNum &"' AND ItemType=1)") If IsObj($rs) And $rs.EOF=False Then $InvItems = $rs.GetRows() Else $InvItems = 0 EndIf Else $InvHst = 0 EndIf EndIf Gui($OrderMsg) WEnd ;This is the second GUI that displays the results Func Gui($txt) Local $myedit, $msg $hGUI=GUICreate("Details:", 500, 300, Default, Default,$WS_OVERLAPPEDWINDOW) ; will create a dialog box that when displayed is centered $GUISize=WinGetClientSize($hGUI) $myedit = GUICtrlCreateEdit($txt,-1, -1, $GUISize[0], $GUISize[1],$ES_READONLY) GUICtrlSetResizing ( $myedit, $GUI_DOCKBORDERS ) GUISetState() DllCall("user32.dll","int","HideCaret","int",0) Send("{END}") ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete($hGUI) EndFunc ;This is the first GUI. It asks for the information required to look up the order Func RefGui() $RefGui = GUICreate("Reference#", 261, 156, -1, -1) GUISetFont(10, 400, 0, "Verdana") GUICtrlCreateLabel("Enter Reference:", 15, 12, 116, 20) $RefNum = GUICtrlCreateInput("REFERENCE #", 136, 8, 110, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE)) $OK = GUICtrlCreateButton("OK", 176, 120, 75, 25, BitOR($BS_DEFPUSHBUTTON,$BS_NOTIFY)) GUICtrlCreateGroup("Select Ref Type:", 16, 40, 145, 105, BitOR($GUI_SS_DEFAULT_GROUP,$WS_CLIPSIBLINGS)) $Internet = GUICtrlCreateRadio("Internet Order", 24, 64, 113, 17) GUICtrlSetState(-1, $GUI_CHECKED) $Sales = GUICtrlCreateRadio("Sales Order", 24, 88, 113, 17) $Invoice = GUICtrlCreateRadio("Invoice", 24, 112, 113, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit If $nMsg = $OK Then ExitLoop EndIf WEnd If GUICtrlRead($Internet) = 1 Then $refType="Internet" ElseIf GUICtrlRead($Sales) = 1 Then $refType="Sales" ElseIf GUICtrlRead($Invoice) = 1 Then $refType="Invoice" EndIf $temp=GUICtrlRead($RefNum) GUIDelete($RefGui) Return $temp EndFunc Func MyErrFunc() $hexnum=hex($objErr.number,8) Msgbox(0,"","We intercepted a COM Error!!" & @CRLF & @CRLF & _ "err.description is: " & $objErr.description & @CRLF & _ "err.windescription is: " & $objErr.windescription & @CRLF & _ "err.lastdllerror is: " & $objErr.lastdllerror & @CRLF & _ "err.scriptline is: " & $objErr.scriptline & @CRLF & _ "err.number is: " & $hexnum & @CRLF & _ "err.source is: " & $objErr.source & @CRLF & _ "err.helpfile is: " & $objErr.helpfile & @CRLF & _ "err.helpcontext is: " & $objErr.helpcontext _ ) exit EndFunc
      Here is just the code for the first GUI so you don't have to look through all that:

      Func RefGui() $RefGui = GUICreate("Reference#", 261, 156, -1, -1) GUISetFont(10, 400, 0, "Verdana") GUICtrlCreateLabel("Enter Reference:", 15, 12, 116, 20) $RefNum = GUICtrlCreateInput("REFERENCE #", 136, 8, 110, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_UPPERCASE)) $OK = GUICtrlCreateButton("OK", 176, 120, 75, 25, BitOR($BS_DEFPUSHBUTTON,$BS_NOTIFY)) GUICtrlCreateGroup("Select Ref Type:", 16, 40, 145, 105, BitOR($GUI_SS_DEFAULT_GROUP,$WS_CLIPSIBLINGS)) $Internet = GUICtrlCreateRadio("Internet Order", 24, 64, 113, 17) GUICtrlSetState(-1, $GUI_CHECKED) $Sales = GUICtrlCreateRadio("Sales Order", 24, 88, 113, 17) $Invoice = GUICtrlCreateRadio("Invoice", 24, 112, 113, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit If $nMsg = $OK Then ExitLoop EndIf WEnd If GUICtrlRead($Internet) = 1 Then $refType="Internet" ElseIf GUICtrlRead($Sales) = 1 Then $refType="Sales" ElseIf GUICtrlRead($Invoice) = 1 Then $refType="Invoice" EndIf $temp=GUICtrlRead($RefNum) GUIDelete($RefGui) Return $temp EndFunc