I found a work around for anyone who is interested about the problem i described above.
This is a script that demonstrates my problem as desribed above. No includes neccesary. If you comment out the line in red the gLabel is executed with no problem. If you enable that function the gLabel gets lost.
Code:
;Forces the program to only run one instance. If it is already open,
;it closes the existing instance and replaces it with a new one.
#SingleInstance Force
SetBatchLines, -1 ;No Delay between lines
Menu, Tray, Tip, VNCGUI
FontOptions = cWhite s8 +Center ;Font Options ex cColor(HTML or HEX) sSize +Center
Font = Arial ;Font Style ex. Arial, Arial Bold, Arial bold Italic, Times New Roman
GuiColor = White ;Gui Color
Gui, Color, %GuiColor%
Gui, Font, %FontOptions%, %Font%
;------------------Add Button Loop-----------------------
;--------------------------------------------------------
Gui, Add, Button, x10 y10 w50 h50 , VNC Viewer ;Add VNC button
Gui, +LastFound
MI_EnableOwnerDrawnMenus(WinExist())
;===========================Add File Menu,icons and tooltip==========================
Menu, FileMenu, Add, Add Client, c
MI_SetMenuItemIcon("FileMenu", 1, "shell32.dll", 45, 16)
Menu, FileMenu, Add, Enable VNCGUI, c
MI_SetMenuItemIcon("FileMenu", 2, "shell32.dll", 45, 16)
Menu, FileMenu, Add, Disable VNCGUI, c
MI_SetMenuItemIcon("FileMenu", 3, "shell32.dll", 48, 16)
Menu, FileMenu, Add
Menu, FileMenu, Add, Exit, c
MI_SetMenuItemBitmap("FileMenu", 5, 6) ; exit
MI_SetMenuStyle("FileMenu", 0x4000000)
;===========================Add Edit Menu,icons and tooltip==========================
Menu, EditMenu, Add, Edit this Script, c
MI_SetMenuItemIcon("EditMenu", 1, A_AhkPath, 2, 16)
Menu, EditMenu, Add, Edit Client List, c
MI_SetMenuItemIcon("EditMenu", 2, A_AhkPath, 2, 16)
Menu, EditMenu, Add
Menu, EditMenu, Add, Edit Script on J:\, c
MI_SetMenuItemIcon("EditMenu", 4, A_AhkPath, 2, 16)
Menu, EditMenu, Add, Edit IP List on J:\, c
MI_SetMenuItemIcon("EditMenu", 5, A_AhkPath, 2, 16)
MI_SetMenuStyle("EditMenu", 0x4000000)
;===========================Add BackUp Menu,icons and tooltip==========================
Menu, BackUpMenu, Add, Back Up VNCGUI on J:\, c
MI_SetMenuItemIcon("BackUpMenu", 1, "shell32.dll", 69, 16)
Menu, BackUpMenu, Add, Back Up VNCGUI Directory, c
MI_SetMenuItemIcon("BackUpMenu", 2, "shell32.dll", 69, 16)
MI_SetMenuStyle("BackUpMenu", 0x4000000)
;===========================Add Help Menu,icons and tooltip==========================
Menu, HelpMenu, Add, Client List Help, c
MI_SetMenuItemIcon("HelpMenu", 1, A_WinDir "\hh.exe", 1, 16)
Menu, HelpMenu, Add, Script Help, c
MI_SetMenuItemIcon("HelpMenu", 2, A_WinDir "\hh.exe", 1, 16)
MI_SetMenuStyle("HelpMenu", 0x4000000)
;===========================Add About Menu,icons and tooltip==========================
Menu, AboutMenu, Add, About, c
MI_SetMenuItemIcon("AboutMenu", 1, "shell32.dll", 24, 16)
MI_SetMenuStyle("AboutMenu", 0x4000000)
;======================Attach the sub-menus that were created above===================
Menu, MyMenuBar, Add, File, :FileMenu
Menu, MyMenuBar, Add, Edit, :EditMenu
Menu, MyMenuBar, Add, Back Up, :BackUpMenu
Menu, MyMenuBar, Add, Help, :HelpMenu
Menu, MyMenuBar, Add, About, :AboutMenu
Gui, Menu, MyMenuBar
;======================Show Main Gui ===================
Gui +OwnDialogs +LastFound
WinTitle = Real VNC %A_ComputerName% -- %A_IPAddress1%
Gui, Show, w200 h200, %WinTitle%
MainWin := WinExist()
Return
;============Button Handler=======================
;=================================================
ButtonVNCViewer:
MsgBox, Button Label Worked!!!!
Return
c:
MsgBox, %A_ThisMenu%`n%A_ThisMenuItem%`n%A_ThisMenuItemPos%
Return
; Menu Icons v2.2
; by Lexikos
;
; Associates an icon with a menu item.
; NOTE: On versions of Windows other than Vista, the menu MUST be shown with
; MI_ShowMenu() for the icons to appear.
;
; MenuNameOrHandle
; The name or handle of a menu. When setting icons for multiple items,
; it is more efficient to use a handle returned by MI_GetMenuHandle("menuname").
; ItemPos
; The position of the menu item, where 1 is the first item.
; FilenameOrHICON
; The filename or handle of an icon.
; SUPPORTS EXECUTABLE FILES ONLY (EXE/DLL/ICL/CPL/etc.)
; IconNumber
; The icon group to use (if omitted, it defaults to 1.)
; This is not used if FilenameOrHICON specifies an icon handle.
; IconSize
; The desired width and height of the icon. If omitted, the system's small icon size is used.
; h_bitmap
; h_icon
; v2.2: These parameters are no longer used as MI now automatically deletes the
; icon/bitmap if a new icon/bitmap is being set.
; OBSOLETE:
; These are set to the bitmap or icon resources which are used.
; Bitmaps and icons can be deleted as follows:
; DllCall("DeleteObject", "uint", h_bitmap)
; DllCall("DestroyIcon", "uint", h_icon)
; This is only necessary if the menu item displaying these resources
; is manually removed.
; Usually only one of h_icon or h_bitmap will be used, and the other will be 0 (NULL).
;
; OPERATING SYSTEM NOTES:
;
; Windows 2000 and above:
; PrivateExtractIcons() is used to extract the icon.
;
; Older versions of Windows:
; PrivateExtractIcons() is not available, so ExtractIconEx() is used.
; As a result, a 16x16 or 32x32 icon will be loaded. If a size is specified,
; the icon may be stretched to fit. If no size is specified, 16x16 is used.
;
MI_SetMenuItemIcon(MenuNameOrHandle, ItemPos, FilenameOrHICON, IconNumber=1, IconSize=0, ByRef unused1="", ByRef unused2="")
{
; Set for compatibility with older scripts:
unused1=0
unused2=0
if MenuNameOrHandle is integer
h_menu := MenuNameOrHandle
else
h_menu := MI_GetMenuHandle(MenuNameOrHandle)
if !h_menu
return false
if FilenameOrHICON is integer
{
; May be 0 to remove icon.
h_icon := FilenameOrHICON
; Copy and potentially resize the icon. Since the caller is probably "caching"
; icon handles or assigning them to multiple items, we don't want to delete
; it if/when a future call to this function re-sets this item's icon.
if h_icon
h_icon := DllCall("CopyImage","uint",h_icon,"uint",1
,"int",IconSize,"int",IconSize,"uint",0)
; else caller wants to remove and delete existing icon.
}
else
{
; Load icon from file. Remember to clean up this icon if we end up using a bitmap.
; Resizing is not necessary in this case since MI_ExtractIcon already does that.
if !(loaded_icon := h_icon := MI_ExtractIcon(FilenameOrHICON, IconNumber, IconSize))
return false
}
; Windows Vista supports 32-bit alpha-blended bitmaps in menus. Note that
; A_OSVersion does not report WIN_VISTA when running in compatibility mode.
; To get nice icons on other versions of Windows, we need to owner-draw.
; DON'T TOUCH UNLESS YOU KNOW WHAT YOU'RE DOING:
; use_bitmap MUST have the same value for each use on a given menu item.
use_bitmap := (A_OSVersion="WIN_VISTA")
; Get the previous bitmap or icon handle.
VarSetCapacity(mii,48,0), NumPut(48,mii), NumPut(0xA0,mii,4)
if DllCall("GetMenuItemInfo","uint",h_menu,"uint",ItemPos-1,"uint",1,"uint",&mii)
h_previous := use_bitmap ? NumGet(mii,44,"int") : NumGet(mii,32,"int")
if use_bitmap
{
if h_icon
{
h_bitmap := MI_GetBitmapFromIcon32Bit(h_icon, IconSize, IconSize)
if loaded_icon
{
; The icon we loaded is no longer needed.
DllCall("DestroyIcon","uint",loaded_icon)
; Don't try to destroy the now invalid handle again:
loaded_icon := 0
}
if !h_bitmap
return false
}
else
; Caller wants to remove and delete existing icon.
h_bitmap := 0
NumPut(0x80,mii,4) ; fMask: Set hbmpItem only, not dwItemData.
, NumPut(h_bitmap,mii,44) ; hbmpItem = h_bitmap
}
else
{
; Associate the icon with the menu item. Relies on the probable case that no other
; script or dll will use dwItemData. If other scripts need to associate data with
; an item, MI should be expanded to allow it.
NumPut(h_icon,mii,32) ; dwItemData = h_icon
, NumPut(-1,mii,44) ; hbmpItem = HBMMENU_CALLBACK
}
if DllCall("SetMenuItemInfo","uint",h_menu,"uint",ItemPos-1,"uint",1,"uint",&mii)
{
; Only now that we know it's a success, delete the previous icon or bitmap.
if use_bitmap
{ ; Exclude NULL and predefined HBMMENU_ values (-1, 1..11).
if (h_previous < -1 || h_previous > 11)
DllCall("DeleteObject","uint",h_previous)
} else
DllCall("DestroyIcon","uint",h_previous)
return true
}
; ELSE FAIL
if loaded_icon
DllCall("DestroyIcon","uint",loaded_icon)
return false
}
; v2.2: This should be used to remove and delete all icons in a menu before deleting the menu.
MI_RemoveIcons(MenuNameOrHandle)
{
if MenuNameOrHandle is integer
h_menu := MenuNameOrHandle
else
h_menu := MI_GetMenuHandle(MenuNameOrHandle)
if !h_menu
return
Loop % DllCall("GetMenuItemCount","uint",h_menu)
MI_SetMenuItemIcon(h_menu, A_Index, 0)
}
; Set a menu item's associated bitmap.
; hBitmap can be a handle to a bitmap, or a HBMMENU value (see below.)
MI_SetMenuItemBitmap(MenuNameOrHandle, ItemPos, hBitmap)
{
if MenuNameOrHandle is integer
h_menu := MenuNameOrHandle
else
h_menu := MI_GetMenuHandle(MenuNameOrHandle)
if !h_menu
return false
VarSetCapacity(mii,48,0), NumPut(48,mii), NumPut(0x80,mii,4), NumPut(hBitmap,mii,44)
return DllCall("SetMenuItemInfo","uint",h_menu,"uint",ItemPos-1,"uint",1,"uint",&mii)
}
/*
HBMMENU_SYSTEM = 1
HBMMENU_MBAR_RESTORE = 2
HBMMENU_MBAR_MINIMIZE = 3
HBMMENU_MBAR_CLOSE = 5
HBMMENU_MBAR_CLOSE_D = 6
HBMMENU_MBAR_MINIMIZE_D = 7
HBMMENU_POPUP_CLOSE = 8
HBMMENU_POPUP_RESTORE = 9
HBMMENU_POPUP_MAXIMIZE = 10
HBMMENU_POPUP_MINIMIZE = 11
*/
;
; General Functions
;
; Gets a menu handle from a menu name.
; Adapted from Shimanov's Menu_AssignBitmap()
; http://www.autohotkey.com/forum/topic7526.html
MI_GetMenuHandle(menu_name)
{
static h_menuDummy
; v2.2: Check for !h_menuDummy instead of h_menuDummy="" in case init failed last time.
If !h_menuDummy
{
Menu, menuDummy, Add
Menu, menuDummy, DeleteAll
Gui, 99:Menu, menuDummy
; v2.2: Use LastFound method instead of window title. [Thanks animeaime.]
Gui, 99:+LastFound
h_menuDummy := DllCall("GetMenu", "uint", WinExist())
Gui, 99:Menu
Gui, 99:Destroy
; v2.2: Return only after cleaning up. [Thanks animeaime.]
if !h_menuDummy
return 0
}
Menu, menuDummy, Add, :%menu_name%
h_menu := DllCall( "GetSubMenu", "uint", h_menuDummy, "int", 0 )
DllCall( "RemoveMenu", "uint", h_menuDummy, "uint", 0, "uint", 0x400 )
Menu, menuDummy, Delete, :%menu_name%
return h_menu
}
; Valid (and safe to use) styles:
; MNS_AUTODISMISS 0x10000000
; MNS_CHECKORBMP 0x04000000 The same space is reserved for the check mark and the bitmap.
; MNS_NOCHECK 0x80000000 No space is reserved to the left of an item for a check mark.
MI_SetMenuStyle(MenuNameOrHandle, style)
{
if MenuNameOrHandle is integer
h_menu := MenuNameOrHandle
else
h_menu := MI_GetMenuHandle(MenuNameOrHandle)
if !h_menu
return
VarSetCapacity(mi,28,0), NumPut(28,mi)
NumPut(0x10,mi,4) ; fMask=MIM_STYLE
NumPut(style,mi,8)
DllCall("SetMenuInfo","uint",h_menu,"uint",&mi)
}
; Extract an icon from an executable, DLL or icon file.
MI_ExtractIcon(Filename, IconNumber, IconSize)
{
; LoadImage is not used..
; ..with exe/dll files because:
; it only works with modules loaded by the current process,
; it needs the resource ordinal (which is not the same as an icon index), and
; ..with ico files because:
; it can only load the first icon (of size %IconSize%) from an .ico file.
; If possible, use PrivateExtractIcons, which supports any size of icon.
if A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
{
r:=DllCall("PrivateExtractIcons"
,"str",Filename,"int",IconNumber-1,"int",IconSize,"int",IconSize
,"uint*",h_icon,"uint*",0,"uint",1,"uint",0,"int")
; StdOut("icon: " h_icon ", size: " IconSize ", num: " IconNumber ", file: " Filename)
if !ErrorLevel
{
if !h_icon || r>1
{
Clipboard:=Filename
ListVars
Pause
}
return h_icon
}
}
; Use ExtractIconEx, which only returns 16x16 or 32x32 icons.
if DllCall("shell32.dll\ExtractIconExA","str",Filename,"int",IconNumber-1
,"uint*",h_icon,"uint*",h_icon_small,"uint",1)
{
SysGet, SmallIconSize, 49
; Use the best-fit size; delete the other. Defaults to small icon.
if (IconSize <= SmallIconSize) {
DllCall("DestroyIcon","uint",h_icon)
h_icon := h_icon_small
} else
DllCall("DestroyIcon","uint",h_icon_small)
; I think PrivateExtractIcons resizes icons automatically,
; so resize icons returned by ExtractIconEx for consistency.
if (h_icon && IconSize)
h_icon := DllCall("CopyImage","uint",h_icon,"uint",1,"int",IconSize
,"int",IconSize,"uint",4|8)
}
return h_icon ? h_icon : 0
}
;
; Owner-Drawn Menu Functions
;
; Sub-classes a window from THIS process to owner-draw menu icons.
; This allows the menu to be shown by means other than MI_ShowMenu().
MI_EnableOwnerDrawnMenus(hwnd="")
{
if (hwnd="") { ; Use the script's main window if hwnd was omitted.
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Process, Exist
hwnd := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
DetectHiddenWindows, %dhw%
}
if !hwnd
return
wndProc := RegisterCallback("MI_OwnerDrawnMenuItemWndProc","",4
,DllCall("GetWindowLong","uint",hwnd,"uint",-4))
return DllCall("SetWindowLong","uint",hwnd,"int",-4,"int",wndProc,"uint")
}
; Shows a menu, allowing owner-drawn icons to be drawn.
MI_ShowMenu(MenuNameOrHandle, x="", y="")
{
static hInstance, hwnd, ClassName := "OwnerDrawnMenuMsgWin"
if MenuNameOrHandle is integer
h_menu := MenuNameOrHandle
else
h_menu := MI_GetMenuHandle(MenuNameOrHandle)
if !h_menu
return false
if !hwnd
{ ; Create a message window to receive owner-draw messages from the menu.
; Only one window is created per instance of the script.
if !hInstance
hInstance := DllCall("GetModuleHandle", "UInt", 0)
; Register a window class to associate OwnerDrawnMenuItemWndProc()
; with the window we will create.
wndProc := RegisterCallback("MI_OwnerDrawnMenuItemWndProc","",4,0)
if !wndProc {
ErrorLevel = RegisterCallback
return false
}
; Create a new window class.
VarSetCapacity(wc, 40, 0) ; WNDCLASS wc
NumPut(wndProc, wc, 4) ; lpfnWndProc
NumPut(hInstance, wc,16) ; hInstance
NumPut(&ClassName,wc,36) ; lpszClassname
; Register the class.
if !DllCall("RegisterClass","uint",&wc)
{ ; failed, free the callback.
DllCall("GlobalFree","uint",wndProc)
ErrorLevel = RegisterClass
return false
}
;
; Create the message window.
;
if A_OSVersion in WIN_XP,WIN_VISTA
hwndParent = -3 ; HWND_MESSAGE (message-only window)
else
hwndParent = 0 ; un-owned
hwnd := DllCall("CreateWindowExA","uint",0,"str",ClassName,"str",ClassName
,"uint",0,"int",0,"int",0,"int",0,"int",0,"uint",hwndParent
,"uint",0,"uint",hInstance,"uint",0)
if !hwnd {
ErrorLevel = CreateWindowEx
return false
}
}
prev_hwnd := DllCall("GetForegroundWindow")
; Required for the menu to initially have focus.
;DllCall("SetForegroundWindow","uint",hwnd)
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
WinActivate, ahk_id %hwnd%
DetectHiddenWindows, %dhw%
if (x="" or y="") {
CoordMode, Mouse, Screen
MouseGetPos, x, y
}
; returns non-zero on success.
ret := DllCall("TrackPopupMenu","uint",h_menu,"uint",0,"int",x,"int",y
,"int",0,"uint",hwnd,"uint",0)
if WinExist("ahk_id " prev_hwnd)
DllCall("SetForegroundWindow","uint",prev_hwnd)
; Required to let AutoHotkey process WM_COMMAND messages we may have
; sent as a result of clicking a menu item. (Without this, the item-click
; won't register if there is an 'ExitApp' after ShowOwnerDrawnMenu returns.)
Sleep, 1
return ret
}
MI_OwnerDrawnMenuItemWndProc(hwnd, Msg, wParam, lParam)
{
static WM_DRAWITEM = 0x002B, WM_MEASUREITEM = 0x002C, WM_COMMAND = 0x111
static ScriptHwnd
Critical 500
if (Msg = WM_MEASUREITEM && wParam = 0)
{ ; MSDN: wParam - If the value is zero, the message was sent by a menu.
h_icon := NumGet(lParam+20)
if !h_icon
return false
; Measure icon and put results into lParam.
VarSetCapacity(buf,24)
if DllCall("GetIconInfo","uint",h_icon,"uint",&buf)
{
hbmColor := NumGet(buf,16)
hbmMask := NumGet(buf,12)
x := DllCall("GetObject","uint",hbmColor,"int",24,"uint",&buf)
DllCall("DeleteObject","uint",hbmColor)
DllCall("DeleteObject","uint",hbmMask)
if !x
return false
NumPut(NumGet(buf,4,"int")+2, lParam+12) ; width
NumPut(NumGet(buf,8,"int") , lParam+16) ; height
return true
}
return false
}
else if (Msg = WM_DRAWITEM && wParam = 0)
{
hdcDest := NumGet(lParam+24)
x := NumGet(lParam+28)
y := NumGet(lParam+32)
h_icon := NumGet(lParam+44)
if !(h_icon && hdcDest)
return false
return DllCall("DrawIconEx","uint",hdcDest,"int",x,"int",y,"uint",h_icon
,"uint",0,"uint",0,"uint",0,"uint",0,"uint",3)
}
else if (Msg = WM_COMMAND && !(wParam>>16)) ; (clicked a menu item)
{
DetectHiddenWindows, On
if !ScriptHwnd {
Process, Exist
ScriptHwnd := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
}
if (hwnd != ScriptHwnd) {
; Forward this message to the AutoHotkey main window.
PostMessage, Msg, wParam, lParam,, ahk_id %ScriptHwnd%
return ErrorLevel
}
}
if A_EventInfo ; Let the "super-class" window procedure handle all other messages.
return DllCall("CallWindowProc","uint",A_EventInfo,"uint",hwnd,"uint",Msg,"uint",wParam,"uint",lParam)
else ; Let the default window procedure handle all other messages.
return DllCall("DefWindowProc","uint",hwnd,"uint",Msg,"uint",wParam,"uint",lParam)
}
;
; Windows Vista Menu Icons
;
; Note: 32-bit alpha-blended menu item bitmaps are supported only on Windows Vista.
; Article on menu icons in Vista:
; http://shellrevealed.com/blogs/shellblog/archive/2007/02/06/Vista-Style-Menus_2C00_-Part-1-_2D00_-Adding-icons-to-standard-menus.aspx
MI_GetBitmapFromIcon32Bit(h_icon, width=0, height=0)
{
VarSetCapacity(buf,40) ; used as ICONINFO (20), BITMAP (24), BITMAPINFO (40)
if DllCall("GetIconInfo","uint",h_icon,"uint",&buf) {
hbmColor := NumGet(buf,16) ; used to measure the icon
hbmMask := NumGet(buf,12) ; used to generate alpha data (if necessary)
}
if !(width && height) {
if !hbmColor or !DllCall("GetObject","uint",hbmColor,"int",24,"uint",&buf)
return 0
width := NumGet(buf,4,"int"), height := NumGet(buf,8,"int")
}
; Create a device context compatible with the screen.
if (hdcDest := DllCall("CreateCompatibleDC","uint",0))
{
; Create a 32-bit bitmap to draw the icon onto.
VarSetCapacity(buf,40,0), NumPut(40,buf), NumPut(1,buf,12,"ushort")
NumPut(width,buf,4), NumPut(height,buf,8), NumPut(32,buf,14,"ushort")
if (bm := DllCall("CreateDIBSection","uint",hdcDest,"uint",&buf,"uint",0
,"uint*",pBits,"uint",0,"uint",0))
{
; SelectObject -- use hdcDest to draw onto bm
if (bmOld := DllCall("SelectObject","uint",hdcDest,"uint",bm))
{
; Draw the icon onto the 32-bit bitmap.
DllCall("DrawIconEx","uint",hdcDest,"int",0,"int",0,"uint",h_icon
,"uint",width,"uint",height,"uint",0,"uint",0,"uint",3)
DllCall("SelectObject","uint",hdcDest,"uint",bmOld)
}
; Check for alpha data.
has_alpha_data := false
Loop, % height*width
if NumGet(pBits+0,(A_Index-1)*4) & 0xFF000000 {
has_alpha_data := true
break
}
if !has_alpha_data
{
; Ensure the mask is the right size.
hbmMask := DllCall("CopyImage","uint",hbmMask,"uint",0
,"int",width,"int",height,"uint",4|8)
VarSetCapacity(mask_bits, width*height*4, 0)
if DllCall("GetDIBits","uint",hdcDest,"uint",hbmMask,"uint",0
,"uint",height,"uint",&mask_bits,"uint",&buf,"uint",0)
{ ; Use icon mask to generate alpha data.
Loop, % height*width
if (NumGet(mask_bits, (A_Index-1)*4))
NumPut(0, pBits+(A_Index-1)*4)
else
NumPut(NumGet(pBits+(A_Index-1)*4) | 0xFF000000, pBits+(A_Index-1)*4)
} else { ; Make the bitmap entirely opaque.
Loop, % height*width
NumPut(NumGet(pBits+(A_Index-1)*4) | 0xFF000000, pBits+(A_Index-1)*4)
}
}
}
; Done using the device context.
DllCall("DeleteDC","uint",hdcDest)
}
if hbmColor
DllCall("DeleteObject","uint",hbmColor)
if hbmMask
DllCall("DeleteObject","uint",hbmMask)
return bm
}
;Exits Apllication
GUIClose:
ExitApp
This is a script the fixes the above mentioned problem. I extract the icon to an hbitmap and assign that to the menu instead of the icon directly. Transparency is lost but for me thats not a big deal.
Youll have to include gdip.ahk by tic
http://www.autohotkey.com/forum/topic32 ... light=gdip and menu icons v2.2(MI.ahk) by Lexikos
http://www.autohotkey.com/forum/topic21991.html Code:
;Forces the program to only run one instance. If it is already open,
;it closes the existing instance and replaces it with a new one.
#SingleInstance Force
SetBatchLines, -1 ;No Delay between lines
Menu, Tray, Tip, VNCGUI
FontOptions = cWhite s8 +Center ;Font Options ex cColor(HTML or HEX) sSize +Center
Font = Arial ;Font Style ex. Arial, Arial Bold, Arial bold Italic, Times New Roman
GuiColor = White ;Gui Color
Gui, Color, %GuiColor%
Gui, Font, %FontOptions%, %Font%
;------------------Add Button Loop-----------------------
;--------------------------------------------------------
Gui, Add, Button, x10 y10 w50 h50 , VNC Viewer ;Add VNC button
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
;===========================Add File Menu,icons ==========================
Menu, FileMenu, Add, Add Client, c
hBitmap := ExtractIcontohBitmap("C:\Program Files\RealVNC\VNC4\vncviewer.exe", 1, 16)
MI_SetMenuItemBitmap("FileMenu", 1, hBitmap)
Menu, FileMenu, Add, Enable VNCGUI, c
hBitmap := ExtractIcontohBitmap("shell32.dll", 45, 16)
MI_SetMenuItemBitmap("FileMenu", 2, hBitmap)
Menu, FileMenu, Add, Disable VNCGUI, c
hBitmap := ExtractIcontohBitmap("shell32.dll", 48, 16)
MI_SetMenuItemBitmap("FileMenu", 3, hBitmap) ; exit
Menu, FileMenu, Add
Menu, FileMenu, Add, Exit, c
MI_SetMenuItemBitmap("FileMenu", 5, 6) ; exit
MI_SetMenuStyle("FileMenu", 0x4000000)
;===========================Add Edit Menu,icons ==========================
Menu, EditMenu, Add, Edit this Script, c
hBitmap := ExtractIcontohBitmap(A_AhkPath, 2, 16)
MI_SetMenuItemBitmap("EditMenu", 1, hBitmap)
Menu, EditMenu, Add, Edit Client List, c
hBitmap := ExtractIcontohBitmap(A_ProgramFiles "\AutoHotkey\SciTE\SciTE.exe", 1, 16)
MI_SetMenuItemBitmap("EditMenu", 2, hBitmap)
Menu, EditMenu, Add
Menu, EditMenu, Add, Edit Script on J:\, c
hBitmap := ExtractIcontohBitmap(A_AhkPath, 2, 16)
MI_SetMenuItemBitmap("EditMenu", 4, hBitmap)
Menu, EditMenu, Add, Edit IP List on J:\, c
hBitmap := ExtractIcontohBitmap(A_ProgramFiles "\AutoHotkey\SciTE\SciTE.exe", 1, 16)
MI_SetMenuItemBitmap("EditMenu", 5, hBitmap)
MI_SetMenuStyle("EditMenu", 0x4000000)
;===========================Add BackUp Menu,icons ==========================
Menu, BackUpMenu, Add, Back Up VNCGUI on J:\, c
hBitmap := ExtractIcontohBitmap("shell32.dll", 69, 16)
MI_SetMenuItemBitmap("BackUpMenu", 1, hBitmap)
Menu, BackUpMenu, Add, Back Up VNCGUI Directory, c
hBitmap := ExtractIcontohBitmap("shell32.dll", 69, 16)
MI_SetMenuItemBitmap("BackUpMenu", 2, hBitmap)
MI_SetMenuStyle("BackUpMenu", 0x4000000)
;===========================Add Help Menu,icons ==========================
Menu, HelpMenu, Add, Client List Help, c
hBitmap := ExtractIcontohBitmap(A_WinDir "\hh.exe", 1, 16)
MI_SetMenuItemBitmap("HelpMenu", 1, hBitmap)
Menu, HelpMenu, Add, Script Help, c
hBitmap := ExtractIcontohBitmap(A_WinDir "\hh.exe", 1, 16)
MI_SetMenuItemBitmap("HelpMenu", 2, hBitmap)
MI_SetMenuStyle("HelpMenu", 0x4000000)
;===========================Add About Menu,icons==========================
Menu, AboutMenu, Add, About, c
hBitmap := ExtractIcontohBitmap("shell32.dll", 24, 16)
MI_SetMenuItemBitmap("AboutMenu", 1, hBitmap)
;MI_SetMenuItemIcon("AboutMenu", 1, "shell32.dll", 24, 16)
MI_SetMenuStyle("AboutMenu", 0x4000000)
;======================Attach the sub-menus that were created above===================
Menu, MyMenuBar, Add, File, :FileMenu
Menu, MyMenuBar, Add, Edit, :EditMenu
Menu, MyMenuBar, Add, Back Up, :BackUpMenu
Menu, MyMenuBar, Add, Help, :HelpMenu
Menu, MyMenuBar, Add, About, :AboutMenu
Gui, Menu, MyMenuBar
;======================Show Main Gui ===================
Gui +OwnDialogs +LastFound
WinTitle = Real VNC %A_ComputerName% -- %A_IPAddress1%
Gui, Show, w200 h200, %WinTitle%
MainWin := WinExist()
Return
;============Button Handler=======================
;=================================================
ButtonVNCViewer:
MsgBox, Button Label Worked!!!!
Return
c:
MsgBox, %A_ThisMenu%`n%A_ThisMenuItem%`n%A_ThisMenuItemPos%
Return
ExtractIcon(Filename, IconNumber, IconSize=0)
{
static SmallIconSize, LargeIconSize
if (!SmallIconSize) {
SysGet, SmallIconSize, 49 ; 49, 50 SM_CXSMICON, SM_CYSMICON
SysGet, LargeIconSize, 11 ; 11, 12 SM_CXICON, SM_CYICON
}
VarSetCapacity(phicon, 4, 0)
h_icon = 0
; If possible, use PrivateExtractIcons, which supports any size of icon.
if A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
{
VarSetCapacity(piconid, 4, 0)
; MSDN: "... this function is deprecated ..." (oh well)
ret := DllCall("PrivateExtractIcons"
, "str", Filename
, "int", IconNumber-1 ; zero-based index of the first icon to extract
, "int", IconSize
, "int", IconSize
, "str", phicon ; pointer to an array of icon handles...
, "str", piconid ; piconid - won't be used
, "uint", 1 ; nIcons - number of icons to extract
, "uint", 0, "uint") ; flags
if (ret && ret != 0xFFFFFFFF)
h_icon := NumGet(phicon)
}
else
{ ; Use ExtractIconEx, which only returns 16x16 or 32x32 icons.
VarSetCapacity(phiconSmall, 4, 0)
; Extract the icon from an executable, DLL or icon file.
if DllCall("shell32.dll\ExtractIconExA"
, "str", Filename
, "int", IconNumber-1 ; zero-based index of the first icon to extract
, "str", phicon ; pointer to an array of icon handles...
, "str", phiconSmall
, "uint", 1)
{
; Use the best-fit size; clean up the other.
if (IconSize <= SmallIconSize) {
DllCall("DestroyIcon", "uint", NumGet(phicon))
h_icon := NumGet(phiconSmall)
} else {
DllCall("DestroyIcon", "uint", NumGet(phiconSmall))
h_icon := NumGet(phicon)
}
}
}
return h_icon
}
ExtractIcontohBitmap(FileName, IconNumber, IconSize){
hIcon := ExtractIcon(Filename, IconNumber, IconSize)
If !hIcon
{
MsgBox, Icon doesn't exist.`nFileName = %FileName%`nIconNumber = %IconNumber%
Return 0
}
pBitmap := Gdip_CreateBitmapFromHICON(hIcon)
If !pBitmap
{
MsgBox, pBitmap doesn't exist.`nFileName = %FileName%`nIconNumber = %IconNumber%
Return 0
}
hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
If !pBitmap
{
MsgBox, hBitmap doesn't exist.`nFileName = %FileName%`nIconNumber = %IconNumber%
Return 0
}
Else
Return hBitmap
}
#Include GDIP.ahk
#Include MI.ahk
;Exits Apllication
GUIClose:
ExitApp
Hope this helps someone else.