kcvinu Posted February 25, 2016 Posted February 25, 2016 (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 February 25, 2016 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
mikell Posted February 25, 2016 Posted February 25, 2016 You need GuiRegisterMsg expandcollapse popup#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
kcvinu Posted February 25, 2016 Author Posted February 25, 2016 @mikell , So GuiGetMsg is for a few limited messages. May i know what is the reason behind it ? Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
Moderators Melba23 Posted February 25, 2016 Moderators Posted February 25, 2016 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 kcvinu 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kcvinu Posted February 25, 2016 Author Posted February 25, 2016 @Melba23 , Thanks for your clarification. But it is an extra power for a programmer to use such messages with easiness. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
Moderators Melba23 Posted February 25, 2016 Moderators Posted February 25, 2016 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 kcvinu 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kcvinu Posted February 25, 2016 Author Posted February 25, 2016 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. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
mikell Posted February 25, 2016 Posted February 25, 2016 (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 February 25, 2016 by mikell kcvinu 1
JohnOne Posted February 25, 2016 Posted February 25, 2016 lol forgot about getcursorinfo and just wrote this mess... expandcollapse popupOpt("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 kcvinu 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
mikell Posted February 25, 2016 Posted February 25, 2016 #include <MsgBoxConstants.au3> Global Const $JOHN_ONE = "JohnOne" Global Const $CRAP = "Magic Numbers" Msgbox($MB_ICONWARNING, $JOHN_ONE, "Really, you used too much " & $CRAP) JohnOne and kcvinu 2
JohnOne Posted February 25, 2016 Posted February 25, 2016 (edited) Don't see the point of adding a thousand constants to a silly little example where I need only 2. Edited February 25, 2016 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
mikell Posted February 25, 2016 Posted February 25, 2016 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
kcvinu Posted February 25, 2016 Author Posted February 25, 2016 (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 February 26, 2016 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
kcvinu Posted February 25, 2016 Author Posted February 25, 2016 @mikell Really, that's a nice workaround for my problem. Thanks a lot. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
JohnOne Posted February 25, 2016 Posted February 25, 2016 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.
mikell Posted February 25, 2016 Posted February 25, 2016 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 ...
JohnOne Posted February 25, 2016 Posted February 25, 2016 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.
kcvinu Posted February 26, 2016 Author Posted February 26, 2016 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. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
LarsJ Posted February 26, 2016 Posted February 26, 2016 expandcollapse popup#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 kcvinu 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
kcvinu Posted February 26, 2016 Author Posted February 26, 2016 @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. LarsJ 1 Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now