Jump to content

GUI/Tray Menu with icons and colors


Holger
 Share

Recommended Posts

First, I'll add to the pile of thanks! This is a killer library, and it's going to make my little app look much more professional than I could have hoped for (especially considering my limited experience with AutoIt).

I have a couple of questions, that I hope are fairly simple...

I'm a bit confused by why things like _TrayCreateItem are tied to an icon. Not terribly important that I understand that, just curious.

I was also confused by all of the '-1' references, so I decided to try replace them in one small section (I chose the 'Tools' tray menu in 'sampleGUIandTray-OnEvent.au3'). It seems to be working, but I'm hoping somebody more familiar with the library could just confirm that I've done it correctly. I've also rearranged the order a bit, and I'm wondering if that might cause problems in some cases.

Here's my modification:

$MenuTools = _TrayCreateMenu($nTrayIcon1, "Tools")
$MenuIcon  = _TrayItemSetIcon($MenuTools, "shell32.dll", -20)
_TrayItemSetSelIcon($MenuTools, "shell32.dll", -44)

$TrayCalc   = _TrayCreateItem($MenuIcon, "Calculator", $MenuTools)
$TrayCMD     = _TrayCreateItem($MenuIcon, "CMD"    , $MenuTools)
$TrayNotepad = _TrayCreateItem($MenuIcon, "Notepad"   , $MenuTools)
$TrayRegedit = _TrayCreateItem($MenuIcon, "Regedit"   , $MenuTools)

GUICtrlSetState($TrayNotepad, $GUI_DISABLE)

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

_TrayCreateItem($nTrayIcon1, "")
_TrayItemSetIcon($nTrayIcon1, "", 0)

Thanks again for this excellent library!

Edited by aGorilla
Link to comment
Share on other sites

I'm a bit confused by why things like _TrayCreateItem are tied to an icon.

Good 'question'...thanks :D

I think there was a logical thinking problem to realize some things.

Info: next version will be script breaking!

I will add a new function _TrayCreateContexMenu(IconID) which will create a contextmenu for an icon.

So both tray item createfunctions only will change ie. from _TrayCreateItem(TrayIconID, Text, TrayParentMenuID) to _TrayCreateItem(Text, TrayParentMenuID)

which should also make script reading easier.

Edited by Holger
Link to comment
Share on other sites

Looking forward to it, I think that will be much easier to follow (at least it would be for me). Just finished replacing all of the -1 in the tray code from 'sampleGUIandTray-OnEvent.au3', and it seems to be working, so I think I finally understand how to bring this into my own app.

One more thought, if you're going to make the change, I'd prefer the id first, unless it's optional (text can vary in length much more than the id's will, and as you saw in my example above, 'I code in columns'). I'll leave it for others to chime in on their preferences, but I think this would be easier to read:

$TrayCalc    = _TrayCreateItem($MenuTools, "Calculator")
$TrayCMD      = _TrayCreateItem($MenuTools, "CMD"      )
$TrayNotepad  = _TrayCreateItem($MenuTools, "Notepad"   )
$TrayRegedit  = _TrayCreateItem($MenuTools, "Regedit"   )

$TrayAdvanced = _TrayCreateItem($MenuMenu , "Modern" ,  -1, 1)
$TraySimple   = _TrayCreateItem($MenuMenu , "Classic",  -1, 1)

In the end, it's your call, and I will use it no matter how you do it :D

I said it before, and I'll say it again, this really is a wonderful library. Thanks again.

Link to comment
Share on other sites

@Holger - Thanks for the input I managed to solve my darned problem. My girl is thankful to you also for me not going completely bald.

Kind regards,

C2C

----------------------------------90% of teens today would die if Myspace,Bebo + FaceBook had a system failure and was completely destroyed. If you are one of the 10% that would be laughing, copy and paste this to your signature.----------------------------------Code to win, 'till you die, 'till the compiler dies from your linesCode to win, take it all, just keep coding till you fallDay by day, codin' all the way, I'm not cavin' inLet another App begin, code to win

Link to comment
Share on other sites

Minor bug:

Some undeclared variables in ModernMenuRaw.au3 are throwing errors when using Opt('MustDeclareVars', 1). There may be others, but I've spotted these so far:

$hIcon
  _AddMenuIcon 
  _ReplaceMenuIcon

$nResult
  GetCursorPos     
  SetForegroundWindow

$stMenuLogFont (should this be a global? It's being 'cleared (set to '0'), but doesn't get used.)
  WM_MEASUREITEM
  WM_DRAWITEM

$stRect (not used elsewhere in this file)
  WM_DRAWITEM

Quick question:

How can I tie a non-menu event to the 'other' mouse button? For example, if I use _TrayIconSetClick($App('Tray_Icon'), 16), to show the menu when the icon is right-clicked, how can I make it launch a gui when left-clicked? Before I switched to ModernMenu, I was using:

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, 'TellMe')

That doesn't seem to work now. I've also tried GUICtrlSetOnEvent with no luck.

Any suggestions?

Link to comment
Share on other sites

@aGorilla: thanks for info :)

Will fix them - I think that these were older or test values.

For using click message info - just use it as I described it here:

http://www.autoitscript.com/forum/index.ph...st&p=513365

Link to comment
Share on other sites

Ok, another crazy question...

When using _TrayCreateMenu, is there some way to add an extra action when the item is clicked? I've tried both GUICtrlSetOnEvent and TrayItemSetOnEvent, but neither worked (as expected). I imagine that ModerMenu is trapping actions, to show the submenu. Is there some form of callback that I can add, to do additional things?

Edit: You can see what I'm trying to do with it here.

Edited by aGorilla
Link to comment
Share on other sites

Update 06.05.2008:

!!! Warning: Script breaking !!!

Please change the following commands to:

_TrayCreateItem(Text, ...)

_TrayCreateMenu(Text , ...)

- Fixed: some old values (thanks to aGorilla)

- Fixed: ..SetText() functions (thanks to MrCreatoR)

- Added the following commands:

_SetMenuIconBkGrdColor(Color)

_SetTrayIconBkGrdColor(Color)

New sidebar menu commands:

_CreateSideMenu(MenuID) ; returns a SideMenuID/index

_DeleteSideMenu(SideMenuID) ; delete a menu sidebar

_SetSideMenuText(SideMenuID, Text) ; set a text for the sidebar

_SetSideMenuColor(SideMenuID, Color) ; set text color

_SetSideMenuBkColor(SideMenuID, Color) ; set text background color

_SetSideMenuBkGradColor(SideMenuID, Color) ; set text background gradient color

_SetSideMenuImage(SideMenuID, Bitmapfile [, Resourcename/number [, Expand/Compress Bitmap]])

Just take a look into the samples how to use them!

At the moment there are some known issues:

- missing 64bit compatibility (already in progress, to fully work with "AutoIt3_x64.exe")

- moving the mouse cursor on the sidebar menu image/text also changes the current menu item selection

- for sidebar menu image only bitmaps are supported at the moment (min.8bpp)

Edited by Holger
Link to comment
Share on other sites

@Holger

Let me say: Wow!!! This is unbelievable! Thank you for the update with new features :)

P.S

This is one of those updates that pushes me to continue improving my scripts :(

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 3 weeks later...

I have an extension for Balloons:

_TrayShowBalloonTip($nTrayIcon3,"hio","gg",1) ; Show Balloon
Sleep(3000)
_TrayShowBalloonTip($nTrayIcon3,"") ; Hide Balloon

CODE
Func MyTrayTipCallBack($nID, $nMsg)

Switch $nID

Case $nTrayIcon2

Switch $nMsg

Case $NIN_BALLOONUSERCLICK, $NIN_BALLOONTIMEOUT

_TrayIconSetState($nTrayIcon2, 8) ; Stop icon flashing

If $nMsg = $NIN_BALLOONUSERCLICK Then MsgBox(64, "Information", "This could be your message.")

_TrayIconSetState($nTrayIcon2, 2) ; Hide icon

EndSwitch

Case $nTrayIcon3

Switch $nMsg

;;; Case $WM_LBUTTONDOWN

; Put your stuff here

;;; case $WM_LBUTTONUP

; Put your stuff here ; One click and double click to put together is difficult

case $WM_LBUTTONDBLCLK

MsgBox(0, "Info", "You left double clicked on TrayIcon3.")

GUISetState(@SW_RESTORE, $hMainGUI) ; Restore/put focus back to our main GUI

;;; case $WM_RBUTTONDOWN

; Put your stuff here

case $WM_RBUTTONUP

MsgBox(0, "Info", "You right clicked on TrayIcon3.")

GUISetState(@SW_RESTORE, $hMainGUI) ; Restore/put focus back to our main GUI

;;; case $WM_RBUTTONDBLCLK

; Put your stuff here

;;; case $WM_MOUSEMOVE

; Put your stuff here

; BALLOON Functions :)

Case $NIN_BALLOONUSERCLICK

ToolTip("")

MsgBox(0, '', "Balloon clicked")

Case $NIN_BALLOONTIMEOUT

ToolTip("")

MsgBox(0, '', "Balloon timed out")

Case $NIN_BALLOONSHOW

ToolTip("Balloon show")

Case $NIN_BALLOONHIDE

ToolTip("")

MsgBox(0, '', "Balloon Hide")

; END BALLOON

EndSwitch

EndSwitch

EndFunc

; Author: Prog@ndy

; according to http://www.vbaccelerator.com/home/VB/Code/...SysTray_frm.asp

Func _TrayShowBalloonTip( $nID , _

$sMessage , _

$sTitle = "", _

$eIcon = 0, _

$lTimeOutMs = 30000 _

)

;~ If $nState = 0 Then Return 1 ; No change

If $nID = -1 Then $nID = $TRAYLASTID

If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

Local $i, $nResult = 0, $bFound = FALSE

For $i = 1 To $TRAYNOTIFYIDS[0][0]

If $nID = $TRAYNOTIFYIDS[$i][0] Then

$bFound = TRUE

ExitLoop

EndIf

Next

If Not $bFound Then Return 0

If (@OSTYPE = "WIN32_NT" And Not (@OSVersion="WIN_NT4")) Then

Local $stNID = DllStructCreate($sNOTIFYICONDATAW)

DllStructSetData($stNID, 1, DllStructGetSize($stNID))

DllStructSetData($stNID, 2, $TRAYMSGWND)

DllStructSetData($stNID, 3, $nID)

DllStructSetData($stNID, 10, $sMessage) ;"szInfo"

DllStructSetData($stNID, 12, $sTitle) ; "szInfoTitle"

DllStructSetData($stNID, 11, $lTimeOutMs) ; "uTimeOutOrVersion"

DllStructSetData($stNID, 13, $eIcon) ; "dwInfoFlags"

DllStructSetData($stNID, 4, $NIF_INFO) ; "uFlags"

Return Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))

EndIf

Return SetError(1,0,0)

EndFunc

You can use it directly in sampleGUIandTray-OnEvent.au3. Replace MyTrayTipCallBack with the one above and add _TrayShowBalloonTip

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

There is already a function included:

_TrayTip(ID, Title, Text, TimeOut, InfoFlags)

Also the notification is as example there - just take a look into the examples.

Edited by Holger
Link to comment
Share on other sites

Oops, I didn't see it :), and i didn't find it in examples.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Sorry if this is a dumb question -- I'm new and just downloaded the samples. Is the tools menu in the samples just for show, or when I click one should the app (e.g., calculator) be getting launched? Looks like they should launch, but nothing is happening.

Thanks,

Sheri

Link to comment
Share on other sites

@Sheri: no, the "exe-file" in the commands (_GUICtrlCreateODMenuItem) are just only to get the right icon of the "exe".

At the moment there is no command to start the program.

You can add it after the "GUIGetMsg()" for instance.

Link to comment
Share on other sites

Yes....but not really as you do expect.

I have additional created a just "basic"/"simple" version of the "ModernMenu" which is/will be 18-25 KB - so much smaller and support directly using Vista menus with icons (after reading some articles).

I just have to add again the tray stuff for testing then it will be published maybe on sunday.

Edit: forgot to say that I will seperate the menu and tray stuff (sometimes you want additional tray stuff but don't need menu icons...)

Edited by Holger
Link to comment
Share on other sites

Yes....but not really as you do expect.

I have additional created a just "basic"/"simple" version of the "ModernMenu" which is/will be 18-25 KB - so much smaller and support directly using Vista menus with icons (after reading some articles).

I just have to add again the tray stuff for testing then it will be published maybe on sunday.

Edit: forgot to say that I will seperate the menu and tray stuff (sometimes you want additional tray stuff but don't need menu icons...)

Sounds great Holger. I'll be waiting for it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...