Jump to content

Asigning functions to buttons


Recommended Posts

Hello again! Hope you're all well ;)

OK, I am writing a script to show from the system tray. To be honest, at the moment, gettin started, I am massively ripping off the brilliant work by

I only want a system tray icon, with the ability to right click it and select a menu option. So far, after bludgeoning one of Holgers examples, I have:

#include <GUIConstants.au3>
#include "ModernMenuRaw.au3"
#NoTrayIcon

Opt("GUIOnEventMode", 1) ; This is for both - GUI and Tray ownerdrawn menu items

;Create the tray icon
$TrayGUI = _TrayIconCreate("Tools", "shell32.dll", -13)
_TrayIconSetClick(-1, 16)
_TrayIconSetState() ; Show the tray icon

; *** Create the tray context menu ***
$nTrayMenu1 = _TrayCreateContextMenu()
$nSideItem3 = _CreateSideMenu($nTrayMenu1)
_SetSideMenuText($nSideItem3, "Home Group")
_SetSideMenuColor($nSideItem3) ; _SetSideMenuColor($nSideItem3, !!HEX Colour Here!!)
_SetSideMenuBkColor($nSideItem3, 0x000000)
_SetSideMenuBkGradColor($nSideItem3, 0xffffff)

$MenuMenu = _TrayCreateMenu("Menu")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$MenuDrives = _TrayCreateMenu("Driveinfo")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0); Force changing to ownerdrawn sometimes needed, i.e. in mixed menu
$MenuTools = _TrayCreateMenu("Tools")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$TrayHelp = _TrayCreateItem("Help")
$TrayRun = _TrayCreateItem("Run...")
_TrayCreateItem("")
_TrayItemSetIcon(-1, "", 0)
$TrayExit = _TrayCreateItem("Exit")

_TrayItemSetIcon($MenuMenu, "", 0)
_TrayItemSetIcon($MenuDrives, "shell32.dll", -9)
_TrayItemSetIcon($MenuTools, "shell32.dll", -20)
_TrayItemSetSelIcon($MenuTools, "shell32.dll", -44)
_TrayItemSetIcon($TrayHelp, "shell32.dll", -24)
_TrayItemSetIcon($TrayRun, "shell32.dll", -25)
_TrayItemSetIcon($TrayExit, "shell32.dll", -28)

GUICtrlSetState($TrayHelp, $GUI_DEFBUTTON)

; *** Sub menu items ***
$TrayCalc = _TrayCreateItem("Calculator", $MenuTools)
$TrayCMD = _TrayCreateItem("CMD", $MenuTools)
$TrayNotepad = _TrayCreateItem("Notepad", $MenuTools)
$TrayRegedit = _TrayCreateItem("Regedit", $MenuTools)

_TrayItemSetIcon($TrayCalc, "calc.exe", 0)
_TrayItemSetIcon($TrayCMD, "cmd.exe", 0)
_TrayItemSetIcon($TrayNotepad, "notepad.exe", 0)
_TrayItemSetIcon($TrayRegedit, "regedit.exe", 0)

_TrayCreateItem("Free Space:", $MenuDrives)
_TrayCreateItem("", $MenuDrives)

Exit

I have two questions to really get me started, and to a stage I think I could run with it.

Firstly, the icons; they are set with lines such as:

_TrayItemSetIcon($MenuDrives, "shell32.dll", -9)

I'm not sure what this means? I GUESS the icon is set from the windows directory (windows api??) somewhere and the '-9' parameter is an offset value as to which icon to choose? just a guess, maybe well off(?) could anyone shed some light on this?

Also how in Gods name do I get the buttons to function!? I have tried adding and editing the While statement from the help file --

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"about:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

But I'm failing; epically :)

Thanks alot for any answers guys!

3mgb

Edited by 3mustgetbeers
Link to comment
Share on other sites

I can get it to work fine using the help file example as a template:

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Display", $settingsitem)
$printeritem    = TrayCreateItem("Printer", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"about:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

But... I love the appearance and functionality added in Holgers script - much more appealing when customised to match its purpose, so ideally I would love to use something like that :)

Edit: When I say I can get it to work fine; i mean that I can use the above (from the help menu) to achieve the desired effect, however I would love to be able to use the functionality of Holgers tool ;)

Edited by 3mustgetbeers
Link to comment
Share on other sites

  • Moderators

mustgetbeers,

the icon is set from the windows directory (windows api??) somewhere and the '-9' parameter is an offset value as to which icon to choose

Spot on! shell32.dll is stuffed with icons and the -9 is used to index the one you want - just use something like ResHacker to look inside and see what is in there. Do not ask me why they are negative indices - they just are! :idiot:

how [...] do I get the buttons to function!?

You have set OnEvent mode with this line:

Opt("GUIOnEventMode", 1) ; This is for both - GUI and Tray ownerdrawn menu items

so polling TrayGetMsg in a loop is not likely to help. ;)

I have never used this UDF myself, but looking at the examples in the "sampleGUIandTray-OnEvent" example from the ModernMenu download it looks as if you need to define event functions for each menu item. You got the OnEventMode line from there - you just needed to keep going a bit deeper. :idiot:

Try that and see if it works. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...