/Tooltip.ahk

http://7plus.googlecode.com/ · AutoHotKey · 680 lines · 445 code · 28 blank · 207 comment · 32 complexity · 0a1a032617082233859ccbfee56b9680 MD5 · raw file

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