Closed ZhuangQu closed 1 year ago
In example, you call GetCurrentDesktopNumber
by
VDA_PATH := "C:\Source\Rust\winvd\target\release\VirtualDesktopAccessor.dll"
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", VDA_PATH, "Ptr")
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetCurrentDesktopNumber", "Ptr")
current := DllCall(GetCurrentDesktopNumberProc, "UInt")
If you define a function
VDA(func, argv*) {
static path := "C:\Source\Rust\winvd\target\release\VirtualDesktopAccessor.dll"
static dll := DllCall("LoadLibrary", "Str", path, "Ptr")
proc := DllCall("GetProcAddress", "Ptr", dll, "AStr", func, "Ptr")
return DllCall(proc, argv*)
}
then you can call GetCurrentDesktopNumber
only by
current := VDA("GetCurrentDesktopNumber", "UInt")
Other calls like these:
VDA("GoToDesktopNumber", "UInt", index)
VDA("RegisterPostMessageHook", "Int", A_ScriptHwnd, "Int", 0xFFFF)
VDA("GetDesktopName", "UInt", index, "Ptr", buffer)
which are more concise without any global variables.
I switched to using A_ScriptHwnd
.
I don't plan to change the AHK example a lot, I like your function idea but I want to keep this simple.
In example, you get
ahkWindowHwnd
bywhich is not necessary. AutoHotkey provides the built-in variable
A_ScriptHwnd
.