Struggling with DLL

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iwrk4dedpr
Posts: 16
Joined: 18 Aug 2014, 23:01

Struggling with DLL

21 Nov 2019, 20:05

Howdy all .... pretty noob here but have been using AHK for more than a few years.
Every now and then I attempt to reconstruct some VBA code that I have. The code moves / orders the Desktop ICON's.

While I'm happy that after a crapload of trial and error I got the VBA version of stuff to work. I'm failing every left / right turn I make. ATM I don't have any AHK scripts, but I'm back to once again trying to use AHK script to adjust my icons.

Here is the beginning of the vba code that I use:

Code: Select all

    h = FindWindow("Progman", vbNullString)
    h = FindWindowEx(h, 0, "SHELLDLL_defVIEW", vbNullString)
    itm = FindWindowEx(h, 0, "SysListView32", vbNullString)
The first line of code returns 66598
Which is used in the next line of code .... and it returns 66600
Which is used in the third line of code .... and it returns 66602


OK .... to be honest I have absolutely NO idea what "PROGMAN" is ( program manager I think ) or "SHELLDLL_defVIEW" or "SysListView32"

and I realize that you will likely return other values ... pretty sure a value of 0 is not a proper value.


Here are the function declarations in my code as well

Code: Select all


'   WIN Api Declarations
    Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
    Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String)
    

Honestly, I wish I could find some sort of TUTORIAL that really explains what to do. I love being selfsufficient. I've seen some stuff on GitHub but I'm lost when looking at it. Any help .... ALL help greatly appreciated.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Struggling with DLL

22 Nov 2019, 09:36

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
iwrk4dedpr
Posts: 16
Joined: 18 Aug 2014, 23:01

Re: Struggling with DLL

22 Nov 2019, 17:32

jeeswg wrote:
22 Nov 2019, 09:36
The key thing to do would be to look up 'DllCall FindWindow' ...
Thanks Jees ..... like I said I've been using AHK for quite some time. I do know about the DLLCall but could never get them to work .... and could never figure out why.


I think at one time or another tried to search the forums for desktop icons alas never came across the thread you've given. .... Having a script to teach me is the best, I seem to do very well when someone else does the hard work ... and all I have to do then is STAND ON THE SHOULDER'S OF GIANTS.

I'll be looking up the other links ... have been many many many times to the windows dll pages, but at the moment beyond me as to what they're saying. I find what works .... make it work how/when I want .... you know the saying ... JACK OF ALL TRADES ... MASTER OF NONE.



Thanks for your time!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 346 guests