Advertisement
Guest User

Untitled

a guest
Jul 18th, 2008
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 112.05 KB | None | 0 0
  1. ;********************************************************************
  2. ; ModernMenu UDF by Holger Kotsch
  3. ; Version-date: 06.05.2008
  4. ;********************************************************************
  5.  
  6. #include-once
  7.  
  8. Global $sLOGFONT                        =    "int;" & _ ; Height
  9.                                             "int;" & _ ; Average width
  10.                                             "int;" & _ ; Excapement
  11.                                             "int;" & _ ; Orientation
  12.                                             "int;" & _ ; Weight
  13.                                             "byte;" & _ ; Italic
  14.                                             "byte;" & _ ; Underline
  15.                                             "byte;" & _ ; Strikeout
  16.                                             "byte;" & _ ; Charset
  17.                                             "byte;" & _ ; Outprecision
  18.                                             "byte;" & _ ; Clipprecision
  19.                                             "byte;" & _ ; Quality
  20.                                             "byte;" & _ ; Pitch & Family
  21.                                             "wchar[32]" ; Font name
  22.                                                
  23. Global Const $sNONCLIENTMETRICS            =    "uint;" & _ ; Struct size
  24.                                             "int;" & _ ;
  25.                                             "int;" & _ ;
  26.                                             "int;" & _ ;
  27.                                             "int;" & _ ;
  28.                                             "int;" & _ ;
  29.                                             $sLOGFONT & ";" & _ ; Caption LogFont structure
  30.                                             "int;" & _ ;
  31.                                             "int;" & _ ;
  32.                                             $sLOGFONT & ";" & _ ; Small caption LogFont structure
  33.                                             "int;" & _ ;
  34.                                             "int;" & _ ;
  35.                                             $sLOGFONT & ";" & _ ; Menu LogFont structure
  36.                                             $sLOGFONT & ";" & _ ; Statusbar LogFont structure
  37.                                             $sLOGFONT ; Message box LogFont structure
  38.  
  39.  
  40. Global Const $sMENUITEMINFO                =    "uint;" & _ ;
  41.                                             "uint;" & _ ;
  42.                                             "uint;" & _ ;
  43.                                             "uint;" & _ ;
  44.                                             "uint;" & _ ;
  45.                                             "hwnd;" & _ ;
  46.                                             "hwnd;" & _ ;
  47.                                             "hwnd;" & _ ;
  48.                                             "long;" & _ ;
  49.                                             "ptr;" & _ ;
  50.                                             "uint;" & _ ;
  51.                                             "hwnd"
  52.  
  53.  
  54. ;**********************************************************************
  55. ; NotifyIconData struct
  56. ;**********************************************************************
  57. Global $sNOTIFYICONDATAW                    =    "dword;" & _ ; Struct size
  58.                                                 "hwnd;" & _ ; Callback window handle
  59.                                                 "uint;" & _ ; Icon ID
  60.                                                 "uint;" & _ ; Flags
  61.                                                 "uint;" & _ ; Callback message ID
  62.                                                 "hwnd;" ; Icon handle
  63.  
  64. Switch @OSVersion
  65.     Case "WIN_95", "WIN_98", "WIN_NT4"
  66.         $sNOTIFYICONDATAW &= "wchar[64]" ; ToolTip text
  67.        
  68.     Case Else
  69.         $sNOTIFYICONDATAW &= "wchar[128];" & _ ; ToolTip text
  70.                             "dword;" & _ ; Icon state
  71.                             "dword;" & _ ; Icon state mask
  72.                             "wchar[256];" & _ ; Balloon ToolTip text
  73.                             "uint;" & _ ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
  74.                             "wchar[64];" & _ ; Balloon ToolTip title text
  75.                             "dword" ; Balloon ToolTip info flags
  76. EndSwitch
  77.  
  78.  
  79. ;**********************************************************************
  80. ; Notify icon constants
  81. ;**********************************************************************
  82. If Not IsDeclared("NIN_SELECT")                Then Global Const $NIN_SELECT = 0x0400
  83. If Not IsDeclared("NINF_KEY")                Then Global Const $NINF_KEY = 0x1
  84. If Not IsDeclared("NIN_KEYSELECT")            Then Global Const $NIN_KEYSELECT = BitOr($NIN_SELECT, $NINF_KEY)
  85. If Not IsDeclared("NIN_BALLOONSHOW")        Then Global Const $NIN_BALLOONSHOW = 0x0400 + 2
  86. If Not IsDeclared("NIN_BALLOONHIDE")        Then Global Const $NIN_BALLOONHIDE = 0x0400 + 3
  87. If Not IsDeclared("NIN_BALLOONTIMEOUT")        Then Global Const $NIN_BALLOONTIMEOUT = 0x0400 + 4
  88. If Not IsDeclared("NIN_BALLOONUSERCLICK")    Then Global Const $NIN_BALLOONUSERCLICK = 0x0400 + 5
  89. If Not IsDeclared("NIN_POPUPOPEN")            Then Global Const $NIN_POPUPOPEN = 0x0400 + 6
  90. If Not IsDeclared("NIN_POPUPCLOSE")            Then Global Const $NIN_POPUPCLOSE = 0x0400 + 7
  91.  
  92. If Not IsDeclared("NIM_ADD")                Then Global Const $NIM_ADD = 0x00000000
  93. If Not IsDeclared("NIM_MODIFY")                Then Global Const $NIM_MODIFY = 0x00000001
  94. If Not IsDeclared("NIM_DELETE")                Then Global Const $NIM_DELETE = 0x00000002
  95. If Not IsDeclared("NIM_SETFOCUS")            Then Global Const $NIM_SETFOCUS = 0x00000003
  96. If Not IsDeclared("NIM_SETVERSION")            Then Global Const $NIM_SETVERSION = 0x00000004
  97.  
  98. If Not IsDeclared("NIF_MESSAGE")            Then Global Const $NIF_MESSAGE = 0x00000001
  99. If Not IsDeclared("NIF_ICON")                Then Global Const $NIF_ICON = 0x00000002
  100. If Not IsDeclared("NIF_TIP")                Then Global Const $NIF_TIP = 0x00000004
  101. If Not IsDeclared("NIF_STATE")                Then Global Const $NIF_STATE = 0x00000008
  102. If Not IsDeclared("NIF_INFO")                Then Global Const $NIF_INFO = 0x00000010
  103. If Not IsDeclared("NIF_REALTIME")            Then Global Const $NIF_REALTIME = 0x00000040
  104. If Not IsDeclared("NIF_SHOWTIP")            Then Global Const $NIF_SHOWTIP = 0x00000080
  105.  
  106. If Not IsDeclared("NIS_HIDDEN")                Then Global Const $NIS_HIDDEN = 0x00000001
  107. If Not IsDeclared("NIS_SHAREDICON")            Then Global Const $NIS_SHAREDICON = 0x00000002
  108.  
  109. If Not IsDeclared("NIIF_NONE")                Then Global Const $NIIF_NONE = 0x00000000
  110. If Not IsDeclared("NIIF_INFO")                Then Global Const $NIIF_INFO = 0x00000001
  111. If Not IsDeclared("NIIF_WARNING")            Then Global Const $NIIF_WARNING = 0x00000002
  112. If Not IsDeclared("NIIF_ERROR")                Then Global Const $NIIF_ERROR = 0x00000003
  113. If Not IsDeclared("NIIF_USER")                Then Global Const $NIIF_USER = 0x00000004
  114. If Not IsDeclared("NIIF_ICON_MASK")            Then Global Const $NIIF_ICON_MASK = 0x0000000F
  115. If Not IsDeclared("NIIF_NOSOUND")            Then Global Const $NIIF_NOSOUND = 0x00000010
  116. If Not IsDeclared("NIIF_LARGE_ICON")        Then Global Const $NIIF_LARGE_ICON = 0x00000020
  117.  
  118.  
  119. ;**********************************************************************
  120. ; Constants for LoadIcon()
  121. ;**********************************************************************
  122. If Not IsDeclared("IDI_APPLICATION")        Then Global Const $IDI_APPLICATION = 32512
  123. If Not IsDeclared("IDI_HAND")                Then Global Const $IDI_HAND = 32513
  124. If Not IsDeclared("IDI_QUESTION")            Then Global Const $IDI_QUESTION = 32514
  125. If Not IsDeclared("IDI_EXCLAMATION")        Then Global Const $IDI_EXCLAMATION = 32515
  126. If Not IsDeclared("IDI_ASTERISK")            Then Global Const $IDI_ASTERISK = 32516
  127. If Not IsDeclared("IDI_WINLOGO")            Then Global Const $IDI_WINLOGO = 32517
  128.  
  129.  
  130. ;**********************************************************************
  131. ; Mouse constants
  132. ;**********************************************************************
  133. If Not IsDeclared("WM_MOUSEMOVE")            Then Global Const $WM_MOUSEMOVE = 0x0200
  134. If Not IsDeclared("WM_LBUTTONDOWN")            Then Global Const $WM_LBUTTONDOWN = 0x0201
  135. If Not IsDeclared("WM_LBUTTONUP")            Then Global Const $WM_LBUTTONUP = 0x0202
  136. If Not IsDeclared("WM_LBUTTONDBLCLK")        Then Global Const $WM_LBUTTONDBLCLK = 0x0203
  137. If Not IsDeclared("WM_RBUTTONDOWN")            Then Global Const $WM_RBUTTONDOWN = 0x0204
  138. If Not IsDeclared("WM_RBUTTONUP")            Then Global Const $WM_RBUTTONUP = 0x0205
  139. If Not IsDeclared("WM_RBUTTONDBLCLK")        Then Global Const $WM_RBUTTONDBLCLK = 0x0206
  140. If Not IsDeclared("WM_MBUTTONDOWN")            Then Global Const $WM_MBUTTONDOWN = 0x0207
  141. If Not IsDeclared("WM_MBUTTONUP")            Then Global Const $WM_MBUTTONUP = 0x0208
  142. If Not IsDeclared("WM_MBUTTONDBLCLK")        Then Global Const $WM_MBUTTONDBLCLK = 0x0209
  143.  
  144.                                                
  145. ;********************************************************************
  146. ; Main Creation Part
  147. ;********************************************************************
  148. Global $hComctl32Dll                = DllOpen("comctl32.dll")
  149. Global $hGdi32Dll                    = DllOpen("gdi32.dll")
  150. Global $hKernel32Dll                = DllOpen("kernel32.dll")
  151. Global $hShell32Dll                    = DllOpen("shell32.dll")
  152. Global $hUser32Dll                    = DllOpen("user32.dll")
  153. Global $hMsimg32Dll                    = DllOpen("msimg32.dll")
  154.  
  155.  
  156. Global $bUseAdvMenu                    = TRUE
  157. Global $bUseAdvTrayMenu                = TRUE
  158. Global $bUseRGBColors                = FALSE
  159.  
  160. ; Set default color values if not given
  161. Global $nMenuBkClr                    = 0xFFFFFF
  162. Global $nMenuIconBkClr                = 0xDBD8D8
  163. Global $nMenuSelectBkClr            = 0xD2BDB6
  164. Global $nMenuSelectRectClr            = 0x854240
  165. Global $nMenuSelectTextClr            = 0x000000
  166. Global $nMenuTextClr                = 0x000000
  167. Global $nMenuSideBkClr                = 0xD00000
  168. Global $nMenuSideTxtClr                = 0xFFFFFF
  169.  
  170. Global $nTrayBkClr                    = 0xFFFFFF
  171. Global $nTrayIconBkClr                = 0xD1D8DB
  172. Global $nTraySelectBkClr            = 0xD2BDB6
  173. Global $nTraySelectRectClr            = 0x854240
  174. Global $nTraySelectTextClr            = 0x000000
  175. Global $nTrayTextClr                = 0x000000
  176.  
  177. If $bUseRGBColors Then
  178.     $nMenuIconBkClr                    = 0xD8D8DB
  179.     $nMenuSelectBkClr                = 0xB6BDD2
  180.     $nMenuSelectRectClr                = 0x404285
  181.     $nMenuSideBkClr                    = 0x0000D0
  182.    
  183.     $nTrayIconBkClr                    = 0xDBD8D1
  184.     $nTraySelectBkClr                = 0xB6BDD2
  185.     $nTraySelectRectClr                = 0x404285
  186. EndIf
  187.  
  188. Global $nMenuIconBkClr2                = $nMenuIconBkClr
  189. Global $nMenuSideBkClr2                = $nMenuSideBkClr
  190. Global $nTrayIconBkClr2                = $nTrayIconBkClr
  191.  
  192.  
  193. ; Store here the menu item:
  194. ; ID/Text/IconIndex/ParentMenu/Tray/SelIconIndex/IsMenu
  195. Global $arMenuItems[1][8]
  196. $arMenuItems[0][0] = 0
  197. Global $nMenuItemsRedim                = 10
  198.  
  199. ; Store here the side item:
  200. ; MenuHandle/Text/TextColor/BkColor/GradientColor/IsBitmap/BitmapHandle/Width/Height/Stretch
  201. Global $arSideItems[1][10]
  202. $arSideItems[0][0] = 0
  203.  
  204. ; Create a usable font for using in ownerdrawn menus
  205. Global $hMenuFont                    = 0
  206. _CreateMenuFont($hMenuFont)
  207.  
  208. ; Create an image list for saving/drawing our menu icons
  209. Global $hMenuImageList    = ImageList_Create(16, 16, BitOr(0x0001, 0x0020), 0, 1)
  210.  
  211. Global $hBlankIcon                    = 0
  212.  
  213. ; Store here the tray icon:
  214. ; NotifyID/TrayIcon/Menu/Click/ToolTip/Callback/OnlyMsg/Flash/FlashBlank
  215. Global $TRAYNOTIFYIDS[1][9]
  216. $TRAYNOTIFYIDS[0][0] = 0
  217. Global $TRAYMSGWND                    = 0
  218. Global $TRAYNOTIFYID                = -1
  219. Global $TRAYLASTID                    = -1
  220. Global $MENULASTITEM                = -1
  221. Global $TRAYLASTITEM                = -1
  222. Global $TRAYLASTMENU                = -1
  223. Global $TRAYTIPMSG                    = 0x0400 + 1 ; This message ID will be used in a GUIRegisterMsg() procdure
  224. Global $FLASHTIMERID                = 3
  225. Global $FLASHTIMEOUT                = 750
  226. Global $sDefaultTT                    = "AutoIt - " & @ScriptName
  227.  
  228. GUIRegisterMsg(0x002B, "WM_DRAWITEM")
  229. GUIRegisterMsg(0x002C, "WM_MEASUREITEM")
  230. GUIRegisterMsg($TRAYTIPMSG, "_TrayWndProc")
  231. GUIRegisterMsg(0x001A, "WM_SETTINGCHANGE")
  232. GUIRegisterMsg(0x0113, "WM_TIMER")
  233.  
  234. ; Cleanup
  235. Func OnAutoItExit()
  236.     For $i = 0 To UBound($TRAYNOTIFYIDS)-1
  237.         _TrayIconDelete($TRAYNOTIFYIDS[ $i ][0])
  238.     Next
  239.     ImageList_Destroy($hMenuImageList)
  240.     DeleteObject($hMenuFont)
  241.    
  242.     For $i = 1 To $arSideItems[0][0]
  243.         If $arSideItems[$i][6] <> 0 Then _
  244.             DeleteObject($arSideItems[$i][6])
  245.     Next
  246.    
  247.     DllClose($hComctl32Dll)
  248.     DllClose($hGdi32Dll)
  249.     DllClose($hKernel32Dll)
  250.     DllClose($hShell32Dll)
  251.     DllClose($hUser32Dll)
  252.     DllClose($hMsimg32Dll)
  253.    
  254.     $arMenuItems    = 0
  255.     $arSideItems    = 0
  256.     $TRAYNOTIFYIDS    = 0
  257. EndFunc
  258.  
  259.  
  260. ;********************************************************************
  261. ; Define the colors for the menu/selection bar
  262. ;********************************************************************
  263. Func _SetMenuBkColor($nColor)
  264.     $nMenuBkClr                = _GetBGRColor($nColor)
  265. EndFunc
  266.  
  267. Func _SetMenuIconBkColor($nColor)
  268.     $nMenuIconBkClr            = _GetBGRColor($nColor)
  269.     $nMenuIconBkClr2        = $nMenuIconBkClr
  270. EndFunc
  271.  
  272. Func _SetMenuIconBkGrdColor($nColor)
  273.     $nMenuIconBkClr2        = _GetBGRColor($nColor)
  274. EndFunc
  275.  
  276. Func _SetMenuSelectBkColor($nColor)
  277.     $nMenuSelectBkClr        = _GetBGRColor($nColor)
  278. EndFunc
  279.  
  280. Func _SetMenuSelectRectColor($nColor)
  281.     $nMenuSelectRectClr        = _GetBGRColor($nColor)
  282. EndFunc
  283.  
  284. Func _SetMenuSelectTextColor($nColor)
  285.     $nMenuSelectTextClr        = _GetBGRColor($nColor)
  286. EndFunc
  287.  
  288. Func _SetMenuTextColor($nColor)
  289.     $nMenuTextClr            = _GetBGRColor($nColor)
  290. EndFunc
  291.  
  292. Func _SetTrayBkColor($nColor)
  293.     $nTrayBkClr                = _GetBGRColor($nColor)
  294. EndFunc
  295.  
  296. Func _SetTrayIconBkColor($nColor)
  297.     $nTrayIconBkClr            = _GetBGRColor($nColor)
  298.     $nTrayIconBkClr2        = $nMenuIconBkClr
  299. EndFunc
  300.  
  301. Func _SetTrayIconBkGrdColor($nColor)
  302.     $nTrayIconBkClr2        = _GetBGRColor($nColor)
  303. EndFunc
  304.  
  305. Func _SetTraySelectBkColor($nColor)
  306.     $nTraySelectBkClr        = _GetBGRColor($nColor)
  307. EndFunc
  308.  
  309. Func _SetTraySelectRectColor($nColor)
  310.     $nTraySelectRectClr        = _GetBGRColor($nColor)
  311. EndFunc
  312.  
  313. Func _SetTraySelectTextColor($nColor)
  314.     $nTraySelectTextClr        = _GetBGRColor($nColor)
  315. EndFunc
  316.  
  317. Func _SetTrayTextColor($nColor)
  318.     $nTrayTextClr            = _GetBGRColor($nColor)
  319. EndFunc
  320.  
  321. Func _SetSideMenuColor($nIdx, $nColor = -2)
  322.     Return _SetSideMenuColors($nIdx, _GetBGRColor($nColor))
  323. EndFunc
  324.  
  325. Func _SetSideMenuBkColor($nIdx, $nColor = -2)
  326.     Return _SetSideMenuColors($nIdx, -1, _GetBGRColor($nColor))
  327. EndFunc
  328.  
  329. Func _SetSideMenuBkGradColor($nIdx, $nColor = -2)
  330.     Return _SetSideMenuColors($nIdx, -1, -1, _GetBGRColor($nColor))
  331. EndFunc
  332.  
  333. Func _SetFlashTimeOut($nTime = 750)
  334.     $FLASHTIMEOUT = $nTime
  335.     If $FLASHTIMEOUT < 50 Then $FLASHTIMEOUT = 50
  336. EndFunc
  337.  
  338.  
  339. ;**********************************************************************
  340. ; Return an BGR color to a given RGB color
  341. ;**********************************************************************
  342. Func _GetBGRColor($nColor)
  343.     If $bUseRGBColors And $nColor <> -2 Then
  344.         Return BitOr(BitShift(BitAnd($nColor, 0xFF), -16), BitAnd($nColor, 0xFF00), BitShift($nColor, 16))
  345.     Else
  346.         Return $nColor
  347.     EndIf
  348. EndFunc
  349.  
  350.  
  351. ;**********************************************************************
  352. ; Get the icon ID like in newer Autoit versions
  353. ;**********************************************************************
  354. Func _GetIconID($nID, $sFile)
  355.     If StringRight($sFile, 4) = ".exe" Then
  356.         If $nID < 0 Then
  357.             $nID = - ($nID + 1)
  358.         ElseIf $nID > 0 Then
  359.             $nID = - $nID
  360.         EndIf
  361.     ElseIf StringRight($sFile, 4) = ".icl" And $nID < 0 Then
  362.         $nID = - ($nID + 1)
  363.     Else
  364.         If $nID > 0 Then
  365.             $nID = - $nID
  366.         ElseIf $nID < 0 Then
  367.             $nID = - ($nID + 1)
  368.         EndIf
  369.     EndIf
  370.        
  371.     Return $nID
  372. EndFunc
  373.  
  374.  
  375. ;**********************************************************************
  376. ; Main functions:
  377. ;**********************************************************************
  378. Func _TrayWndProc($hWnd, $Msg, $wParam, $lParam)
  379.     If $hWnd = $TRAYMSGWND Then
  380.         _TrayNotifyIcon($hWnd, $Msg, $wParam, $lParam)
  381.     EndIf
  382. EndFunc
  383.  
  384.  
  385. Func _TrayNotifyIcon($hWnd, $Msg, $wParam, $lParam)
  386.     Local $nClick = 0
  387.     Local $nID = $wParam
  388.    
  389.     If $TRAYNOTIFYIDS[$nID][5] <> "" And _
  390.         ($TRAYNOTIFYIDS[$nID][6] = 0 Or _
  391.         $TRAYNOTIFYIDS[$nID][6] = $lParam) Then
  392.         Call($TRAYNOTIFYIDS[$nID][5], $nID, $lParam)
  393.     EndIf
  394.    
  395.     Switch $lParam
  396.         Case $WM_LBUTTONDOWN
  397.             $nClick = 1
  398.         case $WM_LBUTTONUP
  399.             $nClick = 2
  400.         case $WM_LBUTTONDBLCLK
  401.             $nClick = 4
  402.         case $WM_RBUTTONDOWN
  403.             $nClick = 8
  404.         case $WM_RBUTTONUP
  405.             $nClick = 16
  406.         case $WM_RBUTTONDBLCLK
  407.             $nClick = 32
  408.         case $WM_MOUSEMOVE
  409.             $nClick = 64
  410.     EndSwitch
  411.  
  412.     If BitAnd($nClick, $TRAYNOTIFYIDS[$nID][3]) And $TRAYNOTIFYIDS[$nID][2] > 0 Then
  413.         Local $hMenu = GUICtrlGetHandle($TRAYNOTIFYIDS[$nID][2])
  414.         If $hMenu <> 0 Then
  415.             Local $stPoint = DllStructCreate("int;int")
  416.             GetCursorPos(DllStructGetPtr($stPoint))
  417.            
  418.             SetForegroundWindow($hWnd)
  419.        
  420.             TrackPopupMenuEx($hMenu, 0, DllStructGetData($stPoint, 1), DllStructGetData($stPoint, 2), $hWnd, 0)
  421.                            
  422.             PostMessage($hWnd, 0, 0, 0)
  423.         EndIf
  424.     EndIf
  425. EndFunc
  426.  
  427.  
  428. ;**********************************************************************
  429. ; Create a new tray notify ID
  430. ;**********************************************************************
  431. Func _GetNewTrayIndex()
  432.     Local $i, $bFreeFound = FALSE
  433.    
  434.     For $i = 1 To $TRAYNOTIFYIDS[0][0]
  435.         If $TRAYNOTIFYIDS[$i][0] = 0 Then
  436.             $bFreeFound = TRUE
  437.             ExitLoop
  438.         EndIf
  439.     Next
  440.    
  441.     If Not $bFreeFound Then
  442.         $TRAYNOTIFYIDS[0][0] += 1
  443.         Local $nSize = UBound($TRAYNOTIFYIDS)
  444.  
  445.         If $TRAYNOTIFYIDS[0][0] > $nSize - 10 Then _
  446.             Redim $TRAYNOTIFYIDS[$nSize + 10][9]
  447.         $i = $TRAYNOTIFYIDS[0][0]
  448.     EndIf
  449.    
  450.     Return $i
  451. EndFunc
  452.  
  453.  
  454. ;**********************************************************************
  455. ; Check for existing tray notify ID
  456. ;**********************************************************************
  457. Func _GetTrayNotifyIdx($nID)
  458.     If $TRAYMSGWND = 0 Then Return 0
  459.    
  460.     Local $i, $nResult = 0
  461.  
  462.     If $nID = -1 Then $nID = $TRAYLASTID
  463.    
  464.     For $i = 1 To $TRAYNOTIFYIDS[0][0]
  465.         If $TRAYNOTIFYIDS[$i][0] = $nID Then
  466.             $nResult = $i
  467.             ExitLoop
  468.         EndIf
  469.     Next
  470.  
  471.     Return $nResult
  472. EndFunc
  473.  
  474.  
  475. ;********************************************************************
  476. ; Change the menu item icon
  477. ;********************************************************************
  478. Func _TrayItemSetIcon($nMenuID, $sIconFile = "", $nIconID = -1)
  479.     If $nMenuID = -1 Then $nMenuID = $TRAYLASTITEM
  480.     If $nMenuID <= 0 Then Return 0
  481.    
  482.     $nIconID = _GetIconID($nIconID, $sIconFile)
  483.    
  484.     Local $i, $sText = "", $hMenu = 0
  485.    
  486.     For $i = 1 To $arMenuItems[0][0]
  487.         If $arMenuItems[$i][0] = $nMenuID Then
  488.             $sText = $arMenuItems[$i][1]
  489.             $hMenu = $arMenuItems[$i][3]
  490.            
  491.             If $sIconFile = "" And $nIconID = -1 Then
  492.                 $arMenuItems[$i][2] = -1
  493.                
  494.                 _SetOwnerDrawn($hMenu, $nMenuID, $sText, FALSE)
  495.                 GUICtrlSetData($nMenuID, $sText)
  496.             Else
  497.                 If $sIconFile <> "" Then
  498.                     $arMenuItems[$i][2] = _AddMenuIcon($sIconFile, $nIconID)
  499.                 Else
  500.                     $arMenuItems[$i][2] = -1
  501.                 EndIf
  502.                
  503.                 _SetOwnerDrawn($hMenu, $nMenuID, $sText)
  504.             EndIf
  505.            
  506.             Return 1
  507.         EndIf
  508.     Next
  509.    
  510.     Return 0
  511. EndFunc
  512.  
  513.  
  514. ;********************************************************************
  515. ; Set the selected menu item icon
  516. ;********************************************************************
  517. Func _TrayItemSetSelIcon($nMenuID, $sIconFile = "", $nIconID = -1)
  518.     If $nMenuID = -1 Then $nMenuID = $TRAYLASTITEM
  519.     If $nMenuID <= 0 Then Return 0
  520.    
  521.     $nIconID = _GetIconID($nIconID, $sIconFile)
  522.    
  523.     Local $i, $sText = "", $hMenu = 0
  524.    
  525.     For $i = 1 To $arMenuItems[0][0]
  526.         If $arMenuItems[$i][0] = $nMenuID Then
  527.             $sText = $arMenuItems[$i][1]
  528.             $hMenu = $arMenuItems[$i][3]
  529.            
  530.             If $sIconFile = "" And $nIconID = -1 Then
  531.                 $arMenuItems[$i][6] = -1
  532.                
  533.                 _SetOwnerDrawn($hMenu, $nMenuID, $sText, FALSE)
  534.                 GUICtrlSetData($nMenuID, $sText)
  535.             Else
  536.                 If $sIconFile <> "" Then
  537.                     $arMenuItems[$i][6] = _AddMenuIcon($sIconFile, $nIconID)
  538.                 Else
  539.                     $arMenuItems[$i][6] = -1
  540.                 EndIf
  541.                
  542.                 _SetOwnerDrawn($hMenu, $nMenuID, $sText)
  543.             EndIf
  544.            
  545.             Return 1
  546.         EndIf
  547.     Next
  548.    
  549.     Return 0
  550. EndFunc
  551.  
  552.  
  553. ;********************************************************************
  554. ; Set the text of an menu item
  555. ;********************************************************************
  556. Func _TrayItemSetText($nMenuID = -1, $sText = "")
  557.     If $nMenuID = -1 Then $nMenuID = $TRAYLASTITEM
  558.     If $nMenuID <= 0 Then Return 0
  559.    
  560.     Local $i
  561.    
  562.     For $i = 1 To $arMenuItems[0][0]
  563.         If $arMenuItems[$i][0] = $nMenuID Then
  564.             $arMenuItems[$i][1] = $sText
  565.             ;_SetOwnerDrawn($arMenuItems[$i][3], $nMenuID, $sText, FALSE)
  566.             GUICtrlSetData($nMenuID, $sText)
  567.             ;_SetOwnerDrawn($arMenuItems[$i][3], $nMenuID, $sText)
  568.             Return 1
  569.         EndIf
  570.     Next
  571.    
  572.     Return 0
  573. EndFunc
  574.  
  575.  
  576. ;**********************************************************************
  577. ; _TrayIconCreate([ToolTip [, IconFile [, IconID]]])
  578. ;**********************************************************************
  579. Func _TrayIconCreate($sToolTip = "", $sIconFile = @AutoItExe, $nIconID = 0, $sCallback = "", $nMsg = 0, $hIcon = 0)
  580.     If $sToolTip = "" Then $sToolTip = $sDefaultTT
  581.    
  582.     $nIconID = _GetIconID($nIconID, $sIconFile)
  583.    
  584.     If $sIconFile = "" Then
  585.         If $hIcon = 0 Then
  586.             If $nIconID = 0 Then
  587.                 $sIconFile = @AutoItExe
  588.             Else
  589.                 $hIcon = LoadIcon(0, $nIconID)
  590.             EndIf
  591.         EndIf
  592.     EndIf
  593.    
  594.     If $sIconFile <> "" Then
  595.         Local $stIcon = DllStructCreate("hwnd")
  596.        
  597.         If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
  598.             $hIcon = DllStructGetData($stIcon, 1)
  599.         Else
  600.             $hIcon = LoadIcon(0, 32516)
  601.         EndIf
  602.     EndIf
  603.    
  604.     If $TRAYMSGWND = 0 Then
  605.         $TRAYMSGWND = GUICreate("", 1, 1, 9999, 9999, -1, 0x00000080)
  606.         GUISetState()
  607.         ShowWindow($TRAYMSGWND, @SW_HIDE)
  608.     EndIf
  609.    
  610.     Local $nNID = _GetNewTrayIndex()
  611.     If $nNID = 0 Then
  612.         DestroyIcon($hIcon)
  613.         Return 0
  614.     EndIf
  615.    
  616.     $TRAYNOTIFYIDS[$nNID][0] = $nNID
  617.     $TRAYNOTIFYIDS[$nNID][1] = $hIcon
  618.     $TRAYNOTIFYIDS[$nNID][2] = 0
  619.     $TRAYNOTIFYIDS[$nNID][3] = 9
  620.     $TRAYNOTIFYIDS[$nNID][4] = $sToolTip
  621.     $TRAYNOTIFYIDS[$nNID][5] = $sCallback
  622.     $TRAYNOTIFYIDS[$nNID][6] = $nMsg
  623.     $TRAYNOTIFYIDS[$nNID][7] = FALSE
  624.     $TRAYNOTIFYIDS[$nNID][8] = FALSE
  625.    
  626.     $TRAYLASTID = $nNID
  627.    
  628.     Return $nNID
  629. EndFunc
  630.  
  631.  
  632. ;**********************************************************************
  633. ; _TrayIconDelete($NotificationID)
  634. ;**********************************************************************
  635. Func _TrayIconDelete($nID)
  636.     If $nID = -1 Then $nID = $TRAYLASTID
  637.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  638.    
  639.     Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
  640.    
  641.     DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  642.     DllStructSetData($stNID, 2, $TRAYMSGWND)
  643.     DllStructSetData($stNID, 3, $nID)
  644.    
  645.     Local $nResult = 0
  646.  
  647.     Local $i
  648.     For $i = 1 To $TRAYNOTIFYIDS[0][0]
  649.         If $nID = $TRAYNOTIFYIDS[$i][0] Then
  650.             Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
  651.    
  652.             DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  653.             DllStructSetData($stNID, 2, $TRAYMSGWND)
  654.             DllStructSetData($stNID, 3, $nID)
  655.    
  656.             $nResult = Shell_NotifyIcon($NIM_DELETE, DllStructGetPtr($stNID))
  657.            
  658.             DestroyIcon($TRAYNOTIFYIDS[$i][1])
  659.             $TRAYNOTIFYIDS[$i][8] = FALSE
  660.             $TRAYNOTIFYIDS[$i][7] = FALSE
  661.             $TRAYNOTIFYIDS[$i][6] = 0
  662.             $TRAYNOTIFYIDS[$i][5] = ""
  663.             $TRAYNOTIFYIDS[$i][4] = ""
  664.             $TRAYNOTIFYIDS[$i][3] = 0
  665.            
  666.             If $TRAYNOTIFYIDS[$i][2] <> 0 Then GUIDelete($TRAYNOTIFYIDS[$i][2])
  667.            
  668.             $TRAYNOTIFYIDS[$i][2] = 0
  669.             $TRAYNOTIFYIDS[$i][1] = 0
  670.             $TRAYNOTIFYIDS[$i][0] = 0
  671.            
  672.             ExitLoop
  673.         EndIf
  674.     Next
  675.    
  676.     Return $nResult
  677. EndFunc
  678.  
  679.  
  680. ;**********************************************************************
  681. ; _TrayIconSetState($NotificationID, $NewState)
  682. ;**********************************************************************
  683. Func _TrayIconSetState($nID = -1, $nState = 1)
  684.     If $nState = 0 Then Return 1 ; No change
  685.    
  686.     If $nID = -1 Then $nID = $TRAYLASTID
  687.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  688.    
  689.     Local $i, $nResult = 0, $bFound = FALSE
  690.    
  691.     For $i = 1 To $TRAYNOTIFYIDS[0][0]
  692.         If $nID = $TRAYNOTIFYIDS[$i][0] Then
  693.             $bFound = TRUE
  694.             ExitLoop
  695.         EndIf
  696.     Next
  697.    
  698.     If Not $bFound Then Return 0
  699.    
  700.     Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
  701.    
  702.     If BitAnd($nState, 1) Then
  703.         DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  704.         DllStructSetData($stNID, 2, $TRAYMSGWND)
  705.         DllStructSetData($stNID, 3, $nID)
  706.         DllStructSetData($stNID, 4, BitOr($NIF_ICON, $NIF_MESSAGE))
  707.         DllStructSetData($stNID, 5, $TRAYTIPMSG)
  708.         DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])
  709.        
  710.         $nResult = Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID))
  711.         If $nResult Then _TrayIconSetToolTip($nID, $TRAYNOTIFYIDS[$nID][4])
  712.     ElseIf BitAnd($nState, 2) Then
  713.         DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  714.         DllStructSetData($stNID, 2, $TRAYMSGWND)
  715.         DllStructSetData($stNID, 3, $nID)
  716.        
  717.         $nResult = Shell_NotifyIcon($NIM_DELETE, DllStructGetPtr($stNID))
  718.     EndIf
  719.    
  720.     If BitAnd($nState, 4) Then
  721.         If Not $TRAYNOTIFYIDS[$nID][7] Then
  722.             If $hBlankIcon = 0 Then _CreateBlankIcon()
  723.             If $hBlankIcon <> 0 Then
  724.                 SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0)
  725.                 $TRAYNOTIFYIDS[$nID][7] = TRUE
  726.             EndIf
  727.         EndIf
  728.     ElseIf BitAnd($nState, 8) Then
  729.         KillTimer($TRAYMSGWND, $FLASHTIMERID)
  730.        
  731.         DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  732.         DllStructSetData($stNID, 2, $TRAYMSGWND)
  733.         DllStructSetData($stNID, 3, $nID)
  734.         DllStructSetData($stNID, 4, $NIF_ICON)
  735.         DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])
  736.        
  737.         $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
  738.        
  739.         $TRAYNOTIFYIDS[$nID][7] = FALSE
  740.         $TRAYNOTIFYIDS[$nID][8] = FALSE
  741.     EndIf
  742.    
  743.     Return $nResult
  744. EndFunc
  745.  
  746.  
  747. ;**********************************************************************
  748. ; _TrayIconSetIcon($NotificationID, IconFile [, IconID])
  749. ;**********************************************************************
  750. Func _TrayIconSetIcon($nID = -1, $sIconFile = @AutoItExe, $nIconID = 0)
  751.     If $nID = -1 Then $nID = $TRAYLASTID
  752.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  753.    
  754.     $nIconID = _GetIconID($nIconID, $sIconFile)
  755.    
  756.     Local $hIcon = 0
  757.    
  758.     If $sIconFile = "" Then
  759.         If $nIconID = 0 Then
  760.             $sIconFile = @AutoItExe
  761.         Else
  762.             $hIcon = LoadIcon(0, $nIconID)
  763.         EndIf
  764.     EndIf
  765.    
  766.     If $sIconFile <> "" Then
  767.         Local $stIcon = DllStructCreate("hwnd")
  768.        
  769.         If ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1) > 0 Then
  770.             $hIcon = DllStructGetData($stIcon, 1)
  771.         Else
  772.             $hIcon = LoadIcon(0, 32516)
  773.         EndIf
  774.     EndIf
  775.    
  776.     Local $stNID    = DllStructCreate($sNOTIFYICONDATAW)
  777.     DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  778.     DllStructSetData($stNID, 2, $TRAYMSGWND)
  779.     DllStructSetData($stNID, 3, $nID)
  780.     DllStructSetData($stNID, 4, $NIF_ICON)
  781.     DllStructSetData($stNID, 6, $hIcon)
  782.  
  783.     DestroyIcon($TRAYNOTIFYIDS[$nID][1])
  784.    
  785.     Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
  786.     If $nResult Then
  787.         $TRAYNOTIFYIDS[$nID][1] = $hIcon
  788.     Else
  789.         DestroyIcon($hIcon)
  790.         $TRAYNOTIFYIDS[$nID][1] = 0
  791.     EndIf
  792.    
  793.     Return $nResult
  794. EndFunc
  795.  
  796.  
  797. ;**********************************************************************
  798. ; _TrayIconSetToolTip($NotificationID, $sToolTip)
  799. ;**********************************************************************
  800. Func _TrayIconSetToolTip($nID = -1, $sToolTip = $sDefaultTT)
  801.     If $nID = -1 Then $nID = $TRAYLASTID
  802.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  803.    
  804.     Local $stNID    = DllStructCreate($sNOTIFYICONDATAW)
  805.     DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  806.     DllStructSetData($stNID, 2, $TRAYMSGWND)
  807.     DllStructSetData($stNID, 3, $nID)
  808.     DllStructSetData($stNID, 4, $NIF_TIP)
  809.     DllStructSetData($stNID, 7, $sToolTip)
  810.  
  811.     Return Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
  812. EndFunc
  813.  
  814.  
  815. ;**********************************************************************
  816. ; _TrayGetMenuHandle($NotificationID)
  817. ;**********************************************************************
  818. Func _TrayGetMenuHandle($nID)
  819.     If $nID = -1 Then $nID = $TRAYLASTID
  820.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  821.    
  822.     Return $TRAYNOTIFYIDS[$nID][2]
  823. EndFunc
  824.  
  825.  
  826. ;**********************************************************************
  827. ; Return a free index in the item array or create a new index
  828. ;**********************************************************************
  829. Func _GetNewItemIndex()
  830.     Local $i = 0, $bFreeFound = FALSE
  831.    
  832.     For $i = 1 To $arMenuItems[0][0]
  833.         If $arMenuItems[$i][0] = 0 Then
  834.             $bFreeFound = TRUE
  835.             ExitLoop
  836.         EndIf
  837.     Next
  838.  
  839.     If Not $bFreeFound Then
  840.         $arMenuItems[0][0] += 1
  841.         Local $nSize = UBound($arMenuItems)
  842.  
  843.         If $arMenuItems[0][0] > $nSize - $nMenuItemsRedim Then _
  844.             Redim $arMenuItems[$nSize + $nMenuItemsRedim][8]
  845.         $i = $arMenuItems[0][0]
  846.     EndIf
  847.    
  848.     Return $i
  849. EndFunc
  850.  
  851.  
  852. ;**********************************************************************
  853. ; Return a free index in the item array or create a new index
  854. ;**********************************************************************
  855. Func _GetNewSideItemIndex()
  856.     Local $i = 0, $bFreeFound = FALSE
  857.    
  858.     For $i = 1 To $arSideItems[0][0]
  859.         If $arSideItems[$i][0] = 0 Then
  860.             $bFreeFound = TRUE
  861.             ExitLoop
  862.         EndIf
  863.     Next
  864.  
  865.     If Not $bFreeFound Then
  866.         $arSideItems[0][0] += 1
  867.         Local $nSize = UBound($arSideItems)
  868.  
  869.         If $arSideItems[0][0] > $nSize - $nMenuItemsRedim Then _
  870.             Redim $arSideItems[$nSize + $nMenuItemsRedim][10]
  871.         $i = $arSideItems[0][0]
  872.     EndIf
  873.    
  874.     Return $i
  875. EndFunc
  876.  
  877.  
  878. ;**********************************************************************
  879. ; Create a context menu for a tray notify ID
  880. ;**********************************************************************
  881. Func _TrayCreateContextMenu($nID = -1)
  882.     Local $nIdx = _GetTrayNotifyIdx($nID)
  883.     If $nIdx = 0 Then Return 0
  884.    
  885.     Local $nContext = 0
  886.    
  887.     If $TRAYNOTIFYIDS[$nIdx][2] = 0 Then
  888.         Local $nDummy = GUICtrlCreateDummy()
  889.         $nContext = GUICtrlCreateContextMenu($nDummy)
  890.         $TRAYNOTIFYIDS[$nIdx][2] = $nContext
  891.        
  892.         $TRAYLASTMENU = $nContext
  893.     EndIf
  894.        
  895.     Return $nContext
  896. EndFunc
  897.  
  898.  
  899. ;**********************************************************************
  900. ; Create a (context) menu for a tray notify ID
  901. ;**********************************************************************
  902. Func _TrayCreateMenu($sText, $nMenuID = -1, $nMenuEntry = -1)
  903.     If $nMenuID = -1 Then $nMenuID = $TRAYLASTMENU
  904.    
  905.     Local $nMenu = GUICtrlCreateMenu($sText, $nMenuID, $nMenuEntry)
  906.    
  907.     If $nMenu > 0 Then
  908.         Local $nIdx = _GetNewItemIndex()
  909.         If $nIdx = 0 Then Return 0
  910.  
  911.         $TRAYLASTITEM = $nMenu
  912.                        
  913.         Local $hMenu = GUICtrlGetHandle($nMenuID)
  914.        
  915.         $arMenuItems[$nIdx][0] = $nMenu
  916.         $arMenuItems[$nIdx][1] = $sText
  917.         $arMenuItems[$nIdx][2] = -1
  918.         $arMenuItems[$nIdx][3] = $hMenu
  919.         $arMenuItems[$nIdx][4] = 0
  920.         $arMenuItems[$nIdx][5] = TRUE
  921.         $arMenuItems[$nIdx][6] = -1
  922.         $arMenuItems[$nIdx][7] = TRUE
  923.     EndIf
  924.    
  925.     Return $nMenu
  926. EndFunc
  927.  
  928.  
  929. ;**********************************************************************
  930. ; Create a menuitem for a tray notify ID
  931. ;**********************************************************************
  932. Func _TrayCreateItem($sText, $nMenuID = -1, $nMenuEntry = -1, $bRadio = 0)
  933.     If $nMenuID = -1 Then $nMenuID = $TRAYLASTMENU
  934.    
  935.     Local $nMenuItem = GUICtrlCreateMenuItem($sText, $nMenuID, $nMenuEntry, $bRadio)
  936.    
  937.     If $nMenuItem > 0 Then
  938.         Local $nIdx = _GetNewItemIndex()
  939.         If $nIdx = 0 Then Return 0
  940.    
  941.         $TRAYLASTITEM = $nMenuItem
  942.        
  943.         Local $hMenu = GUICtrlGetHandle($nMenuID)
  944.        
  945.         $arMenuItems[$nIdx][0] = $nMenuItem
  946.         $arMenuItems[$nIdx][1] = $sText
  947.         $arMenuItems[$nIdx][2] = -1
  948.         $arMenuItems[$nIdx][3] = $hMenu
  949.         $arMenuItems[$nIdx][4] = $bRadio
  950.         $arMenuItems[$nIdx][5] = TRUE
  951.         $arMenuItems[$nIdx][6] = -1
  952.         $arMenuItems[$nIdx][7] = FALSE
  953.     EndIf
  954.    
  955.     Return $nMenuItem
  956. EndFunc
  957.  
  958.  
  959. ;**********************************************************************
  960. ; Delete a menu (item)
  961. ;**********************************************************************
  962. Func _GUICtrlODMenuItemDelete($nID)
  963.     Return _TrayDeleteItem($nID)
  964. EndFunc
  965.  
  966.  
  967. Func _TrayDeleteItem($nID)
  968.     Local $i, $k, $nResult = 0, $bFound = FALSE
  969.    
  970.     Local $hMenu = GUICtrlGetHandle($nID)
  971.     Local $bIsMenu = FALSE
  972.     If $hMenu <> 0 Then $bIsMenu = TRUE
  973.        
  974.     For $i = 1 To $arMenuItems[0][0]
  975.         If $arMenuItems[$i][0] = 0 Then ContinueLoop
  976.        
  977.         If $bIsMenu Then
  978.             For $k = 1 To $arMenuItems[0][0]
  979.                 If $arMenuItems[$k][3] = $hMenu And _
  980.                     $arMenuItems[$i][0] <> $arMenuItems[$k][0] Then _TrayDeleteItem($arMenuItems[$k][0])
  981.                     ;$k <> $i Then _TrayDeleteItem($arMenuItems[$k][0])    
  982.             Next
  983.         EndIf
  984.        
  985.         If $arMenuItems[$i][0] = $nID Then
  986.             If GUICtrlDelete($nID) Then
  987.                 $arMenuItems[$i][0] = 0
  988.                 $arMenuItems[$i][1] = ""
  989.                 $arMenuItems[$i][2] = -1
  990.                 $arMenuItems[$i][3] = 0
  991.                 $arMenuItems[$i][4] = 0
  992.                 $arMenuItems[$i][5] = FALSE
  993.                 $arMenuItems[$i][6] = -1
  994.                 $arMenuItems[$i][7] = FALSE
  995.                
  996.                 $nResult = 1
  997.                 $bFound = TRUE
  998.             EndIf
  999.            
  1000.             ExitLoop
  1001.         EndIf
  1002.     Next
  1003.    
  1004.     If Not $bFound And $nID <> 0 Then GUICtrlDelete($nID)
  1005.    
  1006.     Return $nResult
  1007. EndFunc
  1008.  
  1009.  
  1010. ;**********************************************************************
  1011. ; Sets the possible clicks
  1012. ;**********************************************************************
  1013. Func _TrayIconSetClick($nID, $nClicks)
  1014.     If $nID = -1 Then $nID = $TRAYLASTID
  1015.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  1016.    
  1017.     $TRAYNOTIFYIDS[$nID][3] = $nClicks
  1018. EndFunc
  1019.  
  1020.  
  1021. ;**********************************************************************
  1022. ; TrayTip()
  1023. ;**********************************************************************
  1024. Func _TrayTip($nID, $sTitle, $sText, $nTimeOut = 10, $nInfoFlags = 0)
  1025.     If @OSType <> "WIN32_NT" Then Return 0
  1026.     If @OSVersion = "WIN_NT4" Then Return 0
  1027.  
  1028.     If $nID = -1 Then $nID = $TRAYLASTID
  1029.     If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0
  1030.    
  1031.     Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
  1032.  
  1033.     DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  1034.     DllStructSetData($stNID, 2, $TRAYMSGWND)
  1035.     DllStructSetData($stNID, 3, $nID)
  1036.     DllStructSetData($stNID, 4, $NIF_INFO)
  1037.     DllStructSetData($stNID, 10, $sText)
  1038.     DllStructSetData($stNID, 11, $nTimeOut * 1000)
  1039.     DllStructSetData($stNID, 12, $sTitle)
  1040.     DllStructSetData($stNID, 13, $nInfoFlags)
  1041.    
  1042.      Local $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
  1043.  
  1044.      Return $nResult
  1045. EndFunc
  1046.  
  1047.  
  1048. ;********************************************************************
  1049. ; WM_MEASURE procedure
  1050. ;********************************************************************
  1051. Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
  1052.     Local $nResult = FALSE
  1053.    
  1054.     Local $stMeasureItem = DllStructCreate("uint;uint;uint;uint;uint;dword", $lParam)
  1055.    
  1056.     If DllStructGetData($stMeasureItem, 1) = 1 Then
  1057.        
  1058.         Local $nIconSize    = 0
  1059.         Local $nCheckX        = 0
  1060.         Local $nSpace        = 2
  1061.        
  1062.         _GetMenuInfos($nIconSize, $nCheckX)
  1063.        
  1064.         If $nIconSize < $nCheckX Then $nIconSize = $nCheckX
  1065.        
  1066.         Local $nMenuItemID    = DllStructGetData($stMeasureItem, 3)
  1067.        
  1068.         Local $hDC            = GetDC($hWnd)
  1069.                
  1070.         Local $hMenu        = _GetMenuHandle($nMenuItemID)
  1071.  
  1072.         Local $nState        = GetMenuState($hMenu, $nMenuItemID, 0)
  1073.        
  1074.         ; Reassign the current menu font to the menuitem
  1075.         Local $hMFont        = 0
  1076.         Local $bBoldFont    = FALSE
  1077.        
  1078.         If BitAnd($nState, 0x00001000) And Not BitAnd($nState, 0x00000010) Then
  1079.             _CreateMenuFont($hMFont, TRUE)
  1080.             $bBoldFont    = TRUE
  1081.         Else
  1082.             $hMFont = $hMenuFont
  1083.         EndIf
  1084.        
  1085.         Local $hFont        = SelectObject($hDC, $hMFont)
  1086.                
  1087.         Local $sText        = _GetMenuText($nMenuItemID)
  1088.        
  1089.         Local $nSideIdx        = _GetSideMenuIndex($hMenu)
  1090.         Local $sSideText    = _GetSideMenuText($nSideIdx)
  1091.         Local $hSideImage    = _GetSideMenuImage($nSideIdx)
  1092.         Local $nSideWidth    = 0
  1093.        
  1094.         If $sSideText <> "" Then
  1095.             If $hSideImage = 0 Then
  1096.                 Local $hSideFont = 0
  1097.                 _CreateMenuFont($hSideFont, TRUE, TRUE)
  1098.                 Local $hOldObj = SelectObject($hDC, $hSideFont)
  1099.                
  1100.                 $nSideWidth = _GetSideMenuTextWidth($hDC, $sSideText) + 2 ; 1 x 1 left + right
  1101.                 SelectObject($hDC, $hOldObj)
  1102.                 DeleteObject($hSideFont)
  1103.             Else
  1104.                 Local $nSideHeight    = 0
  1105.                 Local $bStretch        = FALSE
  1106.                
  1107.                 _GetSideMenuImageSize($nSideIdx, $nSideWidth, $nSideHeight, $bStretch)
  1108.             EndIf
  1109.         EndIf
  1110.        
  1111.         Local $nMaxTextWidth    = 0
  1112.         Local $nMaxTextAccWidth    = 0
  1113.        
  1114.         _GetMenuMaxTextWidth($hDC, $hMenu, $nMaxTextWidth, $nMaxTextAccWidth)
  1115.         If $nMaxTextAccWidth > 0 Then $nMaxTextAccWidth += 4
  1116.        
  1117.         Local $nHeight        = 2 * $nSpace + $nIconSize
  1118.         Local $nWidth        = 0
  1119.    
  1120.         ; Set a default separator height
  1121.         If $sText = "" Then
  1122.             $nHeight = 4
  1123.         Else
  1124.             $nWidth    = 6 * $nSpace + 2 * $nIconSize + $nMaxTextWidth + $nMaxTextAccWidth + $nSideWidth
  1125.             If $hMenu = "TOP" Then $nWidth    = 4 * $nSpace+$nMaxTextWidth + $nMaxTextAccWidth
  1126.             ; Maybe this differs - have no emulator here at the moment
  1127.             If @OSVersion <> "WIN_98" And @OSVersion <> "WIN_ME" Then
  1128.                 $nWidth = $nWidth - $nCheckX + 1
  1129.             EndIf
  1130.         EndIf
  1131.  
  1132.         DllStructSetData($stMeasureItem, 4, $nWidth)    ; ItemWidth
  1133.         DllStructSetData($stMeasureItem, 5, $nHeight)    ; ItemHeight
  1134.  
  1135.         SelectObject($hDC, $hFont)
  1136.         If $bBoldFont Then DeleteObject($hMFont)
  1137.        
  1138.         ReleaseDC($hWnd, $hDC)
  1139.         $nResult = TRUE
  1140.     EndIf
  1141.  
  1142.     $stMeasureItem    = 0
  1143.  
  1144.     Return $nResult
  1145. EndFunc
  1146.  
  1147.  
  1148. ;********************************************************************
  1149. ; WM_DRAWITEM procedure
  1150. ;********************************************************************
  1151.  
  1152. Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
  1153.     Local $nResult        = FALSE
  1154.    
  1155.     Local $stDrawItem    = DllStructCreate("uint;uint;uint;uint;uint;dword;dword;int[4];dword", $lParam)
  1156.    
  1157.     If DllStructGetData($stDrawItem, 1) = 1 Then
  1158.         Local $nMenuItemID    = DllStructGetData($stDrawItem, 3)
  1159.         Local $nAction        = DllStructGetData($stDrawItem, 4)
  1160.         Local $nState        = DllStructGetData($stDrawItem, 5)
  1161.         Local $hMenu        = DllStructGetData($stDrawItem, 6)
  1162.         Local $hDC            = DllStructGetData($stDrawItem, 7)
  1163.        
  1164.         Local $bChecked        = BitAnd($nState, 0x0008)
  1165.         Local $bGrayed        = BitAnd($nState, 0x0002)
  1166.         Local $bSelected    = BitAnd($nState, 0x0001)
  1167.         Local $bDefault        = BitAnd($nState, 0x0020)
  1168.         Local $bNoAcc        = BitAnd($nState, 0x0100)
  1169.         Local $bIsRadio        = _GetMenuIsRadio($nMenuItemID)
  1170.        
  1171.         Local $nSideIdx        = _GetSideMenuIndex($hMenu)
  1172.         Local $sSideText    = _GetSideMenuText($nSideIdx)
  1173.         Local $hSideImage    = _GetSideMenuImage($nSideIdx)
  1174.         Local $hSideFont    = 0
  1175.         Local $hOldObj        = 0
  1176.         Local $nSideWidth    = 0
  1177.         Local $nSideHeight    = 0
  1178.         Local $bHasSide        = FALSE
  1179.         Local $bStretch        = FALSE
  1180.  
  1181.         If $sSideText <> "" Then
  1182.             If $hSideImage = 0 Then
  1183.                 _CreateMenuFont($hSideFont, TRUE, TRUE)
  1184.                 $hOldObj = SelectObject($hDC, $hSideFont)
  1185.                 $nSideWidth = _GetSideMenuTextWidth($hDC, $sSideText) + 2 ; 1 left + 1 right
  1186.                 SelectObject($hDC, $hOldObj)
  1187.             Else
  1188.                 _GetSideMenuImageSize($nSideIdx, $nSideWidth, $nSideHeight, $bStretch)
  1189.             EndIf
  1190.            
  1191.             $bHasSide = TRUE
  1192.         EndIf
  1193.        
  1194.         Local $arIR[4]
  1195.         $arIR[0]            = DllStructGetData($stDrawItem, 8, 1) + $nSideWidth
  1196.         $arIR[1]            = DllStructGetData($stDrawItem, 8, 2)
  1197.         $arIR[2]            = DllStructGetData($stDrawItem, 8, 3)
  1198.         $arIR[3]            = DllStructGetData($stDrawItem, 8, 4)
  1199.        
  1200.         Local $stItemRect    = DllStructCreate("int;int;int;int")
  1201.         _SetItemRect($stItemRect, $arIR[0], $arIR[1], $arIR[2], $arIR[3])
  1202.        
  1203.         ; Set default menu values if info function fails
  1204.         Local $nIconSize    = 16
  1205.         Local $nCheckX        = 16
  1206.         Local $nSpace        = 2
  1207.        
  1208.         _GetMenuInfos($nIconSize, $nCheckX)
  1209.        
  1210.        
  1211.         Local $nMBkClr            = $nMenuBkClr
  1212.         Local $nMIconBkClr        = $nMenuIconBkClr
  1213.         Local $nMIconBkClr2        = $nMenuIconBkClr2
  1214.         Local $nMSelectBkClr    = $nMenuSelectBkClr
  1215.         Local $nMSelectRectClr    = $nMenuSelectRectClr
  1216.         Local $nMSelectTextClr    = $nMenuSelectTextClr
  1217.         Local $nMTextClr        = $nMenuTextClr
  1218.        
  1219.         Local $bIsTrayItem        = _IsTrayItem($nMenuItemID)
  1220.        
  1221.         Local $IsMenuBarItem = (_GetMenuHandle($nMenuItemID)== "TOP") And Not $bIsTrayItem
  1222.         If $nState = 320 And $IsMenuBarItem Then
  1223.             $nMBkClr = $nMSelectBkClr
  1224.             $nMTextClr = $nMSelectTextClr
  1225.         EndIf
  1226.        
  1227.         If $bIsTrayItem Then
  1228.             $nMBkClr            = $nTrayBkClr
  1229.             $nMIconBkClr        = $nTrayIconBkClr
  1230.             $nMIconBkClr2        = $nTrayIconBkClr2
  1231.             $nMSelectBkClr        = $nTraySelectBkClr
  1232.             $nMSelectRectClr    = $nTraySelectRectClr
  1233.             $nMSelectTextClr    = $nTraySelectTextClr
  1234.             $nMTextClr            = $nTrayTextClr
  1235.         EndIf
  1236.        
  1237.         ; Select our at beginning selfcreated menu font into the item device context
  1238.         Local $hMFont        = 0
  1239.         Local $bBoldFont    = FALSE
  1240.        
  1241.         If $bDefault Then
  1242.             _CreateMenuFont($hMFont, TRUE)
  1243.             $bBoldFont = TRUE
  1244.         Else
  1245.             $hMFont = $hMenuFont
  1246.         EndIf
  1247.        
  1248.         Local $hBrush        = 0
  1249.         Local $hOldBrush    = 0
  1250.         Local $nClrSel        = 0
  1251.         Local $hBorderBrush    = 0
  1252.         Local $nLen            = 0
  1253.         Local $stSize        = 0
  1254.        
  1255.        
  1256.         ; Show side menu only if action = ODA_DRAWENTIRE
  1257.         If $nAction = 1 Then
  1258.             Local $nCount = GetMenuItemCount($hMenu)
  1259.             Local $nID = GetMenuItemID($hMenu, $nCount - 1)
  1260.            
  1261.             If $nID = -1 Then
  1262.                 Local $stMII = DllStructCreate($sMENUITEMINFO)
  1263.                 DllStructSetData($stMII, 1, DllStructGetSize($stMII))
  1264.                 DllStructSetData($stMII, 2, 0x00000002) ; MIIM_ID
  1265.                 If GetMenuItemInfo($hMenu, $nCount - 1, TRUE, DllStructGetPtr($stMII)) Then _
  1266.                     $nID = DllStructGetData($stMII, 5)
  1267.             EndIf
  1268.            
  1269.             If $nID = $nMenuItemID And $bHasSide Then
  1270.                 Local $stSideRect = DllStructCreate("int;int;int;int")
  1271.                 _SetItemRect($stSideRect, 0, 0, $nSideWidth, $arIR[3])
  1272.                
  1273.                 Local $nSideClr        = $nMenuSideTxtClr
  1274.                 Local $nSideBkClr    = $nMenuSideBkClr
  1275.                 Local $nSideBkClr2    = $nMenuSideBkClr2
  1276.                
  1277.                 _GetSideMenuColors($nSideIdx, $nSideClr, $nSideBkClr, $nSideBkClr2)
  1278.                
  1279.                 If $nSideBkClr <> -1 Then
  1280.                     If $nSideBkClr = $nSideBkClr2 Or _
  1281.                         $nSideBkClr2 = -1 Then
  1282.                         SetBkColor($hDC, $nSideBkClr)
  1283.                        
  1284.                         $hBrush    = CreateSolidBrush($nSideBkClr)
  1285.                         $hOldBrush = SelectObject($hDC, $hBrush)
  1286.                        
  1287.                         FillRect($hDC, DllStructGetPtr($stSideRect), $hBrush)
  1288.                        
  1289.                         SelectObject($hDC, $hOldBrush)
  1290.                         DeleteObject($hBrush)
  1291.                        
  1292.                         $hBrush        = 0
  1293.                         $hOldBrush    = 0
  1294.                     Else
  1295.                         _FillGradientRect($hDC, $stSideRect, $nSideBkClr2, $nSideBkClr, TRUE)
  1296.                     EndIf
  1297.                 EndIf
  1298.                
  1299.                 If $hSideImage = 0 Then
  1300.                     $nLen    = StringLen($sSideText)
  1301.                     $stSize    = DllStructCreate("int;int")
  1302.                    
  1303.                     $stSideText = DllStructCreate("wchar[" & $nLen + 1 & "]")
  1304.                     DllStructSetData($stSideText, 1, $sSideText)
  1305.                    
  1306.                     $hOldObj = SelectObject($hDC, $hSideFont)
  1307.                    
  1308.                     Local $nOldMode = SetBkMode($hDC, 1)
  1309.                     SetTextColor($hDC, $nSideClr)
  1310.                                    
  1311.                     DllStructSetData($stSideRect, 2, 8)
  1312.                     DllStructSetData($stSideRect, 4, DllStructGetData($stSideRect, 4) + 8)
  1313.                    
  1314.                     DrawTextW($hDC, DllStructGetPtr($stSideText), _
  1315.                                     StringLen($sSideText), _
  1316.                                     DllStructGetPtr($stSideRect), _
  1317.                                     BitOr(0x00000008, 0x00000020, 0x00000100))
  1318.                    
  1319.                     SetBkMode($hDC, $nOldMode)
  1320.                     SelectObject($hDC, $hOldObj)
  1321.                 Else
  1322.                     Local $hCDC = CreateCompatibleDC($hDC)
  1323.                     $hObjOld = SelectObject($hCDC, $hSideImage)
  1324.                    
  1325.                     If $bStretch Then
  1326.                         StretchBlt($hDC, 0, 0, $nSideWidth, $arIR[3], $hCDC, 0, 0, $nSideWidth, $nSideHeight, 0x00CC0020)
  1327.                     Else
  1328.                         BitBlt($hDC, 0, 0, $nSideWidth, $arIR[3], $hCDC, 0, $nSideHeight - $arIR[3], 0x00CC0020)
  1329.                     EndIf
  1330.                    
  1331.                     SelectObject($hCDC, $hObjOld)
  1332.                     DeleteDC($hCDC)
  1333.                 EndIf
  1334.             EndIf
  1335.         EndIf
  1336.        
  1337.         If $hSideFont <> 0 Then DeleteObject($hSideFont)
  1338.        
  1339.         Local $hFont = SelectObject($hDC, $hMFont)
  1340.        
  1341.         ; Only show a menu bar when the item is enabled
  1342.         If $bSelected Then ;And Not $bGrayed Then
  1343.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1344.                 $hBorderBrush    = CreateSolidBrush($nMSelectRectClr)
  1345.                 If $bGrayed Then
  1346.                     $hBrush        = CreateSolidBrush($nMBkClr)
  1347.                     $nClrSel    = $nMBkClr
  1348.                 Else
  1349.                     $hBrush        = CreateSolidBrush($nMSelectBkClr) ; BGR color value
  1350.                     $nClrSel    = $nMSelectBkClr
  1351.                 EndIf
  1352.                
  1353.             Else
  1354.                 $hBrush            = GetSysColorBrush(13)
  1355.                 $nClrSel        = GetSysColor(13)
  1356.             EndIf
  1357.         Else
  1358.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1359.                 $hBrush            = CreateSolidBrush($nMBkClr)
  1360.                 $nClrSel        = $nMBkClr
  1361.             Else
  1362.                 $hBrush            = GetSysColorBrush(4)
  1363.                 $nClrSel        = GetSysColor(4)
  1364.             EndIf
  1365.         EndIf
  1366.        
  1367.         Local $nClrTxt        = 0
  1368.        
  1369.         If $bSelected And Not $bGrayed Then
  1370.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1371.                 $nClrTxt    = SetTextColor($hDC, $nMSelectTextClr)
  1372.             Else
  1373.                 $nClrTxt    = SetTextColor($hDC, GetSysColor(14))
  1374.             EndIf
  1375.         ElseIf $bGrayed Then
  1376.             $nClrTxt        = SetTextColor($hDC, GetSysColor(17))
  1377.         Else
  1378.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1379.                 $nClrTxt    = SetTextColor($hDC, $nMTextClr)
  1380.             Else
  1381.                 $nClrTxt    = SetTextColor($hDC, GetSysColor(7))
  1382.             EndIf
  1383.         EndIf    
  1384.        
  1385.         Local $nClrBk        = SetBkColor($hDC, $nClrSel)
  1386.         $hOldBrush            = SelectObject($hDC, $hBrush)
  1387.        
  1388.         FillRect($hDC, DllStructGetPtr($stItemRect), $hBrush)
  1389.         SelectObject($hDC, $hOldBrush)
  1390.         DeleteObject($hBrush)
  1391.        
  1392.         If $IsMenuBarItem Then
  1393.             $nIconSize    = 0
  1394.             $nCheckX        = 0
  1395.             $nSpace        = 2
  1396.         EndIf
  1397.        
  1398.         If Not $IsMenuBarItem And ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1399.             ; Create a small gray edge
  1400.             If Not $bSelected Or $bGrayed Then
  1401.                 ; Reassign the item rect
  1402.                 _SetItemRect($stItemRect, $arIR[0], $arIR[1], $arIR[0] + 2 * $nSpace + $nIconSize + 1, $arIR[3])
  1403.                    
  1404.                 If $nMIconBkClr = $nMIconBkClr2  Or _
  1405.                     $nMIconBkClr2 = -1 Then
  1406.                     $hBrush        = CreateSolidBrush($nMIconBkClr)
  1407.                     $hOldBrush    = SelectObject($hDC, $hBrush)
  1408.                    
  1409.                     FillRect($hDC, DllStructGetPtr($stItemRect), $hBrush)
  1410.                    
  1411.                     SelectObject($hDC, $hOldBrush)
  1412.                     DeleteObject($hBrush)
  1413.                 Else
  1414.                     _FillGradientRect($hDC, $stItemRect, $nMIconBkClr, $nMIconBkClr2)
  1415.                 EndIf
  1416.             EndIf
  1417.         EndIf
  1418.        
  1419.         If $bChecked Then
  1420.             _SetItemRect($stItemRect, $arIR[0] + 1, $arIR[1] + 1, $arIR[0] + $nIconSize + $nSpace + 1, $arIR[1] + $nIconSize + $nSpace + 1)
  1421.            
  1422.             If $bSelected Then
  1423.                 If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1424.                     $hBrush        = CreateSolidBrush($nMSelectBkClr)
  1425.                 Else
  1426.                     $hBrush        = GetSysColorBrush(13)
  1427.                 EndIf    
  1428.             Else
  1429.                 If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1430.                     $hBrush        = CreateSolidBrush($nMBkClr)
  1431.                 Else
  1432.                     $hBrush        = GetSysColorBrush(4)
  1433.                 EndIf
  1434.             EndIf
  1435.            
  1436.             $hOldBrush    = SelectObject($hDC, $hBrush)
  1437.             FillRect($hDC, DllStructGetPtr($stItemRect), $hBrush)
  1438.             SelectObject($hDC, $hOldBrush)
  1439.             DeleteObject($hBrush)
  1440.            
  1441.             ; Create a checkmark/bullet for the checked/radio items
  1442.             Local $hDCBitmap    = CreateCompatibleDC($hDC)
  1443.             Local $hbmpCheck    = CreateBitmap($nIconSize, $nIconSize, 1, 1, 0)
  1444.             Local $hbmpOld        = SelectObject($hDCBitmap, $hbmpCheck)
  1445.            
  1446.             Local $x = DllStructGetData($stItemRect, 1) + ($nIconSize + $nSpace - $nCheckX) / 2
  1447.             Local $y = DllStructGetData($stItemRect, 2) + ($nIconSize + $nSpace - $nCheckX) / 2 - $nSpace
  1448.            
  1449.             _SetItemRect($stItemRect, 0, 0, $nIconSize, $nIconSize)
  1450.            
  1451.             Local $nCtrlStyle = 0x0001
  1452.            
  1453.             If $bIsRadio Then $nCtrlStyle = 0x0002
  1454.            
  1455.             DrawFrameControl($hDCBitmap, DllStructGetPtr($stItemRect), 2, $nCtrlStyle)
  1456.            
  1457.             BitBlt($hDC, $x, $y + 1, $nCheckX, $nCheckX, $hDCBitmap, 0, 0, 0x00CC0020)
  1458.            
  1459.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1460.                 _SetItemRect($stItemRect, $arIR[0] + 1, $arIR[1] + 1, $arIR[0] + $nIconSize + $nSpace + 1, $arIR[1] + $nIconSize + $nSpace + 1)
  1461.                 $hBrush    = CreateSolidBrush($nMSelectRectClr)                    
  1462.                 $hOldBrush    = SelectObject($hDC, $hBrush)
  1463.                 FrameRect($hDC, DllStructGetPtr($stItemRect), $hBrush)
  1464.                 SelectObject($hDC, $hOldBrush)
  1465.                 DeleteObject($hBrush)
  1466.             EndIf
  1467.            
  1468.             SelectObject($hDCBitmap, $hbmpOld)
  1469.             DeleteObject($hbmpCheck)
  1470.             DeleteDC($hDCBitmap)
  1471.         EndIf        
  1472.        
  1473.         ; Reassign the item rect
  1474.         _SetItemRect($stItemRect, $arIR[0], $arIR[1], $arIR[2], $arIR[3])
  1475.        
  1476.         If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1477.             ;If $bSelected And Not $bGrayed Then
  1478.             If $bSelected Then ; Show also a rect around a disabled item
  1479.                 $hOldBrush    = SelectObject($hDC, $hBorderBrush)
  1480.                 FrameRect($hDC, DllStructGetPtr($stItemRect), $hBorderBrush)
  1481.                 SelectObject($hDC, $hOldBrush)
  1482.                 DeleteObject($hBorderBrush)        
  1483.             EndIf
  1484.         EndIf
  1485.        
  1486.         Local $sText    = _GetMenuText($nMenuItemID)
  1487.         If $bNoAcc Then $sText = StringReplace($sText, "&", "")
  1488.        
  1489.         Local $nWidth    = 0
  1490.         Local $sAcc        = ""
  1491.         Local $arText    = StringSplit($sText, @Tab)
  1492.         Local $bTab        = FALSE
  1493.        
  1494.         If IsArray($arText) And $arText[0] > 1 Then
  1495.             $sText    = $arText[1]
  1496.             $sAcc    = $arText[2]
  1497.             $bTab    = TRUE
  1498.         EndIf
  1499.        
  1500.         $nLen            = StringLen($sText)
  1501.         Local $stText    = DllStructCreate("wchar[" & $nLen + 1 & "]")
  1502.         DllStructSetData($stText, 1, $sText)
  1503.            
  1504.         Local $nSaveLeft    = DllStructGetData($stItemRect, 1)
  1505.         Local $nLeft        = $nSaveLeft
  1506.         $nLeft += $nSpace        ; Left border
  1507.         $nLeft += $nSpace        ; Space after gray border
  1508.         $nLeft += $nIconSize    ; Icon width
  1509.         $nLeft += $nSpace + 2    ; Right after the icon
  1510.        
  1511.         DllStructSetData($stItemRect, 1, $nLeft)
  1512.        
  1513.         Local $nFlags        = BitOr(0x00000100, 0x00000020, 0x00000004)
  1514.        
  1515.         DrawTextW($hDC, DllStructGetPtr($stText), $nLen, DllStructGetPtr($stItemRect), $nFlags)
  1516.        
  1517.         ; Draw accelerator text
  1518.         If $bTab Then
  1519.             Local $nMaxTextWidth    = 0
  1520.             Local $nMaxTextAccWidth    = 0
  1521.            
  1522.             _GetMenuMaxTextWidth($hDC, $hMenu, $nMaxTextWidth, $nMaxTextAccWidth)
  1523.             If $nMaxTextAccWidth > 0 Then $nMaxTextAccWidth += 4
  1524.            
  1525.             $nWidth    = 6 * $nSpace + 2 * $nIconSize + $nMaxTextWidth
  1526.            
  1527.             ; Maybe this differs - have no emulator here at the moment
  1528.             If @OSVersion <> "WIN_98" And @OSVersion <> "WIN_ME" Then
  1529.                 $nWidth = $nWidth - $nCheckX + 1
  1530.             EndIf
  1531.            
  1532.             $nLen = StringLen($sAcc)
  1533.             $stText = DllStructCreate("wchar[" & $nLen + 1 & "]")
  1534.             DllStructSetData($stText, 1, $sAcc)
  1535.            
  1536.             ; Set rect for acc text
  1537.             _SetItemRect($stItemRect, $arIR[0] + $nWidth, $arIR[1], $arIR[0] + $nWidth + $nMaxTextAccWidth, $arIR[3])
  1538.            
  1539.             DrawTextW($hDC, DllStructGetPtr($stText), $nLen, DllStructGetPtr($stItemRect), $nFlags)
  1540.            
  1541.             ; Reset rect values
  1542.             _SetItemRect($stItemRect, $arIR[0], $arIR[1], $arIR[2], $arIR[3])
  1543.         EndIf
  1544.        
  1545.         Local $nNoSelIconIndex = -1
  1546.         Local $nSelIconIndex = -1
  1547.        
  1548.         _GetMenuIconIndex($nMenuItemID, $nNoSelIconIndex, $nSelIconIndex)        
  1549.        
  1550.         Local $nIconIndex = $nNoSelIconIndex
  1551.         If $bSelected And $nSelIconIndex > -1 Then $nIconIndex = $nSelIconIndex
  1552.        
  1553.         If $nIconIndex > -1 Then
  1554.             If Not $bChecked Then
  1555.                 If $bGrayed Then
  1556.                     ; An easy way to draw something that looks deactivated
  1557.                     ImageList_DrawEx($hMenuImageList, _
  1558.                                     $nIconIndex, _
  1559.                                     $hDC, _
  1560.                                     $nSpace + $nSideWidth, _
  1561.                                     DllStructGetData($stItemRect, 2) + 2, _
  1562.                                     0, _
  1563.                                     0, _
  1564.                                     0xFFFFFFFF, _
  1565.                                     0xFFFFFFFF, _
  1566.                                     BitOr(0x0004, 0x0001))
  1567.                 Else
  1568.                     ; Draw the icon "normal"
  1569.                     ImageList_Draw($hMenuImageList, _
  1570.                                 $nIconIndex, _
  1571.                                 $hDC, _
  1572.                                 $nSpace + $nSideWidth, _
  1573.                                 DllStructGetData($stItemRect, 2) + 2, _
  1574.                                 0x0001)
  1575.                 EndIf
  1576.             EndIf
  1577.         EndIf
  1578.        
  1579.         DllStructSetData($stItemRect, 1, $nSaveLeft)
  1580.        
  1581.         ; Draw a "line" for a separator item
  1582.         If StringLen($sText) = 0 Then
  1583.             If ($bUseAdvMenu And $bIsTrayItem = FALSE) Or ($bUseAdvTrayMenu And $bIsTrayItem) Then
  1584.                 DllStructSetData($stItemRect, 1, DllStructGetData($stItemRect, 1) + 4 * $nSpace + $nIconSize)
  1585.             Else
  1586.                 DllStructSetData($stItemRect, 1, DllStructGetData($stItemRect, 1))
  1587.             EndIf
  1588.             DllStructSetData($stItemRect, 2, DllStructGetData($stItemRect, 2) + 1)
  1589.             DllStructSetData($stItemRect, 4, DllStructGetData($stItemRect, 1) + 2)
  1590.             DrawEdge($hDC, DllStructGetPtr($stItemRect), 0x0006, 0x0002)
  1591.         EndIf
  1592.        
  1593.         $stText        = 0
  1594.         $stItemRect    = 0
  1595.        
  1596.         SelectObject($hDC, $hFont)
  1597.         If $bBoldFont Then DeleteObject($hMFont)
  1598.        
  1599.         SetTextColor($hDC, $nClrTxt)
  1600.         SetBkColor($hDC, $nClrBk)
  1601.        
  1602.         $nResult = TRUE
  1603.     EndIf
  1604.    
  1605.     $stDrawItem    = 0
  1606.    
  1607.     Return $nResult    
  1608. EndFunc
  1609.  
  1610.  
  1611. ;********************************************************************
  1612. ; Get color part
  1613. ;********************************************************************
  1614. Func _ColorGetClr($nColor, $nMode)
  1615.     Local $nClr = $nColor
  1616.    
  1617.     If $bUseRGBColors Then $nClr = _GetBGRColor($nColor)
  1618.    
  1619.     Switch $nMode
  1620.         Case 1
  1621.             $nClr = BitShift($nClr, 16)
  1622.         Case 2
  1623.             $nClr = BitShift(BitAnd($nClr, 0xFF00), 8)
  1624.         Case 3
  1625.             $nClr = BitAnd($nClr, 0xFF)
  1626.     EndSwitch
  1627.    
  1628.     Return $nClr
  1629. EndFunc
  1630.  
  1631.  
  1632. ;********************************************************************
  1633. ; Fill background rect with gradient colors
  1634. ;********************************************************************
  1635. Func _FillGradientRect($hDC, $stRect, $nClr1, $nClr2, $bVert = FALSE)
  1636.     Local $stVert = DllStructCreate("long;long;ushort;ushort;ushort;ushort;" & _
  1637.                                     "long;long;ushort;ushort;ushort;ushort")
  1638.                                    
  1639.     DllStructSetData($stVert, 1, DllStructGetData($stRect, 1))
  1640.     DllStructSetData($stVert, 2, DllStructGetData($stRect, 2))
  1641.     DllStructSetData($stVert, 3, BitShift(_ColorGetClr($nClr1, 3), -8))
  1642.     DllStructSetData($stVert, 4, BitShift(_ColorGetClr($nClr1, 2), -8))
  1643.     DllStructSetData($stVert, 5, BitShift(_ColorGetClr($nClr1, 1), -8))
  1644.     DllStructSetData($stVert, 6, 0)
  1645.    
  1646.     DllStructSetData($stVert, 7, DllStructGetData($stRect, 3))
  1647.     DllStructSetData($stVert, 8, DllStructGetData($stRect, 4))
  1648.     DllStructSetData($stVert, 9, BitShift(_ColorGetClr($nClr2, 3), -8))
  1649.     DllStructSetData($stVert, 10, BitShift(_ColorGetClr($nClr2, 2), -8))
  1650.     DllStructSetData($stVert, 11, BitShift(_ColorGetClr($nClr2, 1), -8))
  1651.     DllStructSetData($stVert, 12, 0)
  1652.    
  1653.     Local $stGradRect = DllStructCreate("ulong;ulong")
  1654.     DllStructSetData($stGradRect, 1, 0)
  1655.     DllStructSetData($stGradRect, 2, 1)
  1656.    
  1657.     If $bVert Then
  1658.         GradientFill($hDC, DllStructGetPtr($stVert), 2, DllStructGetPtr($stGradRect), 1, 1)
  1659.     Else
  1660.         GradientFill($hDC, DllStructGetPtr($stVert), 2, DllStructGetPtr($stGradRect), 1, 0)
  1661.     EndIf
  1662. EndFunc
  1663.  
  1664.  
  1665. ;********************************************************************
  1666. ; Sets 4 values to a itemrect struct
  1667. ;********************************************************************
  1668. Func _SetItemRect(ByRef $stStruct, $p1, $p2, $p3, $p4)
  1669.     DllStructSetData($stStruct, 1, $p1)
  1670.     DllStructSetData($stStruct, 2, $p2)
  1671.     DllStructSetData($stStruct, 3, $p3)
  1672.     DllStructSetData($stStruct, 4, $p4)
  1673. EndFunc
  1674.  
  1675.  
  1676. ;********************************************************************
  1677. ; WM_SETTINGCHANGE procedure
  1678. ;********************************************************************
  1679. Func WM_SETTINGCHANGE($hWnd, $Msg, $wParam, $lParam)
  1680.     If $wParam = 0x002A Then _CreateMenuFont($hMenuFont)
  1681. EndFunc
  1682.  
  1683.  
  1684. ;********************************************************************
  1685. ; WM_TIMER procedure
  1686. ;********************************************************************
  1687. Func WM_TIMER($hWnd, $Msg, $wParam, $lParam)
  1688.     Local $nID = Number($wParam)
  1689.  
  1690.     If $TRAYNOTIFYIDS[$nID][0] > 0 Then
  1691.         If $TRAYNOTIFYIDS[$nID][7] Then
  1692.             Local $stNID    = DllStructCreate($sNOTIFYICONDATAW)
  1693.             DllStructSetData($stNID, 1, DllStructGetSize($stNID))
  1694.             DllStructSetData($stNID, 2, $TRAYMSGWND)
  1695.             DllStructSetData($stNID, 3, $nID)
  1696.             DllStructSetData($stNID, 4, $NIF_ICON)
  1697.            
  1698.             If $TRAYNOTIFYIDS[$nID][8] Then
  1699.                 DllStructSetData($stNID, 6, $hBlankIcon)
  1700.                 $TRAYNOTIFYIDS[$nID][8] = FALSE
  1701.             Else
  1702.                 DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])
  1703.                 $TRAYNOTIFYIDS[$nID][8] = TRUE
  1704.             EndIf
  1705.            
  1706.             Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
  1707.         EndIf
  1708.     EndIf
  1709.  
  1710.     KillTimer($TRAYMSGWND, $FLASHTIMERID)
  1711.     SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0)    
  1712. EndFunc
  1713.  
  1714.  
  1715. ;********************************************************************
  1716. ; Create a menu item and set its style to OwnerDrawn
  1717. ;********************************************************************
  1718. Func _GUICtrlCreateODMenuItem($sMenuItemText, $nParentMenu, $sIconFile = "", $nIconID = 0, $bRadio = 0)
  1719.     Local $nMenuItem    = GUICtrlCreateMenuItem($sMenuItemText, $nParentMenu, -1, $bRadio)
  1720.    
  1721.     $nIconID = _GetIconID($nIconID, $sIconFile)
  1722.        
  1723.     If $nMenuItem > 0 Then
  1724.         Local $nIdx = _GetNewItemIndex()
  1725.         If $nIdx = 0 Then Return 0
  1726.  
  1727.         $MENULASTITEM = $nMenuItem
  1728.                        
  1729.         Local $hMenu        = GUICtrlGetHandle($nParentMenu)
  1730.        
  1731.         $arMenuItems[$nIdx][0] = $nMenuItem
  1732.         $arMenuItems[$nIdx][1] = $sMenuItemText
  1733.         $arMenuItems[$nIdx][2] = _AddMenuIcon($sIconFile, $nIconID)
  1734.         $arMenuItems[$nIdx][3] = $hMenu
  1735.         $arMenuItems[$nIdx][4] = $bRadio
  1736.         $arMenuItems[$nIdx][5] = FALSE
  1737.         $arMenuItems[$nIdx][6] = -1
  1738.         $arMenuItems[$nIdx][7] = FALSE
  1739.        
  1740.         _SetOwnerDrawn($hMenu, $nMenuItem, $sMenuItemText)
  1741.     EndIf
  1742.        
  1743.     Return $nMenuItem
  1744. EndFunc
  1745.  
  1746.  
  1747. ;********************************************************************
  1748. ; Create a menu and set its style to OwnerDrawn
  1749. ;********************************************************************
  1750. Func _GUICtrlCreateODMenu($sText, $nParentMenu, $sIconFile = "", $nIconID = 0)
  1751.     If $nParentMenu = "" Then
  1752.         Local $nMenu    = GUICtrlCreateMenu($sText)
  1753.     Else
  1754.         Local $nMenu    = GUICtrlCreateMenu($sText, $nParentMenu)
  1755.     EndIf
  1756.    
  1757.     $nIconID = _GetIconID($nIconID, $sIconFile)
  1758.    
  1759.     If $nMenu > 0 Then
  1760.         Local $nIdx = _GetNewItemIndex()
  1761.         If $nIdx = 0 Then Return 0
  1762.        
  1763.         $MENULASTITEM = $nMenu
  1764.        
  1765.         Local $hMenu    = GUICtrlGetHandle($nParentMenu)
  1766.        
  1767.         $arMenuItems[$nIdx][0] = $nMenu
  1768.         $arMenuItems[$nIdx][1] = $sText
  1769.         $arMenuItems[$nIdx][2] = _AddMenuIcon($sIconFile, $nIconID)
  1770.         $arMenuItems[$nIdx][3] = $hMenu
  1771.         $arMenuItems[$nIdx][4] = 0
  1772.         $arMenuItems[$nIdx][5] = FALSE
  1773.         $arMenuItems[$nIdx][6] = -1
  1774.         $arMenuItems[$nIdx][7] = TRUE
  1775.        
  1776.         _SetOwnerDrawn($hMenu, $nMenu, $sText)
  1777.     EndIf
  1778.    
  1779.     Return $nMenu
  1780. EndFunc
  1781.  
  1782. Func _GUICtrlCreateODTopMenu($sText, $nParentGUI)
  1783.     Local $nMenu    = GUICtrlCreateMenu($sText)
  1784.  
  1785.    
  1786.     If $nMenu > 0 Then
  1787.         Local $nIdx = _GetNewItemIndex()
  1788.         If $nIdx = 0 Then Return 0
  1789.        
  1790.         $MENULASTITEM = $nMenu
  1791.         $hMenu = DllCall("User32.dll", "hwnd", "GetMenu", "hwnd", $nParentGUI)
  1792.         If @error Or $hMenu[0]=0 Then Return SetError(1,0,0)
  1793. ;~         GetMenuItemInfo(GUICtrlGetHandle($nMenu)
  1794.         $arMenuItems[$nIdx][0] = $nMenu
  1795.         $arMenuItems[$nIdx][1] = $sText
  1796.         $arMenuItems[$nIdx][2] = -1
  1797.         $arMenuItems[$nIdx][3] = "TOP"
  1798.         $arMenuItems[$nIdx][4] = 0
  1799.         $arMenuItems[$nIdx][5] = FALSE
  1800.         $arMenuItems[$nIdx][6] = -1
  1801.         $arMenuItems[$nIdx][7] = TRUE
  1802.        
  1803.         _SetOwnerDrawn($hMenu[0], $nMenu, $sText)
  1804.         MenuBarBKColor($hMenu[0],$nMenuBkClr)
  1805.     EndIf
  1806.    
  1807.     Return $nMenu
  1808. EndFunc
  1809. Func _GUIMenuBarSetBkColor($nParentGUI,$nMenuBkClr)
  1810.     Local $hMenu = DllCall("User32.dll", "hwnd", "GetMenu", "hwnd", $nParentGUI)
  1811.     If @error Then Return 0
  1812.     Local $r = MenuBarBKColor($hMenu[0],$nMenuBkClr)
  1813.     DllCall("User32.dll", "int", "DrawMenuBar", "hwnd",$nParentGUI)
  1814.     DllCall("User32.dll", "int", "RedrawWindow", "hwnd", $nParentGUI, "ptr", 0, "int", 0, "int", 0x400)
  1815.     Return $r
  1816. EndFunc
  1817.  
  1818. ;********************************************************************
  1819. ; Set the text of an menu item
  1820. ;********************************************************************
  1821. Func _GUICtrlODMenuItemSetText($nMenuID, $sText)
  1822.     If $nMenuID = -1 Then $nMenuID = $MENULASTITEM
  1823.     If $nMenuID <= 0 Then Return 0
  1824.    
  1825.     Local $i
  1826.    
  1827.     For $i = 1 To $arMenuItems[0][0]
  1828.         If $arMenuItems[$i][0] = $nMenuID Then
  1829.             $arMenuItems[$i][1] = $sText
  1830.             _SetOwnerDrawn($arMenuItems[$i][3], $nMenuID, $sText, FALSE)
  1831.             GUICtrlSetData($nMenuID, $sText)
  1832.             _SetOwnerDrawn($arMenuItems[$i][3], $nMenuID, $sText)
  1833.             Return 1
  1834.         EndIf
  1835.     Next
  1836. EndFunc
  1837.  
  1838.  
  1839. ;********************************************************************
  1840. ; Set the icon of an menu item
  1841. ;********************************************************************
  1842. Func _GUICtrlODMenuItemSetIcon($nMenuID, $sIconFile = "", $nIconID = 0)
  1843.     If $nMenuID = -1 Then $nMenuID = $MENULASTITEM
  1844.     If $nMenuID <= 0 Then Return 0
  1845.  
  1846.     $nIconID = _GetIconID($nIconID, $sIconFile)
  1847.    
  1848.     Local $i
  1849.    
  1850.     For $i = 1 To $arMenuItems[0][0]
  1851.         If $arMenuItems[$i][0] = $nMenuID Then
  1852.             If $sIconFile = "" Then
  1853.                 $arMenuItems[$i][2] = -1
  1854.             Else
  1855.                 If $arMenuItems[$i][2] = -1 Then
  1856.                     $arMenuItems[$i][2] = _AddMenuIcon($sIconFile, $nIconID)
  1857.                 Else
  1858.                     _ReplaceMenuIcon($sIconFile, $nIconID, $arMenuItems[$i][2])
  1859.                 EndIf
  1860.             EndIf
  1861.            
  1862.             Return 1
  1863.         EndIf
  1864.     Next
  1865.    
  1866.     Return 0
  1867. EndFunc
  1868.  
  1869.  
  1870. ;********************************************************************
  1871. ; Set the selected icon of an menu item
  1872. ;********************************************************************
  1873. Func _GUICtrlODMenuItemSetSelIcon($nMenuID, $sIconFile = "", $nIconID = 0)
  1874.     If $nMenuID = -1 Then $nMenuID = $MENULASTITEM
  1875.     If $nMenuID <= 0 Then Return 0
  1876.  
  1877.     $nIconID = _GetIconID($nIconID, $sIconFile)
  1878.        
  1879.     Local $i
  1880.    
  1881.     For $i = 1 To $arMenuItems[0][0]
  1882.         If $arMenuItems[$i][0] = $nMenuID Then
  1883.             If $sIconFile = "" Then
  1884.                 $arMenuItems[$i][6] = -1
  1885.             Else
  1886.                 If $arMenuItems[$i][6] = -1 Then
  1887.                     $arMenuItems[$i][6] = _AddMenuIcon($sIconFile, $nIconID)
  1888.                 Else
  1889.                     _ReplaceMenuIcon($sIconFile, $nIconID, $arMenuItems[$i][6])
  1890.                 EndIf
  1891.             EndIf
  1892.            
  1893.             Return 1
  1894.         EndIf
  1895.     Next
  1896.    
  1897.     Return 0
  1898. EndFunc
  1899.  
  1900.  
  1901. ;********************************************************************
  1902. ; Add an icon to our menu image list
  1903. ;********************************************************************
  1904. Func _AddMenuIcon($sIconFile, $nIconID)
  1905.     Local $stIcon    = DllStructCreate("hwnd")
  1906.    
  1907.     Local $nCount    = ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1)
  1908.    
  1909.     Local $nIndex    = -1
  1910.    
  1911.     If $nCount > 0 Then
  1912.         $nIndex    = ImageList_AddIcon($hMenuImageList, DllStructGetData($stIcon, 1))
  1913.         DestroyIcon(DllStructGetData($stIcon, 1))
  1914.     EndIf
  1915.    
  1916.     $stIcon = 0
  1917.    
  1918.     Return $nIndex
  1919. EndFunc
  1920.  
  1921.  
  1922. ;********************************************************************
  1923. ; Replace an icon in our menu image list
  1924. ;********************************************************************
  1925. Func _ReplaceMenuIcon($sIconFile, $nIconID, $nReplaceIndex)
  1926.     If $nReplaceIndex < 0 Then Return -1
  1927.    
  1928.     Local $stIcon    = DllStructCreate("hwnd")
  1929.    
  1930.     Local $nCount    = ExtractIconExW($sIconFile, $nIconID, 0, DllStructGetPtr($stIcon), 1)
  1931.    
  1932.     Local $nIndex    = -1
  1933.    
  1934.     If $nCount > 0 Then
  1935.         ImageList_ReplaceIcon($hMenuImageList, $nReplaceIndex, DllStructGetData($stIcon, 1))
  1936.         DestroyIcon(DllStructGetData($stIcon, 1))
  1937.     EndIf
  1938.    
  1939.     $stIcon = 0
  1940.    
  1941.     Return 1
  1942. EndFunc
  1943.  
  1944.  
  1945. ;********************************************************************
  1946. ; Get the parent menu handle for a menu item
  1947. ;********************************************************************
  1948. Func _GetMenuHandle($nMenuItemID)
  1949.     Local $i, $hMenu = 0
  1950.    
  1951.     For $i = 1 To $arMenuItems[0][0]
  1952.         If $arMenuItems[$i][0] = $nMenuItemID Then
  1953.             $hMenu = $arMenuItems[$i][3]
  1954.             ExitLoop
  1955.         EndIf
  1956.     Next
  1957.    
  1958.     Return $hMenu
  1959. EndFunc
  1960.  
  1961.  
  1962. ;********************************************************************
  1963. ; Get the index of a menu item in our store
  1964. ;********************************************************************
  1965. Func _GetMenuIndex($hMenu, $nMenuItemID)
  1966.     Local $nIndex    = -1
  1967.     Local $nCount    = GetMenuItemCount($hMenu)
  1968.     Local $nPos, $nID
  1969.    
  1970.     For $nPos = 0 To $nCount[0] - 1
  1971.         $nID = GetMenuItemID($hMenu, $nPos)
  1972.         If $nID = $nMenuItemID Then
  1973.             $nIndex = $nPos
  1974.             ExitLoop
  1975.         EndIf
  1976.     Next
  1977.    
  1978.     Return $nIndex
  1979. EndFunc
  1980.  
  1981.  
  1982. ;********************************************************************
  1983. ; Get the menu item text
  1984. ;********************************************************************
  1985. Func _GetMenuText($nMenuItemID)
  1986.     Local $i, $sText = ""
  1987.    
  1988.     For $i = 1 To $arMenuItems[0][0]
  1989.         If $arMenuItems[$i][0] = $nMenuItemID Then
  1990.             $sText = $arMenuItems[$i][1]
  1991.             ExitLoop
  1992.         EndIf
  1993.     Next
  1994.    
  1995.     Return $sText            
  1996. EndFunc
  1997.  
  1998.  
  1999. ;********************************************************************
  2000. ; Creates a menu side
  2001. ;********************************************************************
  2002. Func _CreateSideMenu($nMenuID)
  2003.     If $nMenuID <= 0 Then Return 0
  2004.    
  2005.     Local $hMenu = GUICtrlGetHandle($nMenuID)
  2006.     If $hMenu = 0 Then Return 0
  2007.    
  2008.     Local $i = _GetNewSideItemIndex()
  2009.     If $i = 0 Then Return 0
  2010.    
  2011.     $arSideItems[$i][0] = $hMenu
  2012.     $arSideItems[$i][1] = ""
  2013.     $arSideItems[$i][2] = -1
  2014.     $arSideItems[$i][3] = -1
  2015.     $arSideItems[$i][4] = -1
  2016.     $arSideItems[$i][5] = FALSE
  2017.     $arSideItems[$i][6] = 0
  2018.     $arSideItems[$i][7] = 0
  2019.     $arSideItems[$i][8] = 0
  2020.     $arSideItems[$i][9] = FALSE
  2021.    
  2022.     Return $i
  2023. EndFunc
  2024.  
  2025.  
  2026. ;********************************************************************
  2027. ; Check menu side index
  2028. ;********************************************************************
  2029. Func _IsSideMenuIdx($nIdx)
  2030.     If $nIdx <= 0 Or $nIdx > $arSideItems[0][0] Then Return FALSE
  2031.     If $arSideItems[$nIdx][0] = 0 Then Return FALSE
  2032.    
  2033.     Return TRUE
  2034. EndFunc
  2035.  
  2036.  
  2037. ;********************************************************************
  2038. ; Delete menu side
  2039. ;********************************************************************
  2040. Func _DeleteSideMenu($nIdx)
  2041.     If Not _IsSideMenuIdx($nIdx) Then Return FALSE
  2042.    
  2043.     $arSideItems[$nIdx][0] = 0
  2044.     $arSideItems[$nIdx][1] = ""
  2045.     $arSideItems[$nIdx][2] = -1
  2046.     $arSideItems[$nIdx][3] = -1
  2047.     $arSideItems[$nIdx][4] = -1
  2048.     If $arSideItems[$nIdx][5] And $arSideItems[$nIdx][6] <> 0 Then _
  2049.         DeleteObject($arSideItems[$nIdx][6])
  2050.     $arSideItems[$nIdx][5] = FALSE
  2051.     $arSideItems[$nIdx][6] = 0
  2052.     $arSideItems[$nIdx][7] = 0
  2053.     $arSideItems[$nIdx][8] = 0
  2054.     $arSideItems[$nIdx][9] = FALSE
  2055.    
  2056.     If $nIdx = $arSideItems[0][0] Then $arSideItems[0][0] -= 1
  2057.    
  2058.     Return TRUE
  2059. EndFunc
  2060.  
  2061.  
  2062. ;********************************************************************
  2063. ; Get a menu side index
  2064. ;********************************************************************
  2065. Func _GetSideMenuIndex($hMenu)
  2066.     Local $i
  2067.    
  2068.     For $i = 1 To $arSideItems[0][0]
  2069.         If $arSideItems[$i][0] = $hMenu Then
  2070.             Return $i
  2071.             ExitLoop
  2072.         EndIf
  2073.     Next
  2074.    
  2075.     Return 0            
  2076. EndFunc
  2077.  
  2078.  
  2079. ;********************************************************************
  2080. ; Get a menu side text
  2081. ;********************************************************************
  2082. Func _GetSideMenuText($nIdx)
  2083.     If Not _IsSideMenuIdx($nIdx) Then Return ""
  2084.    
  2085.     Return $arSideItems[$nIdx][1]        
  2086. EndFunc
  2087.  
  2088.  
  2089. ;********************************************************************
  2090. ; Get a menu side image
  2091. ;********************************************************************
  2092. Func _GetSideMenuImage($nIdx)
  2093.     If Not _IsSideMenuIdx($nIdx) Then Return 0
  2094.    
  2095.     If Not $arSideItems[$nIdx][5] Then Return 0
  2096.    
  2097.     Return $arSideItems[$nIdx][6]
  2098. EndFunc
  2099.  
  2100.  
  2101. ;********************************************************************
  2102. ; Get a menu side image dimensions
  2103. ;********************************************************************
  2104. Func _GetSideMenuImageSize($nIdx, ByRef $nWidth, ByRef $nHeight, ByRef $bStretch)
  2105.     If Not _IsSideMenuIdx($nIdx) Then Return FALSE
  2106.    
  2107.     If Not $arSideItems[$nIdx][5] Then Return FALSE
  2108.    
  2109.     $nWidth        = $arSideItems[$nIdx][7]
  2110.     $nHeight    = $arSideItems[$nIdx][8]
  2111.     $bStretch    = $arSideItems[$nIdx][9]
  2112.    
  2113.     Return TRUE
  2114. EndFunc
  2115.  
  2116.  
  2117. ;********************************************************************
  2118. ; Set menu side bitmap
  2119. ;********************************************************************
  2120. Func _SetSideMenuImage($nIdx, $sFile, $sResName = "", $bStretch = FALSE)
  2121.     Return _SetSideMenuText($nIdx, $sFile, $sResName, TRUE, $bStretch)
  2122. EndFunc
  2123.  
  2124.  
  2125. ;********************************************************************
  2126. ; Set menu side text
  2127. ;********************************************************************
  2128. Func _SetSideMenuText($nIdx, $sText, $sResName = "", $bIsBitmap = FALSE, $bStretch = FALSE)
  2129.     If Not _IsSideMenuIdx($nIdx) Then Return FALSE
  2130.    
  2131.     Local $i
  2132.    
  2133.     Local $hBitmap    = 0
  2134.     Local $nW        = 0
  2135.     Local $nH        = 0
  2136.        
  2137.     If $bIsBitmap Then
  2138.         Local $stFile = DllStructCreate("wchar[" & StringLen($sText) + 1 & "]")
  2139.         DllStructSetData($stFile, 1, $sText)
  2140.                
  2141.         If $sResName = "" Then
  2142.             $hBitmap = LoadImageW(0, DllStructGetPtr($stFile), 0, 0, 0, _
  2143.                             BitOr(0x0010, 0x0040, 0x2000, 0x0020))
  2144.         Else
  2145.             Local $hLib = LoadLibraryExW(DllStructGetPtr($stFile), 0, 0x00000002)
  2146.             If $hLib <> 0 Then
  2147.                 If IsNumber($sResName) Then
  2148.                     $hBitmap = LoadImageW($hLib, $sResName, 0, 0, 0, _
  2149.                                     BitOr(0x0040, 0x2000, 0x0020))
  2150.                 Else
  2151.                     Local $stRes = DllStructCreate("wchar[" & StringLen($sResName) + 1 & "]")
  2152.                     DllStructSetData($stRes, 1, $sResName)
  2153.                                        
  2154.                     $hBitmap = LoadImageW($hLib, DllStructGetPtr($stRes), 0, 0, 0, _
  2155.                                     BitOr(0x0040, 0x2000, 0x0020))
  2156.                 EndIf
  2157.                
  2158.                 FreeLibrary($hLib)
  2159.             EndIf
  2160.         EndIf
  2161.                
  2162.         If $hBitmap = 0 Then
  2163.             Return FALSE
  2164.         Else
  2165.             Local $nSize = GetObjectW($hBitmap, 0, 0)
  2166.             Local $stBMP = DllStructCreate("long;long;long;long;ushort;ushort")
  2167.                
  2168.             If GetObjectW($hBitmap, $nSize, DllStructGetPtr($stBMP)) = 0 Then
  2169.                 DeleteObject($hBitmap)
  2170.                 Return FALSE                
  2171.             Else
  2172.                 $nW = DllStructGetData($stBMP, 2)
  2173.                 $nH = DllStructGetData($stBMP, 3)
  2174.             EndIf
  2175.         EndIf
  2176.     EndIf        
  2177.    
  2178.     $arSideItems[$nIdx][1] = $sText
  2179.        
  2180.     If $bIsBitmap Then
  2181.         If $arSideItems[$nIdx][5] <> 0 Then DeleteObject($arSideItems[$nIdx][5])
  2182.         $arSideItems[$nIdx][5] = TRUE
  2183.         $arSideItems[$nIdx][6] = $hBitmap
  2184.         $arSideItems[$nIdx][7] = $nW
  2185.         $arSideItems[$nIdx][8] = $nH
  2186.         If $bStretch Then
  2187.             $arSideItems[$nIdx][9] = TRUE
  2188.         Else
  2189.             $arSideItems[$nIdx][9] = FALSE
  2190.         EndIf
  2191.     Else
  2192.         $arSideItems[$nIdx][5] = FALSE
  2193.         $arSideItems[$nIdx][6] = 0
  2194.     EndIf
  2195.        
  2196.     Return TRUE
  2197. EndFunc
  2198.  
  2199.  
  2200. ;********************************************************************
  2201. ; Set menu side colors
  2202. ;********************************************************************
  2203. Func _SetSideMenuColors($nIdx, $nColor = -1, $nBkColor = -1, $nBkGrdColor = -1)
  2204.     If Not _IsSideMenuIdx($nIdx) Then Return FALSE
  2205.    
  2206.     If $nColor <> -1 Then
  2207.         If $nColor = -2 Then
  2208.             $arSideItems[$nIdx][2] = $nMenuSideTxtClr
  2209.         Else
  2210.             $arSideItems[$nIdx][2] = $nColor
  2211.         EndIf
  2212.     EndIf
  2213.            
  2214.     If $nBkColor <> -1 Then
  2215.         If $nBkColor = -2 Then
  2216.             $arSideItems[$nIdx][3] = $nMenuSideBkClr
  2217.         Else
  2218.             $arSideItems[$nIdx][3] = $nBkColor
  2219.         EndIf
  2220.     EndIf
  2221.            
  2222.     If $nBkGrdColor <> -1 Then
  2223.         If $nBkGrdColor = -2 Then
  2224.             $arSideItems[$nIdx][4] = $nMenuSideBkClr2
  2225.         Else
  2226.             $arSideItems[$nIdx][4] = $nBkGrdColor
  2227.         EndIf
  2228.     EndIf
  2229.            
  2230.     Return 1    
  2231. EndFunc
  2232.  
  2233.  
  2234. ;********************************************************************
  2235. ; Get menu side colors
  2236. ;********************************************************************
  2237. Func _GetSideMenuColors($nIdx, ByRef $nColor, ByRef $nBkColor, ByRef $nBkGradColor)
  2238.     If $nIdx = 0 Then Return 0
  2239.    
  2240.     $nColor            = $arSideItems[$nIdx][2]
  2241.     $nBkColor        = $arSideItems[$nIdx][3]
  2242.     $nBkGradColor    = $arSideItems[$nIdx][4]
  2243.    
  2244.     Return 1
  2245. EndFunc
  2246.  
  2247.  
  2248. ;********************************************************************
  2249. ; Get the maximum text width in a menu
  2250. ;********************************************************************
  2251. Func _GetMenuMaxTextWidth($hDC, $hMenu, ByRef $nMaxWidth, ByRef $nMaxAccWidth)
  2252.     Local $i, $stSize, $stText, $nLen, $nAccLen
  2253.     Local $nWidth        = 0
  2254.     Local $nAccWidth    = 0
  2255.     Local $arString
  2256.    
  2257.     For $i = 1 To $arMenuItems[0][0]
  2258.         If $arMenuItems[$i][3] = $hMenu Then
  2259.             $arString = StringSplit($arMenuItems[$i][1], @Tab)
  2260.             If Not IsArray($arString) Then ContinueLoop
  2261.            
  2262.             If $arString[0] > 1 Then
  2263.                 $nLen    = StringLen($arString[2])
  2264.                 $stSize    = DllStructCreate("int;int")
  2265.                
  2266.                 $stText = DllStructCreate("wchar[" & $nLen + 1 & "]")
  2267.                 DllStructSetData($stText, 1, $arString[2])
  2268.                
  2269.                 GetTextExtentPoint32W($hDC, DllStructGetPtr($stText), $nLen, DllStructGetPtr($stSize))
  2270.                
  2271.                 $nAccWidth = DllStructGetData($stSize, 1)
  2272.                 $stText    = 0
  2273.                 $stSize    = 0
  2274.                
  2275.                 If $nAccWidth > $nMaxAccWidth Then $nMaxAccWidth = $nAccWidth            
  2276.             EndIf
  2277.            
  2278.             $nLen    = StringLen($arString[1])
  2279.             $stSize    = DllStructCreate("int;int")
  2280.            
  2281.             $stText = DllStructCreate("wchar[" & $nLen + 1 & "]")
  2282.             DllStructSetData($stText, 1, $arString[1])
  2283.            
  2284.             GetTextExtentPoint32W($hDC, DllStructGetPtr($stText), $nLen, DllStructGetPtr($stSize))
  2285.                    
  2286.             $nWidth = DllStructGetData($stSize, 1)
  2287.             $stText    = 0
  2288.             $stSize    = 0
  2289.            
  2290.             If $nWidth > $nMaxWidth Then $nMaxWidth = $nWidth
  2291.         EndIf
  2292.     Next
  2293. EndFunc
  2294.  
  2295.  
  2296. ;********************************************************************
  2297. ; Get the maximum side text width
  2298. ;********************************************************************
  2299. Func _GetSideMenuTextWidth($hDC, $sText)
  2300.     If $sText = "" Then Return 0
  2301.    
  2302.     Local $nLen        = StringLen($sText)
  2303.     Local $stSize    = DllStructCreate("int;int")
  2304.     Local $stText    = DllStructCreate("wchar[" & $nLen + 1 & "]")
  2305.     DllStructSetData($stText, 1, $sText)
  2306.                
  2307.     GetTextExtentPoint32W($hDC, DllStructGetPtr($stText), $nLen, DllStructGetPtr($stSize))
  2308.                
  2309.     Return DllStructGetData($stSize, 2)
  2310. EndFunc
  2311.  
  2312.  
  2313. ;********************************************************************
  2314. ; Get the index of an icon from our store
  2315. ;********************************************************************
  2316. Func _GetMenuIsRadio($nMenuItemID)
  2317.     Local $i, $bRadio = 0
  2318.    
  2319.     For $i = 1 To $arMenuItems[0][0]
  2320.         If $arMenuItems[$i][0] = $nMenuItemID Then
  2321.             $bRadio = $arMenuItems[$i][4]
  2322.             ExitLoop
  2323.         EndIf
  2324.     Next
  2325.    
  2326.     Return $bRadio            
  2327. EndFunc
  2328.  
  2329.  
  2330. ;********************************************************************
  2331. ; Get the index of an icon from our store
  2332. ;********************************************************************
  2333. Func _GetMenuIconIndex($nMenuItemID, ByRef $nIconIndex, ByRef $nSelIconIndex)
  2334.     Local $i
  2335.    
  2336.     For $i = 1 To $arMenuItems[0][0]
  2337.         If $arMenuItems[$i][0] = $nMenuItemID Then
  2338.             $nIconIndex = $arMenuItems[$i][2]
  2339.             $nSelIconIndex = $arMenuItems[$i][6]
  2340.             ExitLoop
  2341.         EndIf
  2342.     Next
  2343. EndFunc
  2344.  
  2345.  
  2346. ;********************************************************************
  2347. ; Check if the item is from a tray menu
  2348. ;********************************************************************
  2349. Func _IsTrayItem($nMenuItemID)
  2350.     Local $i, $bTray = FALSE
  2351.    
  2352.     For $i = 1 To $arMenuItems[0][0]
  2353.         If $arMenuItems[$i][0] = $nMenuItemID Then
  2354.             $bTray = $arMenuItems[$i][5]
  2355.             ExitLoop
  2356.         EndIf
  2357.     Next
  2358.    
  2359.     Return $bTray            
  2360. EndFunc
  2361.  
  2362.  
  2363. ;********************************************************************
  2364. ; Get some system menu constants
  2365. ;********************************************************************
  2366. Func _GetMenuInfos(ByRef $nS, ByRef $nX)
  2367.     $nS    = GetSystemMetrics(49)
  2368.     $nX    = GetSystemMetrics(71)
  2369. EndFunc
  2370.  
  2371.  
  2372. ;********************************************************************
  2373. ; Convert a normal menu item to an ownerdrawn menu item
  2374. ;********************************************************************
  2375. Func _SetOwnerDrawn($hMenu, $MenuItemID, $sText, $bOwnerDrawn = TRUE)
  2376.     Local $nType = 0 ; MF_STRING
  2377.    
  2378.     If StringLen($sText) = 0 Then $nType = 0x00000800
  2379.    
  2380.     If $bOwnerDrawn Then $nType = BitOr($nType, 0x00000100)
  2381.    
  2382.     Local $stMII = DllStructCreate($sMENUITEMINFO)
  2383.     DllStructSetData($stMII, 1, DllStructGetSize($stMII))
  2384.     DllStructSetData($stMII, 2, 0x00000010) ; MIIM_TYPE
  2385.     DllStructSetData($stMII, 3, $nType)
  2386.    
  2387.     Local $stTypeData = DllStructCreate("uint")
  2388.     DllStructSetData($stTypeData, 1, $MenuItemID)
  2389.     DllStructSetData($stMII, 10, DllStructGetPtr($stTypeData))
  2390.    
  2391.     SetMenuItemInfo($hMenu, $MenuItemID, FALSE, DllStructGetPtr($stMII))
  2392. EndFunc
  2393.  
  2394.  
  2395. ;********************************************************************
  2396. ; Get the default menu font
  2397. ;********************************************************************
  2398. Func _CreateMenuFont(ByRef $hFont, $bBold = FALSE, $bSide = FALSE)
  2399.     Local $stNCM = DllStructCreate($sNONCLIENTMETRICS)
  2400.     DllStructSetData($stNCM, 1, DllStructGetSize($stNCM))
  2401.    
  2402.     If SystemParametersInfo(0x0029, DllStructGetSize($stNCM), DllStructGetPtr($stNCM), 0) Then
  2403.         Local $stMenuLogFont = DllStructCreate($sLOGFONT)
  2404.        
  2405.         Local $i            
  2406.         For $i = 1 To 14
  2407.             DllStructSetData($stMenuLogFont, $i, DllStructGetData($stNCM, $i + 38))
  2408.         Next
  2409.        
  2410.         If $bSide Then
  2411.             DllStructSetData($stMenuLogFont, 3, 900)
  2412.             DllStructSetData($stMenuLogFont, 4, 900)
  2413.         EndIf
  2414.        
  2415.         If $bBold Then DllStructSetData($stMenuLogFont, 5, 700)
  2416.        
  2417.         If $hFont > 0 Then DeleteObject($hFont)
  2418.                
  2419.         $hFont = CreateFontIndirect(DllStructGetPtr($stMenuLogFont))
  2420.         If $hFont = 0 Then $hFont = _CreateMenuFontByName("MS Sans Serif")
  2421.     EndIf
  2422. EndFunc
  2423.  
  2424.  
  2425. Func _CreateMenuFontByName($sFontName, $nHeight = 8, $nWidth = 400)
  2426.     Local $stFontName = DllStructCreate("char[260]")
  2427.     DllStructSetData($stFontName, 1, $sFontName)
  2428.    
  2429.     Local $hDC        = GetDC(0) ; Get the Desktops DC
  2430.     Local $nPixel    = GetDeviceCaps($hDC, 90)
  2431.    
  2432.     $nHeight    = 0 - MulDiv($nHeight, $nPixel, 72)
  2433.        
  2434.     ReleaseDC(0, $hDC)
  2435.    
  2436.     Local $hFont = CreateFont($nHeight, _
  2437.                                 0, _
  2438.                                 0, _
  2439.                                 0, _
  2440.                                 $nWidth, _
  2441.                                 0, _
  2442.                                 0, _
  2443.                                 0, _
  2444.                                 0, _
  2445.                                 0, _
  2446.                                 0, _
  2447.                                 0, _
  2448.                                 0, _
  2449.                                 DllStructGetPtr($stFontName))
  2450.  
  2451.     $stFontName = 0
  2452.    
  2453.     Return $hFont
  2454. EndFunc
  2455.  
  2456.  
  2457. ;********************************************************************
  2458. ; Create a blank icon for flash functionality
  2459. ;********************************************************************
  2460. Func _CreateBlankIcon()
  2461.     If $hBlankIcon = 0 Then
  2462.         If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
  2463.             Local $stIcon = DllStructCreate("hwnd")
  2464.            
  2465.             If ExtractIconExW("shell32.dll", 50, 0, DllStructGetPtr($stIcon), 1) Then _
  2466.                 $hBlankIcon = DllStructGetData($stIcon, 1)
  2467.         Else
  2468.             Local $stAndMask = DllStructCreate("byte[64]")
  2469.             memset(DllStructGetPtr($stAndMask), 0xFF, 64)
  2470.  
  2471.             Local $stXorMask = DllStructCreate("byte[64]")
  2472.             memset(DllStructGetPtr($stXorMask), 0x0, 64)
  2473.    
  2474.             $hBlankIcon = CreateIcon(0, 16, 16, 1, 1, DllStructGetPtr($stAndMask), DllStructGetPtr($stXorMask))
  2475.         EndIf
  2476.     EndIf
  2477.    
  2478.     Return $hBlankIcon
  2479. EndFunc
  2480.  
  2481.  
  2482. ;********************************************************************
  2483. ; CommCtrl.h - functions
  2484. ;********************************************************************
  2485. Func ImageList_Create($nImageWidth, $nImageHeight, $nFlags, $nInitial, $nGrow)
  2486.     Local $hImageList = DllCall($hComctl32Dll, "hwnd", "ImageList_Create", _
  2487.                                                         "int", $nImageWidth, _
  2488.                                                         "int", $nImageHeight, _
  2489.                                                         "int", $nFlags, _
  2490.                                                         "int", $nInitial, _
  2491.                                                         "int", $nGrow)
  2492.     Return $hImageList[0]
  2493. EndFunc
  2494.  
  2495.  
  2496. Func ImageList_AddIcon($hIml, $hIcon)
  2497.     Local $nIndex = DllCall($hComctl32Dll, "int", "ImageList_AddIcon", _
  2498.                                                     "hwnd", $hIml, _
  2499.                                                     "hwnd", $hIcon)
  2500.     Return $nIndex[0]
  2501. EndFunc
  2502.  
  2503.  
  2504. Func ImageList_Destroy($hIml)
  2505.     Local $bResult = DllCall($hComctl32Dll, "int", "ImageList_Destroy", _
  2506.                                                     "hwnd", $hIml)
  2507.     Return $bResult[0]
  2508. EndFunc
  2509.  
  2510.  
  2511. Func ImageList_Draw($hIml, $nIndex, $hDC, $nX, $nY, $nStyle)
  2512.     Local $bResult = DllCall($hComctl32Dll, "int", "ImageList_Draw", _
  2513.                                                     "hwnd", $hIml, _
  2514.                                                     "int", $nIndex, _
  2515.                                                     "hwnd", $hDC, _
  2516.                                                     "int", $nX, _
  2517.                                                     "int", $nY, _
  2518.                                                     "int", $nStyle)
  2519.     Return $bResult[0]
  2520. EndFunc
  2521.  
  2522.  
  2523. Func ImageList_DrawEx($hIml, $nIndex, $hDC, $nX, $nY, $nDx, $nDy, $nBkClr, $nFgClr, $nStyle)
  2524.     Local $bResult = DllCall($hComctl32Dll, "int", "ImageList_DrawEx", _
  2525.                                                     "hwnd", $hIml, _
  2526.                                                     "int", $nIndex, _
  2527.                                                     "hwnd", $hDC, _
  2528.                                                     "int", $nX, _
  2529.                                                     "int", $nY, _
  2530.                                                     "int", $nDx, _
  2531.                                                     "int", $nDy, _
  2532.                                                     "int", $nBkClr, _
  2533.                                                     "int", $nFgClr, _
  2534.                                                     "int", $nStyle)
  2535.     Return $bResult[0]
  2536. EndFunc
  2537.  
  2538.  
  2539. Func ImageList_ReplaceIcon($hIml, $nIndex, $hIcon)
  2540.     Local $bResult = DllCall($hComctl32Dll, "int", "ImageList_ReplaceIcon", _
  2541.                                                     "hwnd", $hIml, _
  2542.                                                     "int", $nIndex, _
  2543.                                                     "hwnd", $hIcon)
  2544.     Return $bResult[0]
  2545. EndFunc
  2546.  
  2547.  
  2548. ;********************************************************************
  2549. ; ShellApi.h - functions
  2550. ;********************************************************************
  2551. Func ExtractIconExW($sIconFile, $nIconID, $ptrIconLarge, $ptrIconSmall, $nIcons)
  2552.     Local $nCount = DllCall($hShell32Dll, "int", "ExtractIconExW", _
  2553.                                                 "wstr", $sIconFile, _
  2554.                                                 "int", $nIconID, _
  2555.                                                 "ptr", $ptrIconLarge, _
  2556.                                                 "ptr", $ptrIconSmall, _
  2557.                                                 "int", $nIcons)
  2558.     Return $nCount[0]
  2559. EndFunc
  2560.  
  2561.  
  2562. Func Shell_NotifyIcon($nMessage, $pNID)
  2563.     Local $nResult = DllCall($hShell32Dll, "int", "Shell_NotifyIconW", _
  2564.                                                     "int", $nMessage, _
  2565.                                                     "ptr", $pNID)
  2566.     Return $nResult[0]
  2567. EndFunc
  2568.  
  2569.  
  2570. ;********************************************************************
  2571. ; WinBase.h - functions
  2572. ;********************************************************************
  2573. Func MulDiv($nInt1, $nInt2, $nInt3)
  2574.     $nResult = DllCall("kernel32.dll", "int", "MulDiv", _
  2575.                                             "int", $nInt1, _
  2576.                                             "int", $nInt2, _
  2577.                                             "int", $nInt3)
  2578.     Return $nResult[0]
  2579. EndFunc
  2580.  
  2581.  
  2582. Func LoadLibraryExW($pFile, $hFile, $nFlags)
  2583.     $hResult = DllCall($hKernel32Dll, "hwnd", "LoadLibraryExW", _
  2584.                                                 "ptr", $pFile, _
  2585.                                                 "hwnd", $hFile, _
  2586.                                                 "dword", $nFlags)
  2587.     Return $hResult[0]
  2588. EndFunc
  2589.  
  2590.  
  2591. Func FreeLibrary($hLib)
  2592.     $nResult = DllCall($hKernel32Dll, "int", "FreeLibrary", _
  2593.                                                 "hwnd", $hLib)
  2594.     Return $nResult[0]
  2595. EndFunc
  2596.  
  2597.  
  2598. ;********************************************************************
  2599. ; WinGDI.h - functions
  2600. ;********************************************************************
  2601. Func SelectObject($hDC, $hObj)
  2602.     Local $hOldObj = DllCall($hGdi32Dll, "int", "SelectObject", _
  2603.                                                 "hwnd", $hDC, _
  2604.                                                 "hwnd", $hObj)
  2605.     Return $hOldObj[0]
  2606. EndFunc
  2607.  
  2608.  
  2609. Func DeleteObject($hObj)
  2610.     Local $bResult = DllCall($hGdi32Dll, "int", "DeleteObject", _
  2611.                                                 "hwnd", $hObj)
  2612.     Return $bResult[0]
  2613. EndFunc
  2614.  
  2615.  
  2616. Func GetObjectW($hObj, $nSize, $pObj)
  2617.     Local $nResult = DllCall($hGdi32Dll, "int", "GetObjectW", _
  2618.                                                 "hwnd", $hObj, _
  2619.                                                 "int", $nSize, _
  2620.                                                 "ptr", $pObj)
  2621.     Return $nResult[0]
  2622. EndFunc
  2623.  
  2624.  
  2625. Func CreateFont($nHeight, $nWidth, $nEscape, $nOrientn, $fnWeight, $bItalic, $bUnderline, $bStrikeout, $nCharset, $nOutputPrec, $nClipPrec, $nQuality, $nPitch, $ptrFontName)
  2626.     Local $hFont = DllCall($hGdi32Dll, "hwnd", "CreateFont", _
  2627.                                                 "int", $nHeight, _
  2628.                                                 "int", $nWidth, _
  2629.                                                 "int", $nEscape, _
  2630.                                                 "int", $nOrientn, _
  2631.                                                 "int", $fnWeight, _
  2632.                                                 "long", $bItalic, _
  2633.                                                 "long", $bUnderline, _
  2634.                                                 "long", $bStrikeout, _
  2635.                                                 "long", $nCharset, _
  2636.                                                 "long", $nOutputPrec, _
  2637.                                                 "long", $nClipPrec, _
  2638.                                                 "long", $nQuality, _
  2639.                                                 "long", $nPitch, _
  2640.                                                 "ptr", $ptrFontName)
  2641.     Return $hFont[0]
  2642. EndFunc
  2643.  
  2644.  
  2645. Func CreateFontIndirect($pLogFont)
  2646.     Local $hFont = DllCall($hGdi32Dll, "hwnd", "CreateFontIndirectW", _
  2647.                                                 "ptr", $pLogFont)
  2648.     Return $hFont[0]
  2649. EndFunc
  2650.  
  2651.  
  2652. Func GetTextExtentPoint32W($hDC, $ptrText, $nTextLength, $ptrSize)
  2653.     Local $bResult = DllCall($hGdi32Dll, "int", "GetTextExtentPoint32W", _
  2654.                                                 "hwnd" ,$hDC, _
  2655.                                                 "ptr", $ptrText, _
  2656.                                                 "int", $nTextLength, _
  2657.                                                 "ptr", $ptrSize)
  2658.     Return $bResult[0]
  2659. EndFunc
  2660.  
  2661.  
  2662. Func SetBkColor($hDC, $nColor)
  2663.     Local $nOldColor = DllCall($hGdi32Dll, "int", "SetBkColor", _
  2664.                                                 "hwnd", $hDC, _
  2665.                                                 "int", $nColor)
  2666.     Return $nOldColor[0]
  2667. EndFunc
  2668.  
  2669.  
  2670. Func SetTextColor($hDC, $nColor)
  2671.     Local $nOldColor = DllCall($hGdi32Dll, "int", "SetTextColor", _
  2672.                                                 "hwnd", $hDC, _
  2673.                                                 "int", $nColor)
  2674.     Return $nOldColor[0]
  2675. EndFunc
  2676.  
  2677.  
  2678. Func CreateSolidBrush($nColor)
  2679.     Local $hBrush = DllCall($hGdi32Dll, "hwnd", "CreateSolidBrush", _
  2680.                                                 "int", $nColor)
  2681.     Return $hBrush[0]
  2682. EndFunc
  2683.  
  2684.  
  2685. Func GetDeviceCaps($hDC, $nIndex)
  2686.     Local $nResult = DllCall($hGdi32Dll, "int", "GetDeviceCaps", _
  2687.                                                 "hwnd", $hDC, _
  2688.                                                 "int", $nIndex)
  2689.     Return $nResult[0]
  2690. EndFunc
  2691.  
  2692.  
  2693. Func CreateCompatibleDC($hDC)
  2694.     Local $hCompDC = DllCall($hGdi32Dll, "hwnd", "CreateCompatibleDC", _
  2695.                                                 "hwnd", $hDC)
  2696.     Return $hCompDC[0]
  2697. EndFunc
  2698.  
  2699.  
  2700. Func DeleteDC($hDC)
  2701.     Local $bResult = DllCall($hGdi32Dll, "int", "DeleteDC", _
  2702.                                                 "hwnd", $hDC)
  2703.     Return $bResult[0]
  2704. EndFunc
  2705.  
  2706.  
  2707. Func CreateBitmap($nWidth, $nHeight, $nCPlanes, $nCBitsPerPixel, $ptrCData)
  2708.     Local $hBitmap = DllCall($hGdi32Dll, "hwnd", "CreateBitmap", _
  2709.                                                 "int", $nWidth, _
  2710.                                                 "int", $nHeight, _
  2711.                                                 "int", $nCPlanes, _
  2712.                                                 "int", $nCBitsPerPixel, _
  2713.                                                 "ptr", $ptrCData)
  2714.     Return $hBitmap[0]
  2715. EndFunc
  2716.  
  2717.  
  2718. Func BitBlt($hDCDest, $nXDest, $nYDest, $nWDest, $nHDest, $hDCSrc, $nXSrc, $nYSrc, $nOpCode)
  2719.     Local $bResult = DllCall($hGdi32Dll, "int", "BitBlt", _
  2720.                                                 "hwnd", $hDCDest, _
  2721.                                                 "int", $nXDest, _
  2722.                                                 "int", $nYDest, _
  2723.                                                 "int", $nWDest, _
  2724.                                                 "int", $nHDest, _
  2725.                                                 "hwnd", $hDCSrc, _
  2726.                                                 "int", $nXSrc, _
  2727.                                                 "int", $nYSrc, _
  2728.                                                 "long", $nOpCode)
  2729.     Return $bResult[0]
  2730. EndFunc
  2731.  
  2732.  
  2733. Func StretchBlt($hDCDest, $nXDest, $nYDest, $nWDest, $nHDest, $hDCSrc, $nXSrc, $nYSrc, $nWSrc, $nHSrc, $nOpCode)
  2734.     Local $bResult = DllCall($hGdi32Dll, "int", "StretchBlt", _
  2735.                                                 "hwnd", $hDCDest, _
  2736.                                                 "int", $nXDest, _
  2737.                                                 "int", $nYDest, _
  2738.                                                 "int", $nWDest, _
  2739.                                                 "int", $nHDest, _
  2740.                                                 "hwnd", $hDCSrc, _
  2741.                                                 "int", $nXSrc, _
  2742.                                                 "int", $nYSrc, _
  2743.                                                 "int", $nWSrc, _
  2744.                                                 "int", $nHSrc, _
  2745.                                                 "long", $nOpCode)
  2746.     Return $bResult[0]
  2747. EndFunc
  2748.  
  2749.  
  2750. Func SetBkMode($hDC, $nMode)
  2751.     Local $nResult = DllCall($hGdi32Dll, "int", "SetBkMode", _
  2752.                                                 "hwnd", $hDC, _
  2753.                                                 "int", $nMode)
  2754.     Return $nResult[0]
  2755. EndFunc
  2756.  
  2757.  
  2758. Func GradientFill($hDC, $pVert, $nNumVert, $pRect, $nNumRect, $nFillMode)
  2759.     Local $nResult = DllCall($hMsimg32Dll, "int", "GradientFill", _
  2760.                                                     "hwnd", $hDC, _
  2761.                                                     "ptr", $pVert, _
  2762.                                                     "ulong", $nNumVert, _
  2763.                                                     "ptr", $pRect, _
  2764.                                                     "ulong", $nNumRect, _
  2765.                                                     "ulong", $nFillMode)
  2766.     Return $nResult[0]
  2767. EndFunc
  2768.  
  2769.  
  2770. ;********************************************************************
  2771. ; WinUser.h - functions
  2772. ;********************************************************************
  2773. Func GetDC($hWnd)
  2774.     Local $hDC = DllCall($hUser32Dll, "hwnd", "GetDC", _
  2775.                                             "hwnd", $hWnd)
  2776.     Return $hDC[0]
  2777. EndFunc
  2778.  
  2779.  
  2780. Func ReleaseDC($hWnd, $hDC)
  2781.     Local $bResult = DllCall($hUser32Dll, "int", "ReleaseDC", _
  2782.                                                 "hwnd", $hWnd, _
  2783.                                                 "hwnd", $hDC)
  2784.     Return $bResult[0]
  2785. EndFunc
  2786.  
  2787.  
  2788. Func GetSysColor($nIndex)
  2789.     Local $nColor = DllCall($hUser32Dll, "int", "GetSysColor", _
  2790.                                                 "int", $nIndex)
  2791.     Return $nColor[0]
  2792. EndFunc
  2793.  
  2794.  
  2795. Func GetSysColorBrush($nIndex)
  2796.     Local $hBrush = DllCall($hUser32Dll, "hwnd", "GetSysColorBrush", _
  2797.                                                 "int", $nIndex)
  2798.     Return $hBrush[0]
  2799. EndFunc
  2800.  
  2801.  
  2802. Func LoadIcon($hInstance, $nIcon)
  2803.     Local $hIcon = DllCall($hUser32Dll, "hwnd", "LoadIcon", _
  2804.                                                 "hwnd", $hInstance, _
  2805.                                                 "int", $nIcon)
  2806.     Return $hIcon[0]
  2807. EndFunc
  2808.  
  2809.  
  2810. Func DestroyIcon($hIcon)
  2811.     Local $bResult = DllCall($hUser32Dll, "int", "DestroyIcon", _
  2812.                                                 "hwnd", $hIcon)
  2813.     Return $bResult[0]
  2814. EndFunc
  2815.  
  2816.  
  2817. Func CreateIcon($hInstance, $nWidth, $nHeight, $nPlanes, $nBitsPixel, $pAndBits, $pXorBits)
  2818.     Local $hResult = DllCall($hUser32Dll, "hwnd", "CreateIcon", _
  2819.                                                     "hwnd", $hInstance, _
  2820.                                                     "int", $nWidth, _
  2821.                                                     "int", $nHeight, _
  2822.                                                     "byte", $nPlanes, _
  2823.                                                     "byte", $nBitsPixel, _
  2824.                                                     "ptr", $pAndBits, _
  2825.                                                     "ptr", $pXorBits)
  2826.     Return $hResult[0]
  2827. EndFunc
  2828.  
  2829.  
  2830. Func GetSystemMetrics($nIndex)
  2831.     Local $nResult = DllCall($hUser32Dll, "int", "GetSystemMetrics", _
  2832.                                                 "int", $nIndex)
  2833.     Return $nResult[0]
  2834. EndFunc
  2835.  
  2836.  
  2837. Func DrawTextW($hDC, $ptrText, $nLenText, $ptrRect, $nFlags)
  2838.     Local $nHeight = DllCall($hUser32Dll, "int", "DrawTextW", _
  2839.                                                 "hwnd", $hDC, _
  2840.                                                 "ptr", $ptrText, _
  2841.                                                 "int", $nLenText, _
  2842.                                                 "ptr", $ptrRect, _
  2843.                                                 "int", $nFlags)
  2844.     Return $nHeight[0]
  2845. EndFunc
  2846.  
  2847.  
  2848. Func GetMenuItemCount($hMenu)
  2849.     Local $nCount = DllCall($hUser32Dll, "int", "GetMenuItemCount", _
  2850.                                                 "hwnd", $hMenu)
  2851.     Return $nCount[0]
  2852. EndFunc
  2853.  
  2854.  
  2855. Func GetMenuItemID($hMenu, $nPos)
  2856.     Local $nID = DllCall($hUser32Dll, "int", "GetMenuItemID", _
  2857.                                             "hwnd", $hMenu, _
  2858.                                             "int", $nPos)
  2859.     Return $nID[0]
  2860. EndFunc
  2861.  
  2862.  
  2863. Func GetMenuItemInfo($hMenu, $nID, $bPos, $pMII)
  2864.     Local $nResult = DllCall($hUser32Dll, "int", "GetMenuItemInfo", _
  2865.                                                 "hwnd", $hMenu, _
  2866.                                                 "uint", $nID, _
  2867.                                                 "int", $bPos, _
  2868.                                                 "ptr", $pMII)
  2869.     Return $nResult[0]
  2870. EndFunc
  2871.  
  2872.  
  2873. Func SetMenuItemInfo($hMenu, $nID, $bPos, $pMII)
  2874.     Local $nResult = DllCall($hUser32Dll, "int", "SetMenuItemInfo", _
  2875.                                                 "hwnd", $hMenu, _
  2876.                                                 "uint", $nID, _
  2877.                                                 "int", $bPos, _
  2878.                                                 "ptr", $pMII)
  2879.     Return $nResult[0]
  2880. EndFunc
  2881.  
  2882.  
  2883. Func GetMenuState($hMenu, $nID, $nFlags)
  2884.     Local $nState = DllCall($hUser32Dll, "int", "GetMenuState", _
  2885.                                                 "hwnd", $hMenu, _
  2886.                                                 "int", $nID, _
  2887.                                                 "int", $nFlags)
  2888.     Return $nState[0]
  2889. EndFunc
  2890.  
  2891.                                            
  2892. Func FillRect($hDC, $ptrRect, $hBrush)
  2893.     Local $bResult = DllCall($hUser32Dll, "int", "FillRect", _
  2894.                                                 "hwnd", $hDC, _
  2895.                                                 "ptr", $ptrRect, _
  2896.                                                 "hwnd", $hBrush)
  2897.     Return $bResult[0]
  2898. EndFunc
  2899.  
  2900.  
  2901. Func DrawEdge($hDC, $ptrRect, $nEdgeType, $nBorderFlag)
  2902.     Local $bResult = DllCall($hUser32Dll, "int", "DrawEdge", _
  2903.                                                 "hwnd", $hDC, _
  2904.                                                 "ptr", $ptrRect, _
  2905.                                                 "int", $nEdgeType, _
  2906.                                                 "int", $nBorderFlag)
  2907.     Return $bResult[0]
  2908. EndFunc
  2909.  
  2910.  
  2911. Func FrameRect($hDC, $ptrRect, $hBrush)
  2912.     Local $bResult = DllCall($hUser32Dll, "int", "FrameRect", _
  2913.                                                 "hwnd", $hDC, _
  2914.                                                 "ptr", $ptrRect, _
  2915.                                                 "hwnd", $hBrush)
  2916.     Return $bResult[0]
  2917. EndFunc
  2918.  
  2919.  
  2920. Func DrawFrameControl($hDC, $ptrRect, $nType, $nState)
  2921.     Local $bResult = DllCall($hUser32Dll, "int", "DrawFrameControl", _
  2922.                                                 "hwnd", $hDC, _
  2923.                                                 "ptr", $ptrRect, _
  2924.                                                 "int", $nType, _
  2925.                                                 "int", $nState)
  2926.     Return $bResult[0]
  2927. EndFunc
  2928.  
  2929.  
  2930. Func SystemParametersInfo($nAction, $nParam, $pParam, $nWinini)
  2931.     Local $nResult = DllCall($hUser32Dll, "int", "SystemParametersInfoW", _
  2932.                                                 "uint", $nAction, _
  2933.                                                 "uint", $nParam, _
  2934.                                                 "ptr", $pParam, _
  2935.                                                 "uint", $nWinini)
  2936.     Return $nResult[0]
  2937. EndFunc
  2938.  
  2939.  
  2940. Func GetCursorPos($pPoint)
  2941.     Local $nResult = DllCall($hUser32Dll, "int", "GetCursorPos", _
  2942.                                             "ptr", $pPoint)
  2943.     Return $nResult[0]
  2944. EndFunc
  2945.  
  2946.  
  2947. Func SetForegroundWindow($hWnd)
  2948.     Local $nResult = DllCall($hUser32Dll, "int", "SetForegroundWindow", _
  2949.                                                     "hwnd", $hWnd)
  2950.     Return $nResult[0]
  2951. EndFunc
  2952.  
  2953.  
  2954. Func TrackPopupMenuEx($hMenu, $nFlags, $nX, $nY, $hWnd, $pParams)
  2955.     Local $nResult = DllCall($hUser32Dll, "int", "TrackPopupMenuEx", _
  2956.                                                     "hwnd", $hMenu, _
  2957.                                                     "uint", $nFlags, _
  2958.                                                     "int", $nX, _
  2959.                                                     "int", $nY, _
  2960.                                                     "hwnd", $hWnd, _
  2961.                                                     "ptr", $pParams)    
  2962.     Return $nResult[0]
  2963. EndFunc
  2964.  
  2965.  
  2966. Func PostMessage($hWnd, $nMsg, $wParam, $lParam)
  2967.     Local $nResult = DllCall($hUser32Dll, "int", "PostMessage", _
  2968.                                                     "hwnd", $hWnd, _
  2969.                                                     "uint", $nMsg, _
  2970.                                                     "dword", $wParam, _
  2971.                                                     "dword", $lParam)
  2972.     Return $nResult[0]
  2973. EndFunc
  2974.  
  2975.  
  2976. Func ShowWindow($hWnd, $nState)
  2977.     DllCall($hUser32Dll, "int", "ShowWindow", _
  2978.                                 "hwnd", $hWnd, _
  2979.                                 "int", $nState)
  2980. EndFunc
  2981.  
  2982.  
  2983. Func SetTimer($hWnd, $nID, $nTimeOut, $pFunc)
  2984.     Local $nResult = DllCall($hUser32Dll, "uint", "SetTimer", _
  2985.                                                     "hwnd", $hWnd, _
  2986.                                                     "uint", $nID, _
  2987.                                                     "uint", $nTimeOut, _
  2988.                                                     "ptr", $pFunc)
  2989.     Return $nResult[0]
  2990. EndFunc
  2991.  
  2992.  
  2993. Func KillTimer($hWnd, $nID)
  2994.     Local $nResult = DllCall($hUser32Dll, "int", "KillTimer", _
  2995.                                                     "hwnd", $hWnd, _
  2996.                                                     "uint", $nID)
  2997.     Return $nResult[0]
  2998. EndFunc
  2999.  
  3000.  
  3001. Func LoadImageW($hInst, $pName, $nType, $nX, $nY, $nLoad)
  3002.     Local $hResult = DllCall($hUser32Dll, "hwnd", "LoadImageW", _
  3003.                                                     "hwnd", $hInst, _
  3004.                                                     "dword", $pName, _
  3005.                                                     "uint", $nType, _
  3006.                                                     "int", $nX, _
  3007.                                                     "int", $nY, _
  3008.                                                     "uint", $nLoad)    
  3009.     Return $hResult[0]
  3010. EndFunc
  3011.  
  3012.  
  3013. Func memset($pDest, $nChr, $nCount)
  3014.     Local $pResult = DllCall("msvcrt.dll", "ptr:cdecl", "memset", _
  3015.                                                         "ptr", $pDest, _
  3016.                                                         "int", $nChr, _
  3017.                                                         "int", $nCount)
  3018.     Return $pResult[0]
  3019. EndFunc
  3020.  
  3021.  
  3022. Func MenuBarBKColor($hMenu, $nColor)
  3023.     Local $tInfo,$aResult
  3024.     Local $hBrush = DllCall('gdi32.dll', 'hwnd', 'CreateSolidBrush', 'int', $nColor)
  3025.     If @error Then Return
  3026.     $tInfo = DllStructCreate("int Size;int Mask;int Style;int YMax;int hBack;int ContextHelpID;ptr MenuData")
  3027.     DllStructSetData($tInfo, "Mask", 2)
  3028.     DllStructSetData($tInfo, "hBack", $hBrush[0])
  3029.     DllStructSetData($tInfo, "Size", DllStructGetSize($tInfo))
  3030.     $aResult = DllCall("User32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "ptr", DllStructGetPtr($tInfo))
  3031.     Return $aResult[0] <> 0
  3032. EndFunc   ;==>_GUICtrlMenu_SetMenuBackground
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement