Rkey Posted September 8, 2017 Share Posted September 8, 2017 Hi Forum, I'm having trouble accomplishing the following: I'd like to click a label on the GUI just after showing the GUI itself (to eventually fire the event bind to the label) Here is simple version of the code (see the line under "Trying to click the 1st link") expandcollapse popup#include <GuiConstants.au3> #include <GuiConstantsEx.au3> #include <SendMessage.au3> #include <AutoItConstants.au3> #Region GLOBAL VARIABLES Global $iGuiW = 400, $iGuiH = 400 ; GUI Size, Width and Height Global $iGuiTopH = 52, $iGuiBotH = 52 ; GUI Size, Top Height, Bottom Height Global $iLeftWidth = 250 ; GUI Size, Left Menu Width Global $iGap = 10 ; GUI Size, Space between links (vertical) Global $iRightWidth = 100 Global $hMainGUI #EndRegion GLOBAL VARIABLES #Region OPTIONS Opt('MustDeclareVars', 1) ; Variables must be pre-declared - removes the chance for misspelled variables causing bugs Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #EndRegion OPTIONS _MainGui() Func _MainGui() ; Vars Local $hFooter, $nMsg, $aPos Local $iLinks = 5 ; Number of links (minus 1) Local $sMainGuiTitle = "Main" ; Title Local $sHeader = " Main - " & @ScriptName & " - " & @ComputerName ; Header Local $sFooter = "2017©" ; Footer GLobal $aLink[$iLinks], $aPanel[$iLinks], $aIdTreeviewFile[$iLinks] ; Links and Panels $aLink[0] = $iLinks - 1 $aPanel[0] = $iLinks - 1 ; Shortcut to close to escape possible loop HotKeySet("{F1}", "OnF1") ; Create GUI $hMainGUI = GUICreate($sMainGuiTitle, $iGuiW, $iGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP)) ;Adding Links and bind event For $i = 1 To $aLink[0] $aLink[$i] = _AddNewLink('Link ' & $i) GUICtrlSetOnEvent($aLink[$i], "_ShowMessage") Next ;show the main GUI GUISetState(@SW_SHOW, $hMainGUI) ;Trying to click the 1st link local $hwnd = GUICtrlGetHandle ($aLink[1]) _DebugPrint($hwnd & ' search for handle') local $return = _SendMessage($hwnd, $BM_CLICK) _DebugPrint($return & ' return from sendmessage') While 1 Sleep(100) ; Sleep to reduce CPU usage WEnd EndFunc ;==>_MainGui Func _ShowMessage() MsgBox(1, '', GUICtrlRead(@GUI_CtrlId)) EndFunc Func _AddNewLink($sTxt, $iIcon = -44) Local $hLink = GUICtrlCreateLabel($sTxt, 36, $iGuiTopH + $iGap, $iLeftWidth - 46, 17) GUICtrlSetCursor(-1, 0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) GUICtrlCreateIcon("shell32.dll", $iIcon, 10, $iGuiTopH + $iGap, 16, 16) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $iGap += 22 Return $hLink EndFunc ;==>_AddNewLink Func _AddControlsToPanel($hPanel) GUISwitch($hPanel) EndFunc ;==>_AddControlsToPanel ; to create escape function in case X is blocked. Func OnF1() Exit EndFunc ;==>OnF1 Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( "DebugPrint -->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF) EndFunc ;==>_DebugPrint Thanks in advance! Rick Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 8, 2017 Moderators Share Posted September 8, 2017 Rkey, Just use ControlClick: ;Trying to click the 1st link ControlClick($hMainGUI, "", $aLink[1]) ;local $hwnd = GUICtrlGetHandle ($aLink[1]) ;_DebugPrint($hwnd & ' search for handle') ;local $return = _SendMessage($hwnd, $BM_CLICK, 0) ;_DebugPrint($return & ' return from sendmessage') For me that fires the _ShowMessage function for the correct control. M23 Rkey 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 Link to comment Share on other sites More sharing options...
Rkey Posted September 8, 2017 Author Share Posted September 8, 2017 Thanks Melba, that's exactly what I was searching for. Although I swear I looked at this function before, but couldn't get it to work (must be Friday....) Thanks again, Cheers Rick 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