Two modifications to make your example simpler
ZhuangQu opened this issue · comments
四维超立方体 commented
In example, you get ahkWindowHwnd
by
ahkWindowHwnd := WinExist("ahk_pid " . DllCall("GetCurrentProcessId", "Uint"))
ahkWindowHwnd += 0x1000 << 32
which is not necessary. AutoHotkey provides the built-in variable A_ScriptHwnd
.
四维超立方体 commented
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.
Jari Pennanen commented
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.