GUIs via DllCall: list windows/child windows (controls)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

GUIs via DllCall: list windows/child windows (controls)

28 Aug 2017, 14:02

Some methods to list windows/controls via AutoHotkey and via DllCall, and below, a link to list processes.

Code: Select all

q:: ;list child windows (controls)/windows

;get active window
WinGet, hWnd, ID, A
hWnd2 := DllCall("GetForegroundWindow", Ptr)
MsgBox, % hWnd "`r`n" Format("0x{:x}", hWnd2)

;window get class
WinGetClass, vWinClass, % "ahk_id " hWnd
vWinClass2 := ""
VarSetCapacity(vWinClass2, 261*2, 0)
DllCall("GetClassName", Ptr,hWnd, Str,vWinClass2, Int,261)
MsgBox, % vWinClass "`r`n" vWinClass2

;==============================

;list child windows (controls)
EnumFunc("", "c")
pEnumFunc := RegisterCallback("EnumFunc", "F", 2)
DllCall("EnumChildWindows", Ptr,hWnd, Ptr,pEnumFunc, Ptr,0)
vList := EnumFunc("", "r")
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;list child windows (controls)
WinGet, vCtlList, ControlListHwnd, % "ahk_id " hWnd
vList := ""
Loop, Parse, vCtlList, `n
{
	hCtl := A_LoopField
	vList .= (hCtl+0) "`r`n"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;==============================

;list all windows
EnumFunc("", "c")
pEnumFunc := RegisterCallback("EnumFunc", "F", 2)
DllCall("EnumWindows", Ptr,pEnumFunc, Ptr,0)
vList := EnumFunc("", "r")
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;list all windows
DetectHiddenWindows, On
WinGet, vWinList, List
vList := ""
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	vList .= (hWnd+0) "`n"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;==============================

;list hidden windows
EnumFunc("", "c")
pEnumFunc := RegisterCallback("EnumFunc", "F", 2)
DllCall("EnumWindows", Ptr,pEnumFunc, Ptr,0)
vListAll := EnumFunc("", "r")
vList := ""
Loop, Parse, vListAll, % "`n"
{
	if DllCall("user32\IsWindowVisible", Ptr,A_LoopField)
		vList .= A_LoopField "`n"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;list hidden windows
DetectHiddenWindows, Off
WinGet, vWinList, List
vList := ""
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	vList .= (hWnd+0) "`n"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrSplit(vList, "`n").Length() "`n" vList

;==============================

return

;==================================================

EnumFunc(hWnd, vMode)
{
	static vList
	if (vMode = "c") ;clear
		return vList := ""
	else if (vMode = "r") ;return
		return RTrim(vList, "`n")
	vList .= hWnd "`n"
	return 1
}

;==================================================
LINKS:
AutoHotkey-Util/WinEnum.ahk at master · cocobelgica/AutoHotkey-Util · GitHub
https://github.com/cocobelgica/AutoHotkey-Util/blob/master/WinEnum.ahk
[ list processes]
Process
https://autohotkey.com/docs/commands/Process.htm#Examples
Last edited by jeeswg on 17 Feb 2019, 15:24, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUIs via DllCall: list windows/child windows (controls)

29 Aug 2017, 01:22

Hi jeeswg,

how is this related to "GUIs via DllCall"? It's a simple substitution of a few WinGet sub-commands by calling the internally called API functions directly via DllCall(). At least, you should note in which cases DllCall() would produce clear benefits. As is, it's just a "Because we can!" demonstration.

Also, you should try to complete one of your "GUIs via DllCall" topics before you open new ones. As yet, I cannot see any real progress.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUIs via DllCall: list windows/child windows (controls)

29 Aug 2017, 01:42

REASONS FOR THE LIST WINDOWS/CONTROLS FUNCTIONS:

Subtle. Is the word.

When functions require a callback function, they can be quite daunting. So as relatively short as the code is, it represents difficulty. I wanted to know about this back when I was a beginner, so I wanted it relatively easy to find. I considered appending it to an existing thread, but thought it better as a stand-alone thread.

Perhaps I should call this example 'AHK functions via DllCall'. I have said for various reasons, it would be useful to have all of AHK's commands/functions recreated via DllCall. E.g. sometimes I want to do or test things in C++, that I want to convert to AHK. And so if I know: if I've demonstrated how to use the Winapi functions in AHK first I'm halfway there. Plus AHK via dll functions is good pseudocode for other programming languages.

This code is also related to the AHK v1 to AHK v2 transition. As a potential way to replicate some of the AHK v2 functions in AHK v1 that create an array.

NEXT GUIS VIA DLLCALL:

- Listviews: sorting columns. If you know much about this. I realised that in my current GUI via DllCall script, when you click on the headers, it doesn't sort.
- (Also, is there a way to programmatically click a column header on an external listview. Other than via Acc.)
- Various functions for getting/setting text in internal/external controls.
- Notepad replacement to demonstrate a complete GUI via DllCall.

I must say that really I have done all the work. It's all there. The only thing left to do is some additional trivial event handling. What is it that is fundamentally difficult, that you believe is not demonstrated yet? I've done all the really hard stuff already. Perhaps something horrible will emerge when I return to finish my Notepad replacement.

DRAG-AND-DROP:

Btw if you're able to 'finish' your drag-and-drop library, by helping with me with a programmatic drag-and-drop I'd be most grateful. There is the prospect of a very useful technique for dragging and dropping programmatically into modern programs. Thanks if you can help. (By either fixing my code, or making use of your existing functions.)
[COM] Help with the IDropSource and IDropTarget interfaces - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=8700

[EDIT:] SCROLL A GUI

I don't plan to do anything re. this, but the idea of scrolling an entire window is interesting, if you have any knowledge on the matter:
How to scroll the window without displaying the scroll bar - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 67&t=34327

[EDIT:] LISTVIEWS

I didn't have any intention to return to listviews but I noticed some issues:

- defining a custom listview sort order:
- LVM_SORTITEMS (see AHK source code: script_gui.cpp)
- my current listview via DllCall script, you click the column headers but it doesn't sort
- do you *have* to define a function, or is there a default one that is accessible

- adding a sort triangle image:
Sort triangle in column header - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/1313 ... mn-header/

- change grid colour:
- is this doable?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUIs via DllCall: list windows/child windows (controls)

29 Aug 2017, 02:25

jeeswg wrote:The only thing left to do is some additional trivial event handling. What is it that is fundamentally difficult, that you believe is not demonstrated yet?
It's the 'trivial' additional event handling and some other stuff like 'relative control positioning', auto-sizing and positioning, functioning Tab controls, etc.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: kaka2 and 135 guests