Тема: AHK: Сбор информации
Очень хотелось создать инструмент для сбора как можно большей информации, что-то вроде AutoIt3 Window Spy или AHK Window Info (но в отличие от них, чтобы инструмент собирал всю информацию на экране, а не только с окон), а так же понравилось как реализована идея увеличения области под курсором когда определяешь цвет в Color Spy.
Способности: сбор информации с окон, системного лотка, панели задач в WinXP и Win7, работа с ANSI и Unicode версиями интерпретатора.
Замечания: при использовании в Win7, следует менять тему с полупрозрачными окантовками окон (Aero) на любую другую, не возможен двойной левый клик.
#NoEnv
CoordMode, Pixel
DetectHiddenWindows, On
SetBatchLines, -1
Gui, GUI1: +AlwaysOnTop -Caption +E0x80000 +HwndGUI1hWnd +Owner
Gui, GUI1: Show, w150 h150, 10xZoom Of Gathering Info
OnMessage(0x201, "WM_NCLBUTTONDOWN") ; WM_LBUTTONDOWN
hModule:=DllCall("LoadLibrary", "Str", "gdiplus.dll")
VarSetCapacity(GdiplusStartupInput, 16, 0)
NumPut(1, GdiplusStartupInput, 0, "Char") ; GdiplusVersion
DllCall("gdiplus\GdiplusStartup", "UInt*", pToken
, "UInt", &GdiplusStartupInput
, "UInt", 0)
VarSetCapacity(BITMAPINFO, 40, 0)
NumPut(40, BITMAPINFO, 0) ; biSize
NumPut(150, BITMAPINFO, 4) ; biWidth
NumPut(150, BITMAPINFO, 8) ; biHeight
NumPut(1, BITMAPINFO, 12, "UShort") ; biPlanes
NumPut(32, BITMAPINFO, 14, "UShort") ; biBitCount
NumPut(0, BITMAPINFO, 16) ; biCompression
hBitmap:=DllCall("CreateDIBSection", "UInt", hDC
, "UInt", &BITMAPINFO
, "UInt", 0
, "UInt*", 0
, "UInt", 0
, "UInt", 0)
DllCall("ReleaseDC", "UInt", 0, "UInt", hDC)
hMemDC:=DllCall("CreateCompatibleDC", "UInt", 0) ; current screen
DllCall("SelectObject", "UInt", hMemDC, "UInt", hBitmap)
DllCall("gdiplus\GdipCreateFromHDC", "UInt", hMemDC, "UInt*", pGraphics)
DllCall("gdiplus\GdipCreateFromHDC", "UInt", hMemDC, "UInt*", pGraphics2)
DllCall("gdiplus\GdipSetSmoothingMode", "UInt", pGraphics, "Int", 3) ; AA low
Color1:=0xFF000000, Color2:=0xFFFFFFFF ; argb
GdipCreatePen(Color1, pPen1) ; black
GdipCreatePen(Color2, pPen2) ; white
GdipCreatePen(Color1, pPen3) ; black dot rect
GdipCreatePen(Color1, pPen4) ; black rect
DllCall("gdiplus\GdipSetPenDashStyle", "UInt", pPen1
, "Char", 5) ; DashStyleCustom
VarSetCapacity(Array, 8, 0)
NumPut(4, Array, 0, "Float") ; dash lenght
NumPut(3, Array, 4, "Float") ; space lenght
DllCall("gdiplus\GdipSetPenDashArray", "UInt", pPen1
, "Int", &Array
, "Int", 2) ; count
DllCall("gdiplus\GdipSetPenDashStyle", "UInt", pPen3
, "Char", 2) ; DashStyleDot
DllCall("gdiplus\GdipCreateSolidFill", "Int", Color1, "UInt*", pBrush)
VarSetCapacity(TRACKMOUSEEVENT, 16, 0)
NumPut(16, TRACKMOUSEEVENT, 0) ; cbSize
NumPut(0x3, TRACKMOUSEEVENT, 4) ; dwFlags
NumPut(1, TRACKMOUSEEVENT, 12) ; dwHoverTime
TipText:=XPos:=YPos:=0, OffXPos:=OffYPos:=40, TextColor:="cBlue"
VarSetCapacity(TOOLINFO, 44, 0)
NumPut(44, TOOLINFO, 0) ; cbSize
NumPut(0xA0, TOOLINFO, 4) ; uFlags, TTF_TRACK+TTF_ABSOLUTE
NumPut(hToolTip, TOOLINFO, 12) ; hwnd
NumPut(&TipText, TOOLINFO, 36) ; lpszText
Is64BitWindows:=Is64bitOS(), hToolTip:=CreateToolTip(), ResumeTimer()
SendMessage, 0x416,,,, % "ahk_id"hTooltip ; TTM_GETTIPBKCOLOR
DefColorTipBack:=ErrorLevel
SendMessage, 0x417,,,, % "ahk_id"hTooltip ; TTM_GETTIPTEXTCOLOR
DefColorTipText:=ErrorLevel
Menu, Tray, NoStandard
Menu, Tray, Icon, shell32.dll, 172 ; or 23
Menu, Tray, Tip, Gathering info
Menu, Tray, Add, &High smooth, SetSmoothingMode
Menu, Tray, Add, &Paint tooltip, SetPaintTooltip
Menu, Tray, Add, Pin &zoomview, SetZoomViewBehavior
Menu, Tray, Add, &About, About
Menu, Tray, Add
Menu, Tray, Add, &Exit (Tilde+Esc), ExitScript
OnMessage(0x404, "WM_LBUTTONUP") ; AHK_NOTIFYICON
Hotkey, NumpadUp, MoveCursor
Hotkey, NumpadDown, MoveCursor
Hotkey, NumpadLeft, MoveCursor
Hotkey, NumpadRight, MoveCursor
Hotkey, Numpad8, MoveCursor
Hotkey, Numpad2, MoveCursor
Hotkey, Numpad4, MoveCursor
Hotkey, Numpad6, MoveCursor
Hotkey, sc29 & Esc, ExitScript
Return
ChaseCursor:
CoordMode, Mouse, Relative
MouseGetPos, XPosRel, YPosRel
CoordMode, Mouse
MouseGetPos, XPosAbs, YPosAbs, WinID, WinControl
ControlGetFocus, WinControlGF, % "ahk_id"WinID
ControlGetPos, ControlX, ControlY, ControlW, ControlH
, % WinControl, % "ahk_id"WinID
WinGetTitle, WinTitle, % "ahk_id"WinID
WinGet, WinProcName, ProcessName, % "ahk_id"WinID
WinGet, WinProcPID, PID, % "ahk_id"WinID
WinProcAdress:=DllCall("GetClassLong", "UInt", WinID, "Int", -24)
WinGetClass, WinClass, % "ahk_id"WinID
WinGetPos, WinX, WinY, WinW, WinH, % "ahk_id"WinID
StringUpper, WinID, WinID
PixelGetColor, CurrentColor, XPosAbs, YPosAbs, RGB
If IsPainted
{
PixelGetColor, CurrentColor2, XPosAbs, YPosAbs
r:=(CurrentColor2 & 0x00FF00)>>8, g:=(CurrentColor2 & 0x0000FF)>>0
b:=(CurrentColor2 & 0xFF0000)>>16, InvColor:=(CurrentColor2 ^ 0xFFFFFF)
r2:=(InvColor & 0x00FF00)>>8, g2:=(InvColor & 0x0000FF)>>0
b2:=(InvColor & 0xFF0000)>>16, CurrentColor3:=CurrentColor2
Diff_r:=r-r2, Diff_g:=g-g2, Diff_b:=b-b2, Treshold:=25
If ((Diff_r<0 And Diff_r>-Treshold Or Diff_r>0 And Diff_r<Treshold)
And (Diff_g<0 And Diff_g>-Treshold Or Diff_g>0 And Diff_g<Treshold)
And (Diff_b<0 And Diff_b>-Treshold Or Diff_b>0 And Diff_b<Treshold))
CurrentColor3-=0x757575
SendMessage, 0x413, CurrentColor2,,
, % "ahk_id"hTooltip ; TTM_SETTIPBKCOLOR
SendMessage, 0x414, CurrentColor3 ^ 0xFFFFFF,,
, % "ahk_id"hTooltip ; TTM_SETTIPTEXTCOLOR
}
If (WinClass="Shell_TrayWnd" And A_OSVersion="WIN_XP"
And WinControl="ToolbarWindow322")
TipText:=GetToolbarInfo(1)
Else If (WinClass="Shell_TrayWnd" And WinControl="MSTaskListWClass1")
TipText:=GetTaskInfo()
Else If (WinClass="Shell_TrayWnd"
And (WinControl!="TrayClockWClass1"
And WinControl!="TrayShowDesktopButtonWClass1"
And WinControl!="Button1"
And WinControl!="Button2"
And WinControl!="ReBarWindow321"
And WinControl!="CiceroUIWndFrame1"))
TipText:=GetToolbarInfo(2)
Else
TipText:=GetWinInfo()
If (XPos!=XPosAbs Or YPos!=YPosAbs)
{
XPos:=XPosAbs, YPos:=YPosAbs
SendMessage, 0x41E,, &TOOLINFO,, % "ahk_id"hToolTip ; TTM_GETBUBBLESIZE
Width:=ErrorLevel & 0xFFFF, Height:=ErrorLevel>>16
CurXPos:=XPosAbs, CurYPos:=YPosAbs
If (CurXPos+OffXPos+Width>A_ScreenWidth)
CurXPos-=(Width+OffXPos)
Else
CurXPos+=OffXPos
If (CurYPos+OffYPos+Height>A_ScreenHeight)
CurYPos-=(Height+OffYPos)
Else
CurYPos+=OffYPos
PostMessage, 0x412,, (CurXPos|CurYPos<<16),
, % "ahk_id"hToolTip ; TTM_TRACKPOSITION
}
If GetKeyState("NumpadClear", "P") Or GetKeyState("Numpad5", "P")
{
Clipboard:=TipText
TipText.="`n`nsaved"
}
Else
TipText.="`n`nuse numpad-arrows for smallest moves of cursor"
. "`npress numpad5 button to save info into clipboard"
. "`nclick left mouse button on tray icon for use pause"
SetToolTipText(&TipText)
Loop, 15
GdipDrawLine(A_Index-1)
If !IsZoomDragged
{
If (XPosAbs<A_ScreenWidth/2 And YPosAbs<A_ScreenHeight/2)
WinMove, % "ahk_id"GUI1hWnd,, A_ScreenWidth-150, A_ScreenHeight-150
Else If (XPosAbs>A_ScreenWidth/2 And YPosAbs<A_ScreenHeight/2)
WinMove, % "ahk_id"GUI1hWnd,, 0, A_ScreenHeight-150
Else If (XPosAbs>A_ScreenWidth/2 And YPosAbs>A_ScreenHeight/2)
WinMove, % "ahk_id"GUI1hWnd,, 0, 0
Else
WinMove, % "ahk_id"GUI1hWnd,, A_ScreenWidth-150, 0
}
GdipDrawObject("Line", pPen2, 0, 75, 70, 75) ; white line
GdipDrawObject("Line", pPen2, 80, 75, 150, 75)
GdipDrawObject("Line", pPen2, 75, 0, 75, 70)
GdipDrawObject("Line", pPen2, 75, 80, 75, 150)
GdipDrawObject("Line", pPen1, 69, 75, 1, 75) ; black dash line
GdipDrawObject("Line", pPen1, 81, 75, 147, 75)
GdipDrawObject("Line", pPen1, 75, 69, 75, 1)
GdipDrawObject("Line", pPen1, 75, 81, 75, 147)
GdipDrawObject("Rectangle", pPen2, 70, 70, 10, 10) ; white center rect
GdipDrawObject("Rectangle", pPen3, 70, 70, 10, 10) ; black dot center rect
GdipDrawObject("Rectangle", pPen4, 0, 0, 149, 149) ; black outside rect
DllCall("UpdateLayeredWindow", "UInt", GUI1hWnd
, "UInt", 0
, "UInt", 0
, "Int64*", 0x09600000096 ; 150x150
, "UInt", hMemDC
, "Int64*", 0
, "UInt", 0
, "UInt*", 0x01ff0000 ; BLENDFUNCTION
, "UInt", 2)
Return
MoveCursor:
If % A_ThisHotkey="NumpadUp" Or A_ThisHotkey="Numpad8"
MouseMove, XPosRel, YPosRel-1
Else If % A_ThisHotkey="NumpadDown" Or A_ThisHotkey="Numpad2"
MouseMove, XPosRel, YPosRel+1
Else If % A_ThisHotkey="NumpadLeft" Or A_ThisHotkey="Numpad4"
MouseMove, XPosRel-1, YPosRel
Else If % A_ThisHotkey="NumpadRight" Or A_ThisHotkey="Numpad6"
MouseMove, XPosRel+1, YPosRel
KeyWait, % A_ThisHotkey
Return
SetZoomViewBehavior:
IsZoomDragged:=!IsZoomDragged
WinMove, % "ahk_id"GUI1hWnd,, A_ScreenWidth/2-76, A_ScreenHeight/2-76
Menu, Tray, Rename, % (!IsZoomDragged ? "Unpin":"Pin")" &zoomview"
, % (!IsZoomDragged ? "Pin":"Unpin")" &zoomview"
Return
SetSmoothingMode:
IsSmoothingMode:=!IsSmoothingMode
DllCall("gdiplus\GdipSetSmoothingMode", "UInt", pGraphics
, "Int", IsSmoothingMode ? 4:3)
Menu, Tray, Rename, % (!IsSmoothingMode ? "&Low":"&High")" smooth"
, % (!IsSmoothingMode ? "&High":"&Low")" smooth"
Return
SetPaintTooltip:
IsPainted:=!IsPainted
Menu, Tray, % IsPainted ? "Check":"Uncheck", &Paint tooltip
If % A_OSVersion="WIN_7"
Dllcall("UxTheme\SetWindowTheme", "Int", hToolTip
, !IsPainted ? "Ptr":"Str"
, !IsPainted ? 0:""
, !IsPainted ? "Ptr":"Str"
, !IsPainted ? 0:"")
Else
{
If IsPainted
Dllcall("UxTheme\SetWindowTheme", "Int", hToolTip
, "Str", ""
, "Str", "")
Else
{
PostMessage, 0x413, DefColorTipBack,,, % "ahk_id"hTooltip
PostMessage, 0x414, DefColorTipText,,, % "ahk_id"hTooltip
}
}
Return
About:
IsAbout:=True
If IsPaused
Goto, ByPassI
StopTimer()
ByPassI:
Gui, GUI2: Font, Bold
Gui, GUI2: Add, Text
, x32 y30 w140 h20 +Center
, Gathering info
Gui, GUI2: Font
Gui, GUI2: Add, Text
, x32 y50 w140 h20 +Center
, Made using AutoHotkey
Gui, GUI2: Font, Underline cBlue
Gui, GUI2: Add, Text
, x24 y90 w156 h20 gAHKHome +HwndGUI2hlhWnd +Center
, www.autohotkey.com
Gui, GUI2: Font
Gui, GUI2: Add, GroupBox, x22 y10 w160 h110
Gui, GUI2: +HwndGUI2hWnd -MinimizeBox -Resize
Gui, GUI2: Show, Center h135 w205, About
hHandCursor:=DllCall("LoadCursor", "UInt", 0, "Int", 32649) ; IDC_HAND
DllCall("SetClassLong", "UInt", GUI2hlhWnd, "Int", -12, "UInt", hHandCursor)
NumPut(GUI2hWnd, TRACKMOUSEEVENT, 8) ; hwndTrack
OnMessage(0x200, "WM_MOUSEMOVE"), OnMessage(0x2A1, "WM_MOUSEHOVER")
OnMessage(0x2A3, "WM_MOUSELEAVE")
Return
AHKHome:
Run, http://www.autohotkey.com,, UseErrorLevel
Return
GUI2GuiClose:
If IsPaused
Goto, ByPassO
ResumeTimer()
ByPassO:
Gui, GUI2: Destroy
IsAbout:=False
Return
ExitScript:
PostMessage, A_IsUnicode ? 0x433:0x405,, &TOOLINFO,
, % "ahk_id"hToolTip ; TTM_DELTOOL
DllCall("DestroyWindow", "UInt", hToolTip)
DllCall("gdiplus\GdiplusShutdown", "UInt", pToken)
DllCall("FreeLibrary", "UInt", hModule)
SetDefaultCursors()
ExitApp
GetWinInfo()
{
global
If !WinTitle
WinTitle:="no data"
If !WinControl
WinControl:="no data"
If !WinControlGF
WinControlGF:="no data"
Return, "title: "WinTitle
. "`nname: "WinProcName
. "`npid: "WinProcPID
. "`nhwnd: 0x"SubStr(WinID, 3)
. "`nadress: "Dec2Hex(WinProcAdress)
. "`nclass: "WinClass
. ", width: "WinW ", height: "WinH
. ", x: "WinX ", y: "WinY
. "`nctrl: "WinControl
. ", width: "ControlW ", height: "ControlH
. ", x: "ControlX ", y: "ControlY
. "`nctrlgf: "WinControlGF
. "`npos: abs_x: "XPosAbs ", abs_y: "YPosAbs
. " (rel_x: "XPosRel ", rel_y: "YPosRel ")"
. "`ncolor: "CurrentColor
. " ("Hex2Dec(CurrentColor)")"
. "`ninvcolor: 0x"SubStr(Dec2Hex(CurrentColor ^ 0xFFFFFF), 5)
. " ("Hex2Dec(CurrentColor ^ 0xFFFFFF)")"
}
Dec2Hex(DecData)
{
HexData:=00000000
DllCall("msvcrt.dll\s"(A_IsUnicode ? "w":"")"printf", "Str", HexData
, "Str", "0x%08X"
, "UInt", DecData)
Return, HexData
}
Hex2Dec(HexData)
{
r:=(HexData>>0x10) & 0xFF
g:=(HexData>>0x08) & 0xFF
b:=(HexData>>0x00) & 0xFF
Return, "R"r ", G"g ", B"b
}
CreateToolTip()
{
global
hToolTip:=DllCall("CreateWindowEx", "UInt", 0x8 ; WS_EX_TOPMOST
, "Str", "tooltips_class32" ; TOOLTIP_CLASS
, "Str", ""
, "UInt", 0x3 ; TTS_NOPREFIX+TTS_ALWAYSTIP
, "UInt", 0x80000000 ; CW_USEDEFAULT
, "UInt", 0x80000000
, "UInt", 0x80000000
, "UInt", 0x80000000
, "UInt", 0
, "UInt", 0
, "UInt", 0
, "UInt", 0)
PostMessage, A_IsUnicode ? 0x432:0x404,, &TOOLINFO,
, % "ahk_id"hToolTip ; TTM_ADDTOOL
PostMessage, 0x411, 0x1, &TOOLINFO,, % "ahk_id"hToolTip ; TTM_TRACKACTIVATE
PostMessage, 0x418,, A_ScreenWidth/2,, % "ahk_id"hToolTip ; TTM_SETMAXTIPWIDTH
Return, hToolTip
}
SetToolTipText(TText)
{
global
NumPut(TText, TOOLINFO, 36)
PostMessage, A_IsUnicode ? 0x439:0x40C,, &TOOLINFO,
, % "ahk_id"hToolTip ; TTM_UPDATETIPTEXT
}
SetTextColor(DefinedColor)
{
global
TextColor:=DefinedColor
Gui, GUI2: Font, % "Underline" DefinedColor
GuiControl, GUI2: Font, Static3
}
WM_NCLBUTTONDOWN()
{
global
PostMessage, 0xA1, 0x2,,, % "ahk_id"GUI1hWnd ; WM_NCLBUTTONDOWN, HTCAPTION
}
WM_MOUSEMOVE()
{
global
If !Tracking
DllCall("TrackMouseEvent", "Int", &TRACKMOUSEEVENT)
Else
{
MouseGetPos,,,, WinControl2
If WinControl2=Static3
SetTextColor("cRed")
Else If TextColor!=cBlue
SetTextColor("cBlue")
}
}
WM_MOUSEHOVER()
{
global
Tracking:=True
}
WM_MOUSELEAVE()
{
global
MouseGetPos,,,, WinControl3
If WinControl3=Static3
Return
SetTextColor("cBlue"), Tracking:=False
}
WM_LBUTTONUP(wParam, lParam, Msg, hWnd)
{
global
If lParam=0x202 ; WM_LBUTTONUP
{
If IsAbout
Return
IsPaused:=!IsPaused
IsPaused ? StopTimer():ResumeTimer()
Menu, Tray, Icon, shell32.dll, % IsPaused ? 28:172
}
}
StopTimer()
{
global
SetTimer, ChaseCursor, Off
PostMessage, 0x411,, &TOOLINFO,, % "ahk_id"hToolTip
Gui, GUI1: Cancel
SetDefaultCursors()
}
ResumeTimer()
{
global
SetDefinedCursor(32515) ; OCR_NORMAL
PostMessage, 0x411, 0x1, &TOOLINFO,, % "ahk_id"hToolTip
Gui, GUI1: Show
SetTimer, ChaseCursor, 100
}
SetDefaultCursors()
{
DllCall("SystemParametersInfo", "UInt", 0x57 ; SPI_SETCURSORS
, "UInt", 0
, "UInt", 0
, "UInt", 0)
}
SetDefinedCursor(Cursor)
{
SystemCursors:="
,32512,32513,32514,32515,32516,32640,32641,32642
,32643,32644,32645,32646,32648,32649,32650,32651"
Loop, Parse, SystemCursors, CSV
{
If % A_Loopfield=Cursor
{
Loop, Parse, SystemCursors, CSV
{
hCursor:=DllCall("LoadCursor", "UInt", 0, "Int", Cursor)
hCursor:=DllCall("CopyImage", "UInt", hCursor
, "UInt", 0x2 ; IMAGE_CURSOR
, "Int", 28
, "Int", 28
, "UInt", 0)
DllCall("SetSystemCursor", "UInt", hCursor
, "Int", A_Loopfield)
}
}
}
}
GdipDrawLine(Y)
{
global
Loop, 15
{
PixelGetColor, CurrentColor, XPos-7+A_Index-1, YPos-7+Y, RGB
DllCall("gdiplus\GdipSetSolidFillColor", "UInt", pBrush
, "UInt", CurrentColor|0xFF000000)
DllCall("gdiplus\GdipFillRectangle", "UInt", pGraphics
, "UInt", pBrush
, "Float", (A_Index-1)*10
, "Float", Y*10
, "Float", 10 ; w
, "Float", 10) ; h
}
}
GdipCreatePen(PenColor, ByRef N)
{
global
DllCall("gdiplus\GdipCreatePen1", "Int", PenColor
, "Float", 1 ; width
, "Char", 2 ; unit - pixel
, "UInt*", N)
}
GdipDrawObject(Kind, N, FromX, FromY, IntoX, IntoY)
{
global
DllCall("gdiplus\GdipDraw" . Kind, "UInt", pGraphics2
, "UInt", N
, "Float", FromX
, "Float", FromY
, "Float", IntoX
, "Float", IntoY)
}
GetTaskInfo()
{
global
FoundTIcon:=False
ControlGet, hWnd, Hwnd,, MSTaskListWClass1, % "ahk_class"WinClass
StringUpper, hWnd, hWnd
TaskList:=AccessibleObjectFromWindow(hWnd)
Focus:=TaskList.accFocus, Parent:=TaskList.accParent
Selection:=TaskList.accSelection
Loop, % TaskList.accChildCount
{
TWinTitle:=TaskList.accName(A_Index)
DefAction:=TaskList.accDefaultAction(A_Index)
Role:=TaskList.accRole(A_Index)
State:=TaskList.accState(A_Index)
TaskList.accLocation(ComObjParameter(0x4003, &L:=0) ; VT_BYREF+VT_I4
, ComObjParameter(0x4003, &T:=0)
, ComObjParameter(0x4003, &W:=0)
, ComObjParameter(0x4003, &H:=0)
, A_Index)
WinGet, TWinID, ID, % TWinTitle
WinGetPos, TWinX, TWinY, TWinW, TWinH, % "ahk_id"TWinID
StringUpper, TWinID, TWinID
If !TWinID
TWinX:=TWinY:=TWinW:=TWinH:=TWinID:="no data"
TIconLEFTAbs:=NumGet(L), TIconTOPAbs:=NumGet(T)
TIconWidth:=NumGet(W), TIconHeight:=NumGet(H)
If (RContains(TIconLEFTAbs
, TIconTOPAbs
, TIconWidth
, TIconHeight
, XPosAbs
, YPosAbs))
{
If !Focus
Focus:="no data"
FoundTIcon:=True
TL:="title: "TWinTitle
. "`nhwnd: 0x"SubStr(TWinID, 3)
. "`nfocus: "Focus
. "`ndefaction: "DefAction
. "`nrole: "Role
. " ("GetRoleText(Role)")"
. "`nstate: "State
. " ("GetStateText(State)")"
. "`nwidth: "TWinW ", height: "TWinH
. ", x: "TWinX ", y: "TWinY
. "`niconpos: left: "NumGet(L) ", top: "NumGet(T)
. ", width: "NumGet(W) ", height: "NumGet(H)
Break
}
}
If !WinControl
WinControl:="no data"
If !WinControlGF
WinControlGF:="no data"
If !FoundTIcon
TL:="title: "TaskList.accName(0)
. "`nname: "WinProcName
. "`npid: "WinProcPID
. "`nhwnd: 0x"SubStr(hWnd, 3)
. "`nadress: "Dec2Hex(WinProcAdress)
. "`nclass: "WinClass
. ", width: "WinW ", height: "WinH
. ", x: "WinX ", y: "WinY
. "`nctrl: "WinControl
. ", width: "ControlW ", height: "ControlH
. ", x: "ControlX ", y: "ControlY
. "`nctrlgf: "WinControlGF
Return, TL . "`npos: abs_x: "XPosAbs ", abs_y: "YPosAbs
. " (rel_x: "XPosRel ", rel_y: "YPosRel ")"
. "`ncolor: "CurrentColor
. " ("Hex2Dec(CurrentColor)")"
. "`ninvcolor: 0x"SubStr(Dec2Hex(CurrentColor ^ 0xFFFFFF), 5)
. " ("Hex2Dec(CurrentColor ^ 0xFFFFFF)")"
}
AccessibleObjectFromWindow(Hwnd)
{
VarSetCapacity(IID, 16) ; GuidAttribute 618736E0-3C3D-11CF-810C-00AA00389B71
NumPut(0x11CF3C3D618736E0, IID, 0, "Int64") ; IID_IAccessible (first-half)
NumPut(0x719B3800AA000C81, IID, 8, "Int64") ; IID_IAccessible (second-half)
DllCall("LoadLibrary", "Str", "Oleacc", "Ptr")
If !DllCall("Oleacc\AccessibleObjectFromWindow", "Ptr", Hwnd
, "UInt", -4 ; OBJID_Client
, "Ptr", &IID
, "Ptr*", ppvObject)
Return, ComObjEnwrap(ppvObject)
}
GetRoleText(nRole)
{
nSize:=DllCall("Oleacc\GetRoleText", "UInt", nRole, "Ptr", 0, "UInt", 0)
VarSetCapacity(sRole, (A_IsUnicode ? 2:1)*nSize)
DllCall("Oleacc\GetRoleText", "UInt", nRole, "Str", sRole, "UInt", nSize+1)
Return, sRole
}
GetStateText(nState)
{
nSize:=DllCall("Oleacc\GetStateText", "UInt", nState, "Ptr", 0, "UInt", 0)
VarSetCapacity(sState, (A_IsUnicode ? 2:1)*nSize)
DllCall("Oleacc\GetStateText", "UInt", nState, "Str", sState, "UInt", nSize+1)
Return, sState
}
Is64bitOS()
{
Return, (A_PtrSize=8)
Or DllCall("IsWow64Process", "Ptr", DllCall("GetCurrentProcess")
, "Int*", isWow64) And isWow64
}
GetToolbarInfo(TBType)
{
global
ClassName:=TBType=1 ? "MSTaskSwWClass1":"TrayNotifyWnd1"
ControlGet, hParent, hWnd,, % ClassName, % "ahk_class"WinClass
ControlGet, hChild , hWnd,, ToolbarWindow321, % "ahk_id"hParent
WinGet, TBPID, PID, % "ahk_class"WinClass
WinGetPos, WinXPos, WinYPos,,, % "ahk_id"hChild
hProc:=DllCall("OpenProcess", "UInt", 0x18 ; PROCESS_VM_OPERATION+PROCESS_VM_READ
, "Int", 0
, "UInt", TBPID)
pProc:=DllCall("VirtualAllocEx", "UInt", hProc
, "UInt", 0
, "UInt", 32
, "UInt", 0x1000 ; MEM_COMMIT
, "UInt", 0x4) ; PAGE_READWRITE
pRECT:=DllCall("VirtualAllocEx", "UInt", hProc
, "UInt", 0
, "UInt", 16
, "UInt", 0x1000
, "UInt", 0x4)
SendMessage, 0x418,,,, % "ahk_id"hChild ; TB_BUTTONCOUNT
VarSetCapacity(BTN, 32, 0), VarSetCapacity(INFO, 32, 0), VarSetCapacity(RECT, 16)
Loop, % ErrorLevel
{
SendMessage, 0x417, A_Index-1, pProc,, % "ahk_id"hChild ; TB_GETBUTTON
DllCall("ReadProcessMemory", "UInt", hProc
, "UInt", pProc
, "UInt", &BTN
, "UInt", 32
, "UInt", 0)
iBitmap:=NumGet(BTN, OffSet:=0), OffSet+=4
idCommand:=NumGet(BTN, OffSet), OffSet+=4
fsState:=NumGet(BTN, OffSet, "Char"), OffSet+=1
fsStyle:=NumGet(BTN, OffSet, "Char"), OffSet+=1
OffSet+=(Is64BitWindows ? 6:2), TypeOS:=(Is64BitWindows ? "Int64":"Int")
dwData:=NumGet(BTN, OffSet, TypeOS), OffSet+=(Is64BitWindows ? 8:4)
iString:=NumGet(BTN, OffSet, TypeOS)
DllCall("ReadProcessMemory", "UInt", hProc
, "UInt", dwData
, "UInt", &INFO
, "UInt", 32
, "UInt", 0)
hWnd:=NumGet(INFO, 0), uID:=NumGet(INFO, 4)
nMsg:=NumGet(INFO, 8), hIcon:=NumGet(INFO, 20)
WinGet, IconPID, PID, % "ahk_id"hWnd
WinGet, IconProcName, ProcessName, % "ahk_id"hWnd
WinGetClass, IconClass, % "ahk_id"hWnd
VarSetCapacity(IconTooltip, 128), VarSetCapacity(WideTooltip, 128*2)
DllCall("ReadProcessMemory", "UInt", hProc
, "UInt", iString
, "UInt", &WideTooltip
, "UInt", 128*2
, "UInt", 0)
DllCall("WideCharToMultiByte", "UInt", 0
, "UInt", 0
, "Str", WideTooltip
, "Int", -1
, "Str", IconTooltip
, "Int", 128
, "UInt", 0
, "UInt", 0)
If A_IsUnicode
IconTooltip:=WideTooltip
SendMessage, 0x41D, A_Index-1, pRECT,, % "ahk_id"hChild ; TB_GETITEMRECT
DllCall("ReadProcessMemory", "UInt", hProc
, "UInt", pRECT
, "UInt", &RECT
, "UInt", 16
, "UInt", 0)
IconLEFT:=NumGet(RECT, 0, "Int"), IconTOP:=NumGet(RECT, 4, "Int")
IconRIGHT:=NumGet(RECT, 8, "Int"), IconBOTTOM:=NumGet(RECT, 12, "Int")
IconLEFTAbs:=(IconLEFT+WinXPos), IconTOPAbs:=(IconTOP+WinYPos)
If (fsState!=8 And RContains(IconLEFTAbs
, IconTOPAbs
, IconRIGHT-IconLEFT
, IconBOTTOM-IconTOP
, XPosAbs
, YPosAbs))
Break
}
DllCall("VirtualFreeEx", "UInt", hProc
, "UInt", pProc
, "UInt", 0
, "UInt", 0x8000)
DllCall("VirtualFreeEx", "UInt", hProc
, "UInt", pRECT
, "UInt", 0
, "UInt", 0x8000)
DllCall("CloseHandle", "UInt", hProc)
Result:="title: "IconTooltip
. "`nname: "IconProcName
. "`npid: "IconPID
. "`nhwnd: "Dec2Hex(hWnd)
If TBType=1
{
If !WinTitle
WinTitle:="no data"
If !WinControl
WinControl:="no data"
If !WinControlGF
WinControlGF:="no data"
Result.="`nadress: "Dec2Hex(WinProcAdress)
. "`nclass: "WinClass
. ", width: "WinW ", height: "WinH
. ", x: "WinX ", y: "WinY
. "`nctrl: "WinControl
. ", width: "ControlW ", height: "ControlH
. ", x: "ControlX ", y: "ControlY
. "`nctrlgf: "WinControlGF
}
If % A_OSVersion="WIN_7" Or TBType=2
{
Result.="`nclass: "IconClass
. "`niBitmap: "iBitmap
. "`nidCommand: "idCommand
. "`nfsState: "fsState
. "`nfsStyle: "fsStyle
. "`ndwData: "Dec2Hex(dwData)
. "`niString: "Dec2Hex(iString)
. "`nnMsg: "nMsg
. "`nhIcon: "Dec2Hex(hIcon)
}
Return, Result . "`niconpos: left: "IconLEFTAbs ", top: "IconTOPAbs
. ", width: "IconRIGHT ", height: "IconBOTTOM
. "`npos: abs_x: "XPosAbs ", abs_y: "YPosAbs
. " (rel_x: "XPosRel ", rel_y: "YPosRel ")"
. "`ncolor: "CurrentColor
. " ("Hex2Dec(CurrentColor)")"
. "`ninvcolor: 0x"SubStr(Dec2Hex(CurrentColor ^ 0xFFFFFF), 5)
. " ("Hex2Dec(CurrentColor ^ 0xFFFFFF)")"
}
RContains(X, Y, W, H, CX, CY) ; RECTANGLE.CONTAINS METHOD
{
Return, ((((X<=CX) And (CX<(X+W))) And (Y<=CY)) AND (CY<(Y+H)))
}