pr1 Posted February 16, 2010 Share Posted February 16, 2010 Hello, can you process AutoIt Window events, such as left-click, right-click, etc? I am asking because I would like to create a System Tray Icon, which, when left-clicked, would display a dialog. Many thanks. pr1 Global $hWnd = WinGetHandle(AutoItWinGetTitle()) DllStructSetData($tNID, 'cbSize', DllStructGetSize($tNID)) DllStructSetData($tNID, 'hWnd', $hWnd) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 16, 2010 Moderators Share Posted February 16, 2010 pr1, I wrote this in response to another topic - I hope it helps you too! expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #Include <GuiToolBar.au3> Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown. TrayCreateItem("About") TrayItemSetOnEvent(-1, "On_About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "On_Exit") TraySetState() TraySetClick(8) ; Set left click to act as Play/Pause or New TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Dialog") ; Set tray icon tool tip $sToolTipText = "My Dialog" TraySetToolTip($sToolTipText) Global $iIcon_X, $iIcon_Y ; Find the tray icon _Locate_Icon() ; Create and hide the GUI GUICreate("My Dialog", 200, 200, $iIcon_X - 200, $iIcon_Y - 240) GUISetState(@SW_HIDE) While 1 Switch GUIGetMsg() ; Pressing either [_] or [X] rehides the GUI Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) EndSwitch WEnd Func On_Dialog() ; Show the GUI GUISetState(@SW_SHOW) EndFunc Func _Locate_Icon () ; Find taskbar Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "") ; Start icon position calculation $iIcon_X = $aPos[0] $iIcon_Y = $aPos[1] ; Get systray handle and position Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return ; Continue icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then Return ; Look for tooltip by finding track title For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) If StringInStr($sText, $sToolTipText) > 0 Then ; Get coords of icon $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSystray_ButtonNumber) ; Finalise icon position calculation $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ExitLoop EndIf If $iSystray_ButtonNumber = $iSystray_ButCount - 1 Then Return 1 Next Return 0 EndFunc Func On_About() MsgBox(0, "About", "Whatever") EndFunc Func On_Exit() Exit EndFunc 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...
pr1 Posted February 16, 2010 Author Share Posted February 16, 2010 pr1,I wrote this in response to another topic - I hope it helps you too! Many thanks M23. Exactly what I was looking for.pr1 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