PageRenderTime 72ms CodeModel.GetById 39ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/Tooltip.ahk

http://7plus.googlecode.com/
AutoHotKey | 680 lines | 445 code | 28 blank | 207 comment | 32 complexity | 0a1a032617082233859ccbfee56b9680 MD5 | raw file
  1/* 
  2ToolTip() by HotKeyIt http://www.autohotkey.com/forum/viewtopic.php?t=40165 
  3
  4Syntax: ToolTip(Number,Text,Title,Options) 
  5
  6Return Value: ToolTip returns hWnd of the ToolTip 
  7
  8|-------------------------------------------------------------------------------------------------------------------| 
  9|         Options can include any of following parameters separated by space 
 10|-------------------------------------------------------------------------------------------------------------------| 
 11| Option   |      Meaning 
 12|-------------------------------------------------------------------------------------------------------------------| 
 13| A      |   Aim ConrolId or ClassNN (Button1, Edit2, ListBox1, SysListView321...) 
 14|         |   - using this, ToolTip will be shown when you point mouse on a control 
 15|         |   - D (delay) can be used to change how long ToolTip is shown 
 16|         |   - W (wait) can wait for specified seconds before ToolTip will be shown 
 17|         |   - Some controls like Static require a subroutine to have a ToolTip!!! 
 18|-------------------------------------------------------------------------------------------------------------------| 
 19| B + F   |   Specify here the color for ToolTip in 6-digit hexadecimal RGB code 
 20|         |   - B = Background color, F = Foreground color (text color) 
 21|         |   - this can be 0x00FF00 or 00FF00 or Blue, Lime, Black, White... 
 22|-------------------------------------------------------------------------------------------------------------------| 
 23| C      |   Close button for ToolTip/BalloonTip. See ToolTip actions how to use it 
 24|-------------------------------------------------------------------------------------------------------------------| 
 25| D      |   Delay. This option will determine how long ToolTip should be shown.30 sec. is maximum 
 26|         |   - this option is also available when assigning the ToolTip to a control. 
 27|-------------------------------------------------------------------------------------------------------------------| 
 28| E      |   Edges for ToolTip, Use this to set margin of ToolTip window (space between text and border) 
 29|         |   - Supply Etop.left.bottom.right in pixels, for example: E10.0.10.5 
 30|-------------------------------------------------------------------------------------------------------------------| 
 31| G      |   Execute one or more internal Labels of ToolTip function only. 
 32|         |   For example: 
 33|         |   - Track the position only, use ToolTip(1,"","","Xcaret Ycaret gTTM_TRACKPOSITION") 
 34|         |      - When X+Y are empty (= display near mouse position) you can use TTM_UPDATE 
 35|         |   - Update text only, use ToolTip(1,"text","","G1"). Note specify L1 if links are used. 
 36|         |   - Update title only, use ToolTip(1,"","Title","G1") 
 37|         |   - Hide ToolTip, use ToolTip(1,"","","gTTM_POP") 
 38|         |      - To show ToolTip again use ToolTip(1,"","","gTTM_TRACKPOSITION.TTM_TRACKACTIVATE") 
 39|         |   - Update background color + text color, specify . between gLabels to execute several: 
 40|         |      - ToolTip(1,"","","BBlue FWhite gTTM_SETTIPBKCOLOR.TTM_SETTIPTEXTCOLOR") 
 41|         |   - Following labels can be used: TTM_SETTITLEA + TTM_SETTITLEW (title+I), TTM_POPUP, TTM_POP 
 42|         |     TTM_SETTIPBKCOLOR (B), TTM_SETTIPTEXTCOLOR (F), TTM_TRACKPOSITION (N+X+Y), 
 43|         |     TTM_SETMAXTIPWIDTH (R), TTM_SETMARGIN (E), TT_SETTOOLINFO (text+A+P+N+X+Y+S+L) 
 44|         |     TTM_SETWINDOWTHEME (Q) 
 45|-------------------------------------------------------------------------------------------------------------------| 
 46| H      |   Hide ToolTip after a link is clicked.See L option 
 47|-------------------------------------------------------------------------------------------------------------------| 
 48| I      |   Icon 1-3, e.g. I1. If this option is missing no Icon will be used (same as I0) 
 49|         |   - 1 = Info, 2 = Warning, 3 = Error, > 3 is meant to be a hIcon (handle to an Icon) 
 50|         |   Use Included MI_ExtractIcon and GetAssociatedIcon functions to get hIcon 
 51|-------------------------------------------------------------------------------------------------------------------| 
 52| J      |   Justify ToolTip to center of control 
 53|-------------------------------------------------------------------------------------------------------------------| 
 54| L      |   Links for ToolTips. See ToolTip actions how Links for ToolTip work. 
 55|-------------------------------------------------------------------------------------------------------------------| 
 56| M      |   Mouse click-trough. So a click will be forwarded to the window underneath ToolTip 
 57|-------------------------------------------------------------------------------------------------------------------| 
 58| N      |   Do NOT activate ToolTip (N1), To activate (show) call ToolTip(1,"","","gTTM_TRACKACTIVATE") 
 59|-------------------------------------------------------------------------------------------------------------------| 
 60| O      |   Oval ToolTip (BalloonTip). Specify O1 to use a BalloonTip instead of ToolTip. 
 61|-------------------------------------------------------------------------------------------------------------------| 
 62| P      |   Parent window hWnd or GUI number. This will assign a ToolTip to a window. 
 63|         |   - Reqiered to assign ToolTip to controls and actions. 
 64|-------------------------------------------------------------------------------------------------------------------| 
 65| Q      |   Quench Style/Theme. Use this to disable Theme of ToolTip. 
 66|         |   Using this option you can have for example colored ToolTips in Vista. 
 67|-------------------------------------------------------------------------------------------------------------------| 
 68| R      |   Restrict width. This will restrict the width of the ToolTip. 
 69|         |   So if Text is to long it will be shown in several lines 
 70|-------------------------------------------------------------------------------------------------------------------| 
 71| S      |   Show at coordinates regardless of position. Specify S1 to use that feature 
 72|         |   - normally it is fed automaticaly to show on screen 
 73|-------------------------------------------------------------------------------------------------------------------| 
 74| T      |   Transparency. This option will apply Transparency to a ToolTip. 
 75|         |   - this option is not available to ToolTips assigned to a control. 
 76|-------------------------------------------------------------------------------------------------------------------| 
 77| V      |   Visible: even when the parent window is not active, a control-ToolTip will be shown 
 78|-------------------------------------------------------------------------------------------------------------------| 
 79| W      |   Wait time in seconds (max 30) before ToolTip pops up when pointing on one of controls. 
 80|-------------------------------------------------------------------------------------------------------------------| 
 81| X + Y   |   Coordinates where ToolTip should be displayed, e.g. X100 Y200 
 82|         |   - leave empty to display ToolTip near mouse 
 83|         |   - you can specify Xcaret Ycaret to display at caret coordinates 
 84|-------------------------------------------------------------------------------------------------------------------| 
 85| 
 86|          To destroy a ToolTip use ToolTip(Number), to destroy all ToolTip() 
 87| 
 88|-------------------------------------------------------------------------------------------------------------------| 
 89|               ToolTip Actions (NOTE, OPTION P MUST BE PRESENT TO USE THAT FEATURE) 
 90|-------------------------------------------------------------------------------------------------------------------| 
 91|      Assigning an action to a ToolTip to works using OnMessage(0x4e,"Function") - WM_NOTIFY 
 92|      Parameter/option P must be present so ToolTip will forward messages to script 
 93|      All you need to do inside this OnMessage function is to include: 
 94|         - If wParam=0 
 95|            ToolTip("",lParam[,Label]) 
 96| 
 97|      Additionally you need to have one or more of following labels in your script 
 98|      - ToolTip: when clicking a link 
 99|      - ToolTipClose: when closing ToolTip 
100|         - You can also have a diferent label for one or all ToolTips 
101|         - Therefore enter the number of ToolTip in front of the label 
102|            - e.g. 99ToolTip: or 1ToolTipClose: 
103| 
104|      - Those labels names can be customized as well 
105|         - e.g. ToolTip("",lParam,"MyTip") will use MyTip: and MyTipClose: 
106|         - you can enter the number of ToolTip in front of that label as well. 
107| 
108|      - Links have following syntax: 
109|         - <a>Link</a> or <a link>LinkName</a> 
110|         - When a Link is clicked, ToolTip() will jump to the label 
111|            - Variable ErrorLevel will contain clicked link 
112| 
113|         - So when only LinkName is given, e.g. <a>AutoHotkey</a> Errorlevel will be AutoHotkey 
114|         - When using Link is given as well, e.g. <a http://www.autohotkey.com>AutoHotkey</a> 
115|            - Errorlevel will be set to http://www.autohotkey.com 
116| 
117|-------------------------------------------------------------------------------------------------------------------| 
118|      Please note some options like Close Button and Links will require Win2000++ (+version 6.0 of comctl32.dll) 
119|        AutoHotKey Version 1.0.48++ is required due to "assume static mode" 
120|        If you use 1 ToolTip for several controls, the only difference between those can be the text. 
121|           - Rest, like Title, color and so on, will be valid globally 
122|-------------------------------------------------------------------------------------------------------------------| 
123|      Example for LinkClick and ToolTip close! 
124|-------------------------------------------------------------------------------------------------------------------| 
125         OnMessage(0x201,"WM_LBUTTONDOWN") ;Will make ToolTip Click possible 
126         WM_LBUTTONDOWN(wParam,lParam,msg,hWnd){ 
127            If tt%hwnd% { 
128               MsgBox, 262148,ToolTip Clicked, Close ToolTip 
129               IfMsgBox Yes 
130                  ToolTip(tt%hwnd%) 
131            } 
132         } 
133         OnMessage(0x4e,"WM_NOTIFY") ;Will make LinkClick and ToolTipClose possible 
134         WM_NOTIFY(wParam, lParam, msg, hWnd){ 
135            ToolTip("",lParam,"") 
136         } 
137         Sleep, 10 
138         ToolTip(1,"<a>Click</a>`n<a>Onother one</a>`n" 
139         . "<a This link is different`nit uses different text>Different</a>`n" 
140         . "<a>ExitApp</a>","ClickMe","L1 P99 C1") 
141         hwnd:=ToolTip(2,"Click me anywhere!","Click Me","P99 C1") 
142         tt%hwnd%:= 1 
143         Return 
144          
145         ToolTip: 
146         link:=ErrorLevel 
147         SetTimer, MsgBox, -10 
148         Return 
149
150         ToolTipClose: 
151         ExitApp 
152
153         MsgBox: 
154         If Link=ExitApp 
155            ExitApp 
156         MsgBox % Link 
157         Return 
158|-------------------------------------------------------------------------------------------------------------------| 
159|      Example for dynamic text! 
160|-------------------------------------------------------------------------------------------------------------------| 
161      OnMessage(0x4e,"WM_NOTIFY") 
162      Gui,Add,Button,,Time 
163      Gui,Add,Button,,Username 
164      Gui,Add,Button,,User is Admin? 
165      Gui,Add,Button,,IP addresses 
166      Loop 4 
167         ToolTip("Button1"," ","","p1 aButton" . A_Index) 
168      gui,show 
169      Sleep, 3000 
170      Return 
171
172      WM_NOTIFY(wParam,lParam){ 
173         If (control:=ToolTip("",lparam)){ 
174            Tool:=ErrorLevel 
175            MouseGetPos,,,,ClassNN 
176            If (ClassNN="Button1"){ 
177               FormatTime,text,%A_Now%,HH:mm:ss 
178               Title:="Time" 
179            } else if (ClassNN="Button2"){ 
180               text:=A_UserName,title:="UserName" 
181            } else if (ClassNN="Button3"){ 
182               text:=(A_ISAdmin ? "Yes" : "No"),title:="User is Admin?" 
183            } else if (ClassNN="Button4"){ 
184               text:= "1: " A_IPAddress1 "`n2: " A_IPAddress2 "`n3: " A_IPAddress3 "`n4: " A_IPAddress4 
185               title:="IP Addresses" 
186            } 
187            ToolTip(control,text,title,"G1 A" . Tool . " I" (ClassNN="Button1" ? "2" : "1")) 
188         } 
189      } 
190
191      GuiClose: 
192      ExitApp 
193|-------------------------------------------------------------------------------------------------------------------| 
194*/ 
195
196ToolTip(ID="", text="", title="",options=""){ 
197   ;____  Assume Static Mode for internal variables and structures  ____ 
198    
199   static 
200   ;________________________  ToolTip Messages  ________________________ 
201    
202   static TTM_POPUP:=0x422,         TTM_ADDTOOL:=0x404,        TTM_UPDATETIPTEXT:=0x40c 
203   ,TTM_POP:=0x41C,           TTM_DELTOOL:=0x405,        TTM_GETBUBBLESIZE:=0x41e 
204   ,TTM_UPDATE:=0x41D,        TTM_SETTOOLINFO:=0x409,      TTN_FIRST:=0xfffffdf8 
205   ,TTM_TRACKPOSITION:=0x412,    TTM_SETTIPBKCOLOR:=0x413,   TTM_SETTIPTEXTCOLOR:=0x414 
206   ,TTM_SETTITLEA:=0x420,      TTM_SETTITLEW:=0x421,      TTM_SETMARGIN:=0x41a 
207   ,TTM_SETWINDOWTHEME:=0x200b,   TTM_SETMAXTIPWIDTH:=0x418, TTM_NEWTOOLRECT:=0x406 
208    
209   ;_______________Remote Buffer Messages for TrayIcon pos______________ 
210    
211   ;MEM_COMMIT:=0x1000,       PAGE_READWRITE:=4,          MEM_RELEASE:=0x8000 
212    
213   ;________________________  ToolTip colors  ________________________ 
214    
215   ,Black:=0x000000,    Green:=0x008000,      Silver:=0xC0C0C0 
216   ,Lime:=0x00FF00,      Gray:=0x808080,          Olive:=0x808000 
217   ,White:=0xFFFFFF,    Yellow:=0xFFFF00,      Maroon:=0x800000 
218    ,Navy:=0x000080,      Red:=0xFF0000,          Blue:=0x0000FF 
219   ,Purple:=0x800080,   Teal:=0x008080,         Fuchsia:=0xFF00FF 
220    ,Aqua:=0x00FFFF 
221   ,RemoteBuf:="RemoteBuf" 
222
223   ;________________________  Local variables for options ________________________ 
224    
225   local option,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,v,w,x,y,xc,yc,xw,yw,update,RECT 
226    
227   If ((#_DetectHiddenWindows:=A_DetectHiddenWindows)="Off") 
228      DetectHiddenWindows, On 
229    
230   ;____________________________  Delete all ToolTips or return link _____________ 
231
232   If !ID 
233   { 
234      If text 
235         If text is Xdigit 
236            GoTo, TTN_LINKCLICK 
237      Loop, Parse, hWndArray, % Chr(2) ;Destroy all ToolTip Windows 
238      { 
239         If WinExist("ahk_id " . A_LoopField) 
240            DllCall("DestroyWindow","Uint",A_LoopField) 
241         hWndArray%A_LoopField%= 
242      } 
243      hWndArray= 
244      Loop, Parse, idArray, % Chr(2) ;Destroy all ToolTip Structures 
245      { 
246         TT_ID:=A_LoopField 
247         If TT_ALL_%TT_ID% 
248            Gosub, TT_DESTROY 
249      } 
250      idArray= 
251      DetectHiddenWindows,%#_DetectHiddenWindows% 
252      Return 
253   } 
254    
255   TT_ID:=ID 
256   TT_HWND:=TT_HWND_%TT_ID% 
257    
258   ;___________________  Load Options Variables and Structures ___________________ 
259    
260   If (options){ 
261      Loop,Parse,options,%A_Space% 
262         If (option:= SubStr(A_LoopField,1,1)) 
263            %option%:= SubStr(A_LoopField,2) 
264   } 
265   If (G){ 
266      If (Title!=""){ 
267         Gosub, TTM_SETTITLEA 
268         Gosub, TTM_UPDATE 
269      } 
270      If (Text!=""){ 
271         If (A!="") 
272            ID:=A 
273         If (InStr(text,"<a") and L){ 
274            TOOLTEXT_%TT_ID%:=text 
275            text:=RegExReplace(text,"<a\K[^<]*?>",">") 
276         } else 
277            TOOLTEXT_%TT_ID%:= 
278         If (ID=TT_ID and !TOOLINFO_%TT_ID%){ 
279            Loop,Parse,TT_ALL_%TT_ID%,% Chr(2) 
280               If (TOOLINFO_%A_LoopField%){ 
281                  ID:=A_LoopField 
282                  NumPut(&text,TOOLINFO_%ID%,36) 
283                  Gosub, TTM_UPDATETIPTEXT 
284                  Gosub, TTM_UPDATE 
285                  Loop, Parse,G,. 
286                     If IsLabel(A_LoopField) 
287                        Gosub, %A_LoopField% 
288               } 
289            DetectHiddenWindows,%#_DetectHiddenWindows% 
290            Return 
291         } else { 
292            NumPut(&text,TOOLINFO_%ID%,36) 
293            Gosub, TTM_UPDATETIPTEXT 
294            Gosub, TTM_UPDATE 
295         } 
296      } 
297      Loop, Parse,G,. 
298         If IsLabel(A_LoopField) 
299            Gosub, %A_LoopField% 
300      DetectHiddenWindows,%#_DetectHiddenWindows% 
301      Return 
302   } 
303   ;__________________________  Save TOOLINFO Structures _________________________ 
304    
305   If P { 
306      If (p<100 and !WinExist("ahk_id " p)){ 
307         Gui,%p%:+LastFound 
308         P:=WinExist() 
309      } 
310      If !InStr(TT_ALL_%TT_ID%,Chr(2) . Abs(P) . Chr(2)) 
311         TT_ALL_%TT_ID% .= Chr(2) . Abs(P) . Chr(2) 
312   } 
313   If !InStr(TT_ALL_%TT_ID%,Chr(2) . ID . Chr(2)) 
314      TT_ALL_%TT_ID% .= Chr(2) . ID . Chr(2) 
315   If H 
316      TT_HIDE_%TT_ID%:=1 
317   ;__________________________  Create ToolTip Window  __________________________ 
318    
319   If (!TT_HWND and text) 
320   { 
321      TT_HWND := DllCall("CreateWindowEx", "Uint", 0x8, "str", "tooltips_class32", "str", "", "Uint", 0x02 + (v ? 0x1 : 0) + (l ? 0x100 : 0) + (C ? 0x80 : 0)+(O ? 0x40 : 0), "int", 0x80000000, "int", 0x80000000, "int", 0x80000000, "int", 0x80000000, "Uint", P ? P : 0, "Uint", 0, "Uint", 0, "Uint", 0) 
322      TT_HWND_%TT_ID%:=TT_HWND 
323      hWndArray.=(hWndArray ? Chr(2) : "") . TT_HWND 
324      idArray.=(idArray ? Chr(2) : "") . TT_ID 
325      Gosub, TTM_SETMAXTIPWIDTH 
326      DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 2, "Uint", (D ? D*1000 : -1)) ;TTDT_AUTOPOP 
327      DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 3, "Uint", (W ? W*1000 : -1)) ;TTDT_INITIAL 
328      DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x403, "Uint", 1, "Uint", (W ? W*1000 : -1)) ;TTDT_RESHOW 
329   } else if (!text and !options){ 
330      DllCall("DestroyWindow","Uint",TT_HWND) 
331      TT_HWND_%TT_ID%= 
332      Gosub, TT_DESTROY 
333      DetectHiddenWindows,%#_DetectHiddenWindows% 
334      Return 
335   } 
336    
337   ;______________________  Create TOOLINFO Structure  ______________________ 
338    
339   Gosub, TT_SETTOOLINFO 
340
341   If (Q!="") 
342      Gosub, TTM_SETWINDOWTHEME 
343   If (E!="") 
344      Gosub, TTM_SETMARGIN 
345   If (F!="") 
346      Gosub, TTM_SETTIPTEXTCOLOR 
347   If (B!="") 
348      Gosub, TTM_SETTIPBKCOLOR 
349   If (title!="") 
350      Gosub, TTM_SETTITLEA 
351    
352   If (!A){ 
353      Gosub, TTM_UPDATETIPTEXT 
354      Gosub, TTM_UPDATE 
355      If D { 
356         A_Timer := A_TickCount, D *= 1000 
357         Gosub, TTM_TRACKPOSITION 
358         Gosub, TTM_TRACKACTIVATE 
359         Loop 
360         { 
361            Gosub, TTM_TRACKPOSITION 
362            If (A_TickCount - A_Timer > D) 
363               Break 
364         } 
365         Gosub, TT_DESTROY 
366         DllCall("DestroyWindow","Uint",TT_HWND) 
367         TT_HWND_%TT_ID%= 
368      } else { 
369         Gosub, TTM_TRACKPOSITION 
370         Gosub, TTM_TRACKACTIVATE 
371         If T 
372            WinSet,Transparent,%T%,ahk_id %TT_HWND% 
373         If M 
374            WinSet,ExStyle,^0x20,ahk_id %TT_HWND% 
375      } 
376   } 
377
378   ;________  Restore DetectHiddenWindows and return HWND of ToolTip  ________ 
379
380   DetectHiddenWindows, %#_DetectHiddenWindows% 
381   ErrorLevel:=ID 
382   Return TT_HWND 
383    
384   ;________________________  Internal Labels  ________________________ 
385    
386   TTM_POP:    ;Hide ToolTip 
387   TTM_POPUP:    ;Causes the ToolTip to display at the coordinates of the last mouse message. 
388   TTM_UPDATE: ;Forces the current tool to be redrawn. 
389      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", 0) 
390   Return 
391   TTM_TRACKACTIVATE: ;Activates or deactivates a tracking ToolTip. 
392   DllCall("SendMessage", "Uint", TT_HWND, "Uint", 0x411, "Uint", (N ? 0 : 1), "Uint", &TOOLINFO_%ID%) 
393   Return 
394   TTM_UPDATETIPTEXT: 
395   TTM_GETBUBBLESIZE: 
396   TTM_ADDTOOL: 
397   TTM_DELTOOL: 
398   TTM_SETTOOLINFO: 
399   TTM_NEWTOOLRECT: 
400      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &TOOLINFO_%ID%) 
401   Return 
402   TTM_SETTITLEA: 
403   TTM_SETTITLEW: 
404      title := (StrLen(title) < 96) ? title : ("&#x2026;" . SubStr(title, -97)) 
405      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", I, "Uint", &Title) 
406   Return 
407   TTM_SETWINDOWTHEME: 
408      If Q 
409         DllCall("uxtheme\SetWindowTheme", "Uint", TT_HWND, "Uint", 0, "UintP", 0) 
410      else 
411         DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &Q) 
412   Return 
413   TTM_SETMAXTIPWIDTH: 
414      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", R ? R : A_ScreenWidth) 
415   Return 
416   TTM_TRACKPOSITION: 
417      VarSetCapacity(xc, 20, 0), xc := Chr(20) 
418      DllCall("GetCursorInfo", "Uint", &xc) 
419      yc := NumGet(xc,16), xc := NumGet(xc,12) 
420      xc+=15,yc+=15 
421      If (x="caret" or y="caret"){ 
422         WinGetPos,xw,yw,,,A 
423         If x=caret 
424         { 
425            SysGet,xl,76 
426            SysGet,xr,78 
427            xc:=xw+A_CaretX +1 
428            xc:=(xl>xc ? xl : (xr<xc ? xr : xc)) 
429         } 
430         If (y="caret"){ 
431            SysGet,yl,77 
432            SysGet,yr,79 
433            yc:=yw+A_CaretY+15 
434            yc:=(yl>yc ? yl : (yr<yc ? yr : yc)) 
435         } 
436      } else if (x="TrayIcon" or y="TrayIcon"){ 
437         Process, Exist 
438         PID:=ErrorLevel 
439         hWndTray:=WinExist("ahk_class Shell_TrayWnd") 
440         ControlGet,hWndToolBar,Hwnd,,ToolbarWindow321,ahk_id %hWndTray% 
441         If (Isfunc(RemoteBuf . "_Open") and Isfunc(RemoteBuf . "_Read") and Isfunc(RemoteBuf . "_Close") and Isfunc(RemoteBuf . "_Get")){ 
442            %RemoteBuf%_Open(TrayH,hWndToolBar,20) 
443            DataH:=NumGet(TrayH,0) 
444            SendMessage, 0x418,0,0,,ahk_id %hWndToolBar% 
445            Loop % ErrorLevel 
446            { 
447               SendMessage,0x417,A_Index-1,%RemoteBuf%_Get(TrayH),,ahk_id %hWndToolBar% 
448               %RemoteBuf%_Read(TrayH,lpData,20) 
449               VarSetCapacity(dwExtraData,8) 
450               pwData:=NumGet(lpData,12) 
451               DllCall( "ReadProcessMemory", "uint", DataH, "uint", pwData, "uint", &dwExtraData, "uint", 8, "uint", 0 ) 
452               BWID:=NumGet(dwExtraData,0) 
453               WinGet,BWPID,PID, ahk_id %BWID% 
454               If (BWPID!=PID) 
455                  continue 
456               SendMessage, 0x41d,A_Index-1,%RemoteBuf%_Get(TrayH),,ahk_id %hWndToolBar% 
457               %RemoteBuf%_Read(TrayH,rcPosition,20) 
458               ControlGetPos,xc,yc,xw,yw,Button2,ahk_id %hWndTray% 
459               If (NumGet(lpData,8)>7){ 
460                  ControlGetPos,xc,yc,xw,yw,Button2,ahk_id %hWndTray% 
461                  xc+=xw/2, yc+=yw/4 
462               } else { 
463                  ControlGetPos,xc,yc,,,ToolbarWindow321,ahk_id %hWndTray% 
464                  halfsize:=NumGet(rcPosition,12)/2 
465                  xc+=NumGet(rcPosition,0)+ halfsize 
466                  yc+=NumGet(rcPosition,4)+ (halfsize/2) 
467               } 
468               WinGetPos,xw,yw,,,ahk_id %hWndTray% 
469               xc+=xw,yc+=yw 
470               break 
471            } 
472            %RemoteBuf%_close(TrayH) 
473         } else 
474            ControlGetPos,xc,yc,,,ToolbarWindow321,ahk_id %hWndTray% 
475      } 
476      If (!x and !y) 
477         Gosub, TTM_UPDATE 
478      else if !WinActive("ahk_id " . TT_HWND) 
479         DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", (x<9999999 ? x : xc & 0xFFFF)|(y<9999999 ? y : yc & 0xFFFF)<<16) 
480   Return 
481   TTM_SETTIPBKCOLOR: 
482      If B is alpha 
483         If (%b%) 
484            B:=%b% 
485      B := (StrLen(B) < 8 ? "0x" : "") . B 
486      B := ((B&255)<<16)+(((B>>8)&255)<<8)+(B>>16) ; rgb -> bgr 
487      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", B, "Uint", 0) 
488   Return 
489   TTM_SETTIPTEXTCOLOR: 
490      If F is alpha 
491         If (%F%) 
492            F:=%f% 
493      F := (StrLen(F) < 8 ? "0x" : "") . F 
494      F := ((F&255)<<16)+(((F>>8)&255)<<8)+(F>>16) ; rgb -> bgr 
495      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint",F & 0xFFFFFF, "Uint", 0) 
496   Return 
497   TTM_SETMARGIN: 
498      VarSetCapacity(RECT,16) 
499      Loop,Parse,E,. 
500         NumPut(A_LoopField,RECT,(A_Index-1)*4) 
501      DllCall("SendMessage", "Uint", TT_HWND, "Uint", %A_ThisLabel%, "Uint", 0, "Uint", &RECT) 
502   Return 
503   TT_SETTOOLINFO: 
504      If A { 
505         If A is not Xdigit 
506            ControlGet,A,Hwnd,,%A%,ahk_id %P% 
507         ID :=Abs(A) 
508         If !InStr(TT_ALL_%TT_ID%,Chr(2) . ID . Chr(2)) 
509            TT_ALL_%TT_ID% .= Chr(2) . ID . Chr(2) . ID+Abs(P) . Chr(2) 
510         If !TOOLINFO_%ID% 
511            VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40) 
512         else 
513            Gosub, TTM_DELTOOL 
514         Numput((N ? 0 : 1)|(J ? 2 : 0)|16,TOOLINFO_%ID%,4),Numput(P,TOOLINFO_%ID%,8),Numput(ID,TOOLINFO_%ID%,12) 
515         If (text!="") 
516            NumPut(&text,TOOLINFO_%ID%,36) 
517         Gosub, TTM_ADDTOOL 
518         ID :=ID+Abs(P) 
519         If !TOOLINFO_%ID% 
520         { 
521            VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40) 
522            Numput(0|16,TOOLINFO_%ID%,4), Numput(P,TOOLINFO_%ID%,8), Numput(P,TOOLINFO_%ID%,12) 
523         } 
524         Gosub, TTM_ADDTOOL 
525         ID :=Abs(A) 
526      } else { 
527         If !TOOLINFO_%ID% 
528            VarSetCapacity(TOOLINFO_%ID%, 40, 0),TOOLINFO_%ID%:=Chr(40) 
529         If (text!=""){ 
530            If InStr(text,"<a"){ 
531               TOOLTEXT_%ID%:=text 
532               text:=RegExReplace(text,"<a\K[^<]*?>",">") 
533            } else 
534               TOOLTEXT_%ID%:= 
535            NumPut(&text,TOOLINFO_%ID%,36) 
536         } 
537         NumPut((J ? 2 : 0)|(!(x . y) ? 0 : 0x20)|(S ? 0x80 : 0)|(L ? 0x1000 : 0x100),TOOLINFO_%ID%,4), Numput(P,TOOLINFO_%ID%,8), Numput(P,TOOLINFO_%ID%,12) 
538         Gosub, TTM_ADDTOOL 
539      } 
540   Return 
541   TTN_LINKCLICK: 
542      Loop 4 
543         m += *(text + 8 + A_Index-1) << 8*(A_Index-1) 
544      If !(TTN_FIRST-1=m or TTN_FIRST-2=m or TTN_FIRST-3=m) 
545         Return 
546      Loop 4 
547         p += *(text + A_Index-1) << 8*(A_Index-1) 
548      If (TTN_FIRST-3=m) 
549         Loop 4 
550            option += *(text + 16 + A_Index-1) << 8*(A_Index-1) 
551      Loop,Parse,hWndArray,% Chr(2) 
552         If (p=A_LoopField and i:=A_Index) 
553            break 
554      Loop,Parse,idArray,% Chr(2) 
555      { 
556         If (i=A_Index){ 
557            If (TTN_FIRST-1=m){ 
558               Loop 4 
559                  ErrorLevel += *(text + 4 + A_Index-1) << 8*(A_Index-1) 
560               Return A_LoopField 
561            } 
562            text:=TOOLTEXT_%A_LoopField% 
563            If (TTN_FIRST-2=m){ 
564               If Title 
565               { 
566                  If IsLabel(A_LoopField . title . "Close") 
567                     Gosub % A_LoopField . title . "Close" 
568                  else If IsLabel(title . "Close") 
569                     Gosub % title . "Close" 
570               } else { 
571                  If IsLabel(A_LoopField . A_ThisFunc . "Close") 
572                     Gosub % A_LoopField . A_ThisFunc . "Close" 
573                  else If IsLabel(A_ThisFunc . "Close") 
574                     Gosub % A_ThisFunc . "Close" 
575               } 
576            } else If (InStr(TOOLTEXT_%A_LoopField%,"<a")){ 
577               Loop % option+1 
578                  StringTrimLeft,text,text,% InStr(text,"<a")+1 
579               If TT_HIDE_%A_LoopField% 
580                  ToolTip(A_LoopField,"","","gTTM_POP") 
581               If ((a:=A_AutoTrim)="Off") 
582                  AutoTrim, On 
583               ErrorLevel:=SubStr(text,1,InStr(text,">")-1) 
584               StringTrimLeft,text,text,% InStr(text,">") 
585               text:=SubStr(text,1,InStr(text,"</a>")-1) 
586               If !ErrorLevel 
587                  ErrorLevel:=text 
588               ErrorLevel=%ErrorLevel% 
589               AutoTrim, %a% 
590               If Title 
591               { 
592                  If IsFunc(f:=(A_LoopField . title)) 
593                     %f%(ErrorLevel) 
594                  else if IsLabel(A_LoopField . title) 
595                     Gosub % A_LoopField . title 
596                  else if IsFunc(title) 
597                     %title%(ErrorLevel) 
598                  else If IsLabel(title) 
599                     Gosub, %title% 
600               } else { 
601                  if IsFunc(f:=(A_LoopField . A_ThisFunc)) 
602                     %f%(ErrorLevel) 
603                  else If IsLabel(A_LoopField . A_ThisFunc) 
604                     Gosub % A_LoopField . A_ThisFunc 
605                  else If IsLabel(A_ThisFunc) 
606                     Gosub % A_ThisFunc 
607               } 
608            } 
609            break 
610         } 
611      } 
612      DetectHiddenWindows, %#_DetectHiddenWindows% 
613   Return 
614   TT_DESTROY: 
615      Loop, Parse, TT_ALL_%TT_ID%,% Chr(2) 
616         If A_LoopField 
617         { 
618            ID:=A_LoopField 
619            Gosub, TTM_DELTOOL 
620            TOOLINFO_%A_LoopField%:="", TT_HWND_%A_LoopField%:="", TOOLTEXT_%A_LoopField%:="", TT_HIDE_%A_LoopField%:="" 
621         } 
622      TT_ALL_%TT_ID%= 
623   Return 
624} 
625
626MI_ExtractIcon(Filename, IconNumber, IconSize) 
627{ 
628   If A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000 
629   { 
630     DllCall("PrivateExtractIcons", "Str", Filename, "Int", IconNumber-1, "Int", IconSize, "Int", IconSize, "UInt*", hIcon, "UInt*", 0, "UInt", 1, "UInt", 0, "Int") 
631      If !ErrorLevel 
632      Return hIcon 
633   } 
634   If DllCall("shell32.dll\ExtractIconExA", "Str", Filename, "Int", IconNumber-1, "UInt*", hIcon, "UInt*", hIcon_Small, "UInt", 1) 
635   { 
636      SysGet, SmallIconSize, 49 
637       
638      If (IconSize <= SmallIconSize) { 
639       DllCall("DeStroyIcon", "UInt", hIcon) 
640       hIcon := hIcon_Small 
641      } 
642     Else 
643      DllCall("DeStroyIcon", "UInt", hIcon_Small) 
644       
645      If (hIcon && IconSize) 
646         hIcon := DllCall("CopyImage", "UInt", hIcon, "UInt", 1, "Int", IconSize, "Int", IconSize, "UInt", 4|8) 
647   } 
648   Return, hIcon ? hIcon : 0 
649} 
650GetAssociatedIcon(File){ 
651   static 
652   sfi_size:=352 
653   local Ext,Fileto,FileIcon,FileIcon# 
654   If !File 
655      Loop, Parse, #_hIcons, | 
656         If A_LoopField 
657            DllCall("DestroyIcon",UInt,A_LoopField) 
658   If not sfi 
659      VarSetCapacity(sfi, sfi_size) 
660   SplitPath, File,,, Ext 
661   If !Ext 
662      Return 
663   else if Ext in EXE,ICO,ANI,CUR,LNK 
664   { 
665      If ext=LNK 
666      { 
667         FileGetShortcut,%File%,Fileto,,,,FileIcon,FileIcon# 
668         File:=!FileIcon ? FileTo : FileIcon 
669      } 
670      SplitPath, File,,, Ext 
671      hIcon%Ext%:=MI_ExtractIcon(file,FileIcon# ? FileIcon# : 1,32) 
672   } else If (!hIcon%Ext% or !InStr(hIcons,"|" . hIcon%Ext% . "|")){ 
673      If DllCall("Shell32\SHGetFileInfoA", "str", File, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101){ 
674         Loop 4 
675            hIcon%Ext% += *(&sfi + A_Index-1) << 8*(A_Index-1) 
676      } 
677      hIcons.= "|" . hIcon%Ext% . "|" 
678   } 
679   return hIcon%Ext% 
680}