The key thing to do would be to look up 'DllCall FindWindow' or 'DllCall FindWindowEx', and see if anyone has written scripts using those Winapi functions.
Admittedly, if you're new to AHK, you wouldn't know to lookup DllCall, and might not know that these were Winapi dll functions.
Code: Select all
;q:: ;find window
;the FindWindowEx lines are dependent on the previous lines:
hWnd := DllCall("user32\FindWindow", "Str","Progman", "Ptr",0, "Ptr")
hCtl1 := DllCall("user32\FindWindowEx", "Ptr",hWnd, "Ptr",0, "Str","SHELLDLL_DefView", "Ptr",0, "Ptr")
hCtl2 := DllCall("user32\FindWindowEx", "Ptr",hCtl1, "Ptr",0, "Str","SysListView32", "Ptr",0, "Ptr")
vOutput1 := hWnd " " hCtl1 " " hCtl2
;the ControlGet lines are dependent on the WinGet line:
WinGet, hWnd, ID, ahk_class Progman
ControlGet, hCtl1, Hwnd,, SHELLDLL_DefView1, % "ahk_id " hWnd
ControlGet, hCtl2, Hwnd,, SysListView321, % "ahk_id " hWnd
vOutput2 := (hWnd+0) " " (hCtl1+0) " " (hCtl2+0)
;each line is independent:
WinGet, hWnd, ID, ahk_class Progman
ControlGet, hCtl1, Hwnd,, SHELLDLL_DefView1, ahk_class Progman
ControlGet, hCtl2, Hwnd,, SysListView321, ahk_class Progman
vOutput3 := (hWnd+0) " " (hCtl1+0) " " (hCtl2+0)
MsgBox, % vOutput1 "`r`n" vOutput2 "`r`n" vOutput3
;==============================
;list controls for Progman (states the hCtl (control hWnd) and the ClassNN (control class and a number):
WinGet, hWnd, ID, ahk_class Progman
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
vOutput := ""
Loop Parse, vCtlList, % "`n"
{
vCtlClassNN := A_LoopField
ControlGet, hCtl, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd
vOutput .= vCtlClassNN "`r`n"
}
;Clipboard := vOutput
MsgBox, % vOutput
return
Dll functions typically have their own page on Microsoft's website (MSDN), FindWindow/FindWindowEx appear in user32.dll.
Progman is the class of a window. Other common Explorer classes are: WorkerW, CabinetWClass, ExploreWClass. The class for Notepad windows is 'Notepad', the class for WordPad windows is 'WordPadClass', the class for Internet Explorer is 'IEFrame'.
SHELLDLL_DefView and SysListView32 are classes for controls. Other common classes include: Edit, Static, msctls_statusbar32, SysTreeView32.
Searching for relevant search terms, might find useful template code, e.g.:
[x64 & x32 fix] DeskIcons - Get/Set Desktop Icon Positions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3529
However, I already knew about that script, and it didn't appear on the first page of Google results when I searched 'AutoHotkey desktop icons'.
I wouldn't be too concerned about asking for help, especially at the beginning, show that you've done some searching/tried some code, that's the main thing.
DllCall can be tricky even for the experts, because you have to find out what the types are, e.g. Str/Ptr etc. It can be quite difficult to find that info sometimes, e.g. searching through the .h files (header files) for 'typedef', that come with Visual Studio, or doing tests in C++ to ascertain the size of the type in 64-bit and 32-bit.
C++: DllCall: get parameter types/sizes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=75&t=39426
I.e. the problem is not complicated code, but simply finding certain factual information.
Cheers.
Some links:
jeeswg's DllCall and structs tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=63708
[an AHK v2 script]
window get controls (indented to show hierarchy) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=83&t=69189