GUI/Tray Menu with icons and colors
#241
Posted 18 November 2008 - 08:12 PM
i guess you could send a mouseclick to the icon by _SendMessage(IconHwnd, WM_RBUTTONDOWN) but i really don't know how to get the icon handle in the native autoit trayicon.
as to this udf, you will have a handle to the icon, so you could try it with _sendmessage. maybe it works.
j.
Don't forget this IP: 213.251.145.96
#242
Posted 18 November 2008 - 10:41 PM
http://www.autoitscript.com/forum/index.php?showtopic=13704
http://www.autoitscript.com/forum/index.ph...st&p=342464
http://www.autoitscript.com/forum/index.ph...st&p=406421
lots of examples. they will do it. good luck
j.
Don't forget this IP: 213.251.145.96
#243
Posted 18 November 2008 - 10:49 PM
#NoTrayIcon #Include <GuiToolBar.au3> _SysTray_ClickItem("AIMP2", "right", 1) If @error Then MsgBox(48, "Failure", "Required item not found") ;=========# _SysTray_ClickItem #====================================================== ; ;Function Name: _SysTray_ClickItem() ;Description: Click on item in Windows system tray by any substring in the title ;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item). ; $iButton - [optional] The button to click, "left" or "right". Default is the left button. ; $iClick - [optional] The number of times to click the mouse. Default is 1 ; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved ; $iSpeed = [optional] Mouse movement speed ;Return Value(s): Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 if required item not found ;Requirement(s): AutoIt 3.2.10.0 and above ;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea) ; ;==================================================================================== Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1) Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(1, 0, 0) EndIf $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $iButCount = 0 Then Return SetError(1, 0, 0) EndIf $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button2") If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button2") For $i = 0 To $iButCount - 1 $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed) Return 1 EndIf Next Return SetError(1, 0, 0) EndFunc
from here
forum Search
j.
Don't forget this IP: 213.251.145.96
#244
Posted 20 November 2008 - 04:22 PM
http://www.autoitscript.com/forum/index.ph...+show+tray+menu
How ever I have just scanned that thread to see wherever any one had posted a better solution than hijacking the mouse and keyboard to no oval.
But it seams that there is no better way to do is for autoits tray menu funcs.
So then what about the "cool menu with colour & icons script" of this thread. Is there some function
in it you can use for showing the tray menu with, in this case a hotkey?
I click you, you click me!The Home Of abushcrafter
#245
Posted 22 November 2008 - 12:20 AM
i cannot tell you exactly how, you will have to try out a lot.
Func _MyHotKeyFunc() ; DllCall($hUser32Dll, "int", "SetForegroundWindow","hwnd", GUICtrlGetHandle($mt)) ; _TrayNotifyIcon($mt, 512, $xxx, 0) ; DllCall($hUser32Dll, "int", "ShowWindow", "hwnd", $xxx,"int", @SW_SHOW) EndFunc
but meanwhile, this works fine and you should be satisfied with it, no ?
#NoTrayIcon #Include <GuiToolBar.au3> HotKeySet("{Enter}","_Click") While 1 Sleep(1) WEnd Func _Click(); enter the title of your trayitem here ! _SysTray_ClickItem("e", "right", 1) EndFunc ;=========# _SysTray_ClickItem #====================================================== ; ;Function Name: _SysTray_ClickItem() ;Description: Click on item in Windows system tray by any substring in the title ;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item). ; $iButton - [optional] The button to click, "left" or "right". Default is the left button. ; $iClick - [optional] The number of times to click the mouse. Default is 1 ; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved ; $iSpeed = [optional] Mouse movement speed ;Return Value(s): Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 if required item not found ;Requirement(s): AutoIt 3.2.10.0 and above ;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea) ; ;==================================================================================== Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1) Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(1, 0, 0) EndIf $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $iButCount = 0 Then Return SetError(1, 0, 0) EndIf $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button2") If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button2") For $i = 0 To $iButCount - 1 $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed) Return 1 EndIf Next Return SetError(1, 0, 0) EndFunc
the script clicks right on the first icon which title contains an "e".
cheers
j.
Don't forget this IP: 213.251.145.96
#246
Posted 22 November 2008 - 12:24 AM
from MSDN:
can anyone help with the fonts ?Setting Fonts for Menu-Item Text Strings
This topic contains an example from an application that uses owner-drawn menu items in a menu. The menu contains items that set the attributes of the current font, and the items are displayed using the appropriate font attribute.
Here is how the menu is defined in the resource-definition file. Note that the strings for the Regular, Bold, Italic, and Underline menu items are assigned at run time, so their strings are empty in the resource-definition file.
Copy Code
MainMenu MENU
BEGIN
POPUP "&Character"
BEGIN
MENUITEM "", IDM_REGULAR
MENUITEM SEPARATOR
MENUITEM "", IDM_BOLD
MENUITEM "", IDM_ITALIC
MENUITEM "", IDM_ULINE
END
END The application's window procedure processes the messages involved in using owner-drawn menu items. The application uses the WM_CREATE message to do the following:
Set the MF_OWNERDRAW flag for the menu items.
Set the text strings for the menu items.
Obtain handles of the fonts used to draw the items.
Obtain the text and background color values for selected menu items.
The text strings and font handles are stored in an array of application-defined MYITEM structures. The application-defined GetAFont function creates a font that corresponds to the specified font attribute and returns a handle to the font. The handles are destroyed during the processing of the WM_DESTROY message.
During the processing of the WM_MEASUREITEM message, the example gets the width and height of a menu-item string and copies these values into the MEASUREITEMSTRUCT structure. The system uses the width and height values to calculate the size of the menu.
During the processing of the WM_DRAWITEM message, the menu item's string is drawn with room left next to the string for the check-mark bitmap. If the user selects the item, the selected text and background colors are used to draw the item.
Copy Code
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
typedef struct _MYITEM
{
HFONT hfont;
LPSTR psz;
} MYITEM; // structure for item font and string
MYITEM *pmyitem; // pointer to item's font and string
static MYITEM myitem[CITEMS]; // array of MYITEMS
static HMENU hmenu; // handle to main menu
static COLORREF crSelText; // text color of selected item
static COLORREF crSelBkgnd; // background color of selected item
COLORREF crText; // text color of unselected item
COLORREF crBkgnd; // background color unselected item
LPMEASUREITEMSTRUCT lpmis; // pointer to item of data
LPDRAWITEMSTRUCT lpdis; // pointer to item drawing data
HDC hdc; // handle to screen DC
SIZE size; // menu-item text extents
WORD wCheckX; // check-mark width
int nTextX; // width of menu item
int nTextY; // height of menu item
int i; // loop counter
HFONT hfontOld; // handle to old font
BOOL fSelected = FALSE; // menu-item selection flag
size_t * pcch;
HRESULT hResult;
switch (uMsg)
{
case WM_CREATE:
// Modify the Regular, Bold, Italic, and Underline
// menu items to make them owner-drawn items. Associate
// a MYITEM structure with each item to contain the
// string for and font handle to each item.
hmenu = GetMenu(hwnd);
ModifyMenu(hmenu, IDM_REGULAR, MF_BYCOMMAND |
MF_CHECKED | MF_OWNERDRAW, IDM_REGULAR,
(LPTSTR) &myitem[REGULAR]);
ModifyMenu(hmenu, IDM_BOLD, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_BOLD, (LPTSTR) &myitem[BOLD]);
ModifyMenu(hmenu, IDM_ITALIC, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_ITALIC,
(LPTSTR) &myitem[ITALIC]);
ModifyMenu(hmenu, IDM_ULINE, MF_BYCOMMAND |
MF_OWNERDRAW, IDM_ULINE, (LPTSTR) &myitem[ULINE]);
// Retrieve each item's font handle and copy it into
// the hfont member of each item's MYITEM structure.
// Also, copy each item's string into the structures.
myitem[REGULAR].hfont = GetAFont(REGULAR);
myitem[REGULAR].psz = "Regular";
myitem[BOLD].hfont = GetAFont(BOLD);
myitem[BOLD].psz = "Bold";
myitem[ITALIC].hfont = GetAFont(ITALIC);
myitem[ITALIC].psz = "Italic";
myitem[ULINE].hfont = GetAFont(ULINE);
myitem[ULINE].psz = "Underline";
// Retrieve the text and background colors of the
// selected menu text.
crSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
crSelBkgnd = GetSysColor(COLOR_HIGHLIGHT);
return 0;
case WM_MEASUREITEM:
// Retrieve a device context for the main window.
hdc = GetDC(hwnd);
// Retrieve pointers to the menu item's
// MEASUREITEMSTRUCT structure and MYITEM structure.
lpmis = (LPMEASUREITEMSTRUCT) lParam;
pmyitem = (MYITEM *) lpmis->itemData;
// Select the font associated with the item into
// the main window's device context.
hfontOld = SelectObject(hdc, pmyitem->hfont);
// Retrieve the width and height of the item's string,
// and then copy the width and height into the
// MEASUREITEMSTRUCT structure's itemWidth and
// itemHeight members.
hResult = StringCchLength(pmyitem->psz,STRSAFE_MAX_CCH, pcch);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
GetTextExtentPoint32(hdc, pmyitem->psz,
*pcch, &size);
lpmis->itemWidth = size.cx;
lpmis->itemHeight = size.cy;
// Select the old font back into the device context,
// and then release the device context.
SelectObject(hdc, hfontOld);
ReleaseDC(hwnd, hdc);
return TRUE;
break;
case WM_DRAWITEM:
// Get pointers to the menu item's DRAWITEMSTRUCT
// structure and MYITEM structure.
lpdis = (LPDRAWITEMSTRUCT) lParam;
pmyitem = (MYITEM *) lpdis->itemData;
// If the user has selected the item, use the selected
// text and background colors to display the item.
if (lpdis->itemState & ODS_SELECTED)
{
crText = SetTextColor(lpdis->hDC, crSelText);
crBkgnd = SetBkColor(lpdis->hDC, crSelBkgnd);
fSelected = TRUE;
}
// Remember to leave space in the menu item for the
// check-mark bitmap. Retrieve the width of the bitmap
// and add it to the width of the menu item.
wCheckX = GetSystemMetrics(SM_CXMENUCHECK);
nTextX = wCheckX + lpdis->rcItem.left;
nTextY = lpdis->rcItem.top;
// Select the font associated with the item into the
// item's device context, and then draw the string.
hfontOld = SelectObject(lpdis->hDC, pmyitem->hfont);
hResult = StringCchLength(pmyitem->psz,STRSAFE_MAX_CCH, pcch);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
ExtTextOut(lpdis->hDC, nTextX, nTextY, ETO_OPAQUE,
&lpdis->rcItem, pmyitem->psz,
*pcch, NULL);
// Select the previous font back into the device
// context.
SelectObject(lpdis->hDC, hfontOld);
// Return the text and background colors to their
// normal state (not selected).
if (fSelected)
{
SetTextColor(lpdis->hDC, crText);
SetBkColor(lpdis->hDC, crBkgnd);
}
return TRUE;
// Process other messages.
case WM_DESTROY:
// Destroy the menu items' font handles.
for (i = 0; i < CITEMS; i++)
DeleteObject(myitem[i].hfont);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return NULL;
}
HFONT GetAFont(int fnFont)
{
static LOGFONT lf; // structure for font information
// Get a handle to the ANSI fixed-pitch font, and copy
// information about the font to a LOGFONT structure.
GetObject(GetStockObject(ANSI_FIXED_FONT), sizeof(LOGFONT),
&lf);
// Set the font attributes, as appropriate.
if (fnFont == BOLD)
lf.lfWeight = FW_BOLD;
else
lf.lfWeight = FW_NORMAL;
lf.lfItalic = (fnFont == ITALIC);
lf.lfItalic = (fnFont == ULINE);
// Create the font, and then return its handle.
return CreateFont(lf.lfHeight, lf.lfWidth,
lf.lfEscapement, lf.lfOrientation, lf.lfWeight,
lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet,
lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
lf.lfPitchAndFamily, lf.lfFaceName);
}
thx
j.
Don't forget this IP: 213.251.145.96
#247
Posted 23 November 2008 - 03:35 PM
i think it is possible to do just the same (AND MORE) with simple popup guis and labels. isn't it ? in this way you are free to design anything you like and it would be easier to use.... maybe i will give it a try when i have time...
j.
Don't forget this IP: 213.251.145.96
#248
Posted 25 November 2008 - 10:56 AM
I click you, you click me!The Home Of abushcrafter
#249
Posted 08 December 2008 - 08:01 PM
I need some help.
In my script I want to change the Tray icon. For this I do: TrayIconSetIcon(-1, 'icon.ico').
The old icon is destroyed, but the new icon from file "icon.ico" doesn't drawn.
What I do not rigth?
I have resolved this problem.
The Icon doesn't drawn If before it the _TrayIconSetState(-1,1) has not been done.
That's not good, I don't want to draw the old icon.
Edited by nickston, 09 December 2008 - 08:03 PM.
#250
Posted 31 December 2008 - 02:18 PM
#251
Posted 19 January 2009 - 07:23 AM
Hi. all.another question:
i can't get the icon flashing
To activate flashing use _TrayIconSetState($ID, 4)
doesn't seem to work.
any idea ?
j.
The ModernMenuRaw.au3 have a bug, from which _TrayIconSetState($ID, 4) don't work.
There is a set SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0), but there are must be the another set SetTimer($TRAYMSGWND, $nID, $FLASHTIMEOUT, 0). There are you need change two strings.
#252
Posted 13 March 2009 - 09:33 AM
I'm using this great tray menu but i can't get it to work with OnEvent ?
Here is the code i use:
$Setup = _TrayCreateItem("Setup") TrayItemSetOnEvent(-1, "Setup") _TrayItemSetIcon(-1, $ScriptDir & "\data\set.ico", 0)
TrayItemSetOnEvent is not trigerred when i click, why ?
#253
Posted 13 March 2009 - 11:06 AM
OnEvent functions are only called when the option TrayOnEventMode is set to 1 - when in this mode TrayGetMsg is NOT used at all.
#254
Posted 13 March 2009 - 01:02 PM
Did you mange to read this far in the help file and actually set Opt(TrayOnEventMode)?
Yes it's set to 1... in fact my tray menu worked with an old version done by jennico, now i use this nicer tray menu but my Events are not triggered
Can someone confirm it works with events ? as this i can't double check my code to see if i made a mistake somewhere
#255
Posted 13 March 2009 - 02:18 PM
#256
Posted 13 March 2009 - 02:19 PM
I think, this UDF uses GUI-Menus, not Tray-menus. So you should use GUIOnEventMode and GUICtrlSetOnEvent.
Thank you ProgAndy it works now
#257
Posted 10 May 2009 - 06:33 AM
#258
Posted 01 June 2009 - 09:00 AM
When using this UDF On x64 blank menu appears. ( Background white & characters white )
NO COLOR SETTINGS CHANGED.
GIVEN EXAMPLES CANNOT BE SEEN WHEN EXECUTED.
Functions are executed when clicked but not seen.
#259
Posted 01 June 2009 - 10:56 AM
#260
Posted 03 June 2009 - 07:24 AM
Yes you are right.
32 bit do run on 64bit , I've tried that.
The above situation is also valid for _SYSTRAY UDF.
In _SYSTRAY UDF, array returns nothing or same value or program crashed when using autoit x64.exe.
Thanks For Replying.
Edited by ZNote, 03 June 2009 - 07:25 AM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users





