jcpetu Posted April 26, 2013 Share Posted April 26, 2013 Hello forum, I´m trying to trap messages from diferent controls to add functionality. I managed to get messages from buttons but I´m confused respect how to trap other controls. Here is the code in case anyone could help me. Thanks in advance. expandcollapse popup#include #include #include #include #include #include Opt("GUIOnEventMode", 1) Global $Form1, $Label1, $Input1, $Label2, $Input2, $Label3, $Input3, $Edit1, $Button1, $Button2, $Checkbox1, $Radio1 Global $Gui = GUICreate("Basic GUI", 615, 362, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Salir") $Label1 = GUICtrlCreateLabel("Label1", 24, 48, 36, 17) $Input1 = GUICtrlCreateInput("Input1", 80, 48, 161, 21) $Label2 = GUICtrlCreateLabel("Label2", 24, 96, 36, 17) $Input2 = GUICtrlCreateInput("Input2", 80, 88, 161, 21) $Label3 = GUICtrlCreateLabel("Label3", 24, 136, 36, 17) $Input3 = GUICtrlCreateInput("Input3", 80, 128, 161, 21) $Edit1 = GUICtrlCreateEdit("", 304, 48, 265, 113) GUICtrlSetData(-1, "Edit1") $Button1 = GUICtrlCreateButton("Button1", 32, 184, 121, 33) $Button2 = GUICtrlCreateButton("Button2", 192, 184, 121, 41) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 352, 184, 97, 25) $Radio1 = GUICtrlCreateRadio("Radio1", 488, 184, 73, 33) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While Sleep(100) WEnd Func Salir() GUIDelete() Exit EndFunc ;==>Salir Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local Const $BCN_HOTITEMCHANGE = -1249 Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam) Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code"), _ $nID = DllStructGetData($tNMBHOTITEM, "IDFrom"), _ $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom"), _ $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags"), _ $sText = "" Switch $nNotifyCode Case $BCN_HOTITEMCHANGE ; message sent by a button Switch $nID Case $Button1 ConsoleWrite("Message from button 1" & _GUICtrlButton_GetText($hCtrl) & @CRLF) Case $Button2 ConsoleWrite("Message from button 1" & _GUICtrlButton_GetText($hCtrl) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
AZJIO Posted April 26, 2013 Share Posted April 26, 2013 (edited) In a file-help function _GUICtrlButton_Create not tried? In the help file did not try to function _GUICtrlButton_Create? http://azjio.narod2.ru/autoit3_docs/userfunctions/WM_NOTIFY.htm Edited April 26, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
jcpetu Posted April 27, 2013 Author Share Posted April 27, 2013 Hello AZJIO, yes I create my code from the example you mentioned, and I can trab button messages. But I want to trap messages for all other controls. Link to comment Share on other sites More sharing options...
PhoenixXL Posted April 27, 2013 Share Posted April 27, 2013 For Hovering Events check GUIGetCursorInfoExampleexpandcollapse popup#include <StructureConstants.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $Form1, $Label1, $Input1, $Label2, $Input2, $Label3, $Input3, $Edit1, $Button1, $Button2, $Checkbox1, $Radio1 Global $Gui = GUICreate("Basic GUI", 615, 362, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Salir") Opt("GUIOnEventMode", 1) ;The return of any native control is the ControlID ;That is if $Label1 is X then $Label2 is X+1 $Label1 = GUICtrlCreateLabel("Label1", 24, 48, 36, 17) $Label2 = GUICtrlCreateLabel("Label2", 24, 96, 36, 17) $Label3 = GUICtrlCreateLabel("Label3", 24, 136, 36, 17) $Input1 = GUICtrlCreateInput("Input1", 80, 48, 161, 21) $Input2 = GUICtrlCreateInput("Input2", 80, 88, 161, 21) $Input3 = GUICtrlCreateInput("Input3", 80, 128, 161, 21) $Edit1 = GUICtrlCreateEdit("", 304, 48, 265, 113) GUICtrlSetData(-1, "Edit1") $Button1 = GUICtrlCreateButton("Button1", 32, 184, 121, 33) $Button2 = GUICtrlCreateButton("Button2", 192, 184, 121, 41) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 352, 184, 97, 25) $Radio1 = GUICtrlCreateRadio("Radio1", 488, 184, 73, 33) GUISetState(@SW_SHOW) Local $prev_Ctl_hovered While 1 $nMsg = GUIGetCursorInfo() If @error Then ContinueLoop If $nMsg[4] <> $prev_Ctl_hovered Then Switch $nMsg[4] Case $Label1 To $Label3 ConsoleWrite("Hovering on Label" & $nMsg[4] - $Label1 + 1 & @CRLF) Case $Input1 To $Input3 ConsoleWrite("Hovering on Label" & $nMsg[4] - $Input1 + 1 & @CRLF) Case $Edit1 ConsoleWrite("Hovering on Edit1" & @CRLF) Case $Button1, $Button2 ConsoleWrite("Hovering on Button" & $nMsg[4] - $Button1 + 1 & @CRLF) Case $Checkbox1 ConsoleWrite("Hovering on Checkbox" & @CRLF) Case $Radio1 ConsoleWrite("Hovering on Radio" & @CRLF) EndSwitch $prev_Ctl_hovered = $nMsg[4] EndIf WEnd Func Salir() GUIDelete() Exit EndFunc ;==>SalirFor Checking clicked messages see GUICtrlSetOnEvent (orelse GUIGetMsg when not using Opt("GUIOnEventMode", 1))Regards My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
jcpetu Posted April 27, 2013 Author Share Posted April 27, 2013 Hi PhoenixXL, I just want to avoid checking into the While loop, thats the reason to trap the windows message which I think is much efficient.I know I have to trap the control ID who sent the message, I also tried with the following but I didn´t get to find the correct code so far.expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $Label1, $Input1, $Label2, $Input2, $Label3, $Input3, $Edit1, $Button1, $Button2, $Checkbox1, $Radio1 Global $Gui = GUICreate("", 615, 362, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") $Label1 = GUICtrlCreateLabel("Label1", 24, 48, 36, 17) $Input1 = GUICtrlCreateInput("Input1", 80, 48, 161, 21) $Label2 = GUICtrlCreateLabel("Label2", 24, 96, 36, 17) $Input2 = GUICtrlCreateInput("Input2", 80, 88, 161, 21) $Label3 = GUICtrlCreateLabel("Label3", 24, 136, 36, 17) $Input3 = GUICtrlCreateInput("Input3", 80, 128, 161, 21) $Edit1 = GUICtrlCreateEdit("", 304, 48, 265, 113) GUICtrlSetData(-1, "Edit1") $Button1 = GUICtrlCreateButton("Button1", 32, 184, 121, 33) $Button2 = GUICtrlCreateButton("Button2", 192, 184, 121, 41) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 352, 184, 97, 25) $Radio1 = GUICtrlCreateRadio("Radio1", 488, 184, 73, 33) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While Sleep(100) WEnd Func Close() GUIDelete() Exit EndFunc ;==>Close Func WM_NOTIFY($hWnd, $iMsg, $wParam, $ilParam) ;Notify func Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $NTF = GUICtrlGetHandle($Label1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") If $iCode = -12 Or $iCode = -17 Then Return False Switch $iCode Case $NTF ConsoleWrite("$NTFYLabel1" & @CRLF) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYThanks for the example and regards. Link to comment Share on other sites More sharing options...
AZJIO Posted April 27, 2013 Share Posted April 27, 2013 My other projects or all Link to comment Share on other sites More sharing options...
PhoenixXL Posted April 27, 2013 Share Posted April 27, 2013 (edited) With WM_NOTIFY your code will simply increase. Check this I don't think its inefficient in any way with comparison.expandcollapse popup#include <StructureConstants.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $Form1, $Label1, $Input1, $Label2, $Input2, $Label3, $Input3, $Edit1, $Button1, $Button2, $Checkbox1, $Radio1 Global $Gui = GUICreate("Basic GUI", 615, 362, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Salir") Opt("GUIOnEventMode", 1) ;The return of any native control is the ControlID ;That is if $Label1 is X then $Label2 is X+1 $Label1 = GUICtrlCreateLabel("Label1", 24, 48, 36, 17) $Label2 = GUICtrlCreateLabel("Label2", 24, 96, 36, 17) $Label3 = GUICtrlCreateLabel("Label3", 24, 136, 36, 17) $Input1 = GUICtrlCreateInput("Input1", 80, 48, 161, 21) $Input2 = GUICtrlCreateInput("Input2", 80, 88, 161, 21) $Input3 = GUICtrlCreateInput("Input3", 80, 128, 161, 21) $Edit1 = GUICtrlCreateEdit("", 304, 48, 265, 113) GUICtrlSetData(-1, "Edit1") $Button1 = GUICtrlCreateButton("Button1", 32, 184, 121, 33) $Button2 = GUICtrlCreateButton("Button2", 192, 184, 121, 41) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 352, 184, 97, 25) $Radio1 = GUICtrlCreateRadio("Radio1", 488, 184, 73, 33) For $i = $Label1 To $Radio1 GUICtrlSetOnEvent($i, "Clicked_Item") ;Register Click Event Next AdlibRegister("Hovered_Item", 10) GUISetState(@SW_SHOW) While Sleep(10) WEnd Func Salir() GUIDelete() Exit EndFunc ;==>Salir Func Clicked_Item() $iControlID = @GUI_CtrlId ConsoleWrite(GUICtrlRead($iControlID, 1) & " Clicked" & @CRLF) EndFunc Func Hovered_Item() Static $prev_Ctl = 0 $aMsg = GUIGetCursorInfo() If @error Or $aMsg[4] = 0 Or $aMsg[4] = $prev_Ctl Then Return ConsoleWrite(GUICtrlRead($aMsg[4], 1) & " Hovered" & @CRLF) $prev_Ctl = $aMsg[4] EndFuncThumbs up if helped Regards Edited April 27, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 27, 2013 Moderators Share Posted April 27, 2013 I just want to avoid checking into the While loop, thats the reason to trap the windows message which I think is much efficientIt is most definitely not. The AutoIt authors have gone to a lot of trouble to give you 2 easy-to-use modes (MessageLoop & OnEvent) to trap the messages for native-created controls. Anything you code will be very much less efficient as it will use an AutoIt-coded handler to do what is being done for you internally in C++ code. UDF-created controls need message handlers because they are not dealt with internally by AutoIt - which is why I would always recommend using them only if you find that you need their increased functionality and as a result the necessary extra coding is worth the effort. M23 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 Link to comment Share on other sites More sharing options...
BrewManNH Posted April 27, 2013 Share Posted April 27, 2013 Just an FYI, I dpon't think WM_NOTIFY is the message you would need to look for with buttons and labels anyways, you're probably wanting to look for WM_COMMAND messages. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jcpetu Posted April 28, 2013 Author Share Posted April 28, 2013 Thanks to all for the answers. Autoit is a wonderfull language and I truly apreciate the effort the authors have done. All the answers you gave me got the point but I am curious and want to understand. one thing I learned, there are many ways to do the same. THANKS A LOT and regrads. Link to comment Share on other sites More sharing options...
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