Ciantic / VirtualDesktopAccessor

DLL for accessing Windows 11/10 Virtual Desktop features from e.g. AutoHotkey
MIT License
772 stars 93 forks source link

OnChangeDesktop in ahk doesn't work #76

Closed achim-t closed 1 year ago

achim-t commented 1 year ago

The code is pretty much from the example:

RegisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RegisterPostMessageHook", "Ptr")
DllCall(RegisterPostMessageHookProc, "Ptr", A_ScriptHwnd, "Int", 0x1400 + 30, "Int")
OnMessage(0x1400 + 30, "OnChangeDesktop")
OnChangeDesktop(wParam, lParam, msg, hwnd) {
    Critical, 100
    OldDesktop := wParam + 1
    NewDesktop := lParam + 1

    OutputDebug % "Desktop changed from " OldDesktop " to " NewDesktop
}

When I change the desktop (by Win+Tab and click on different desktop) I would expect a message in the debugger. But there is no output.

Other functions like GetDesktopCount work.

full script ```ahk #SingleInstance, Force SendMode Input SetWorkingDir, %A_ScriptDir% ; Path to the DLL, relative to the script VDA_PATH := A_ScriptDir . "\libraries\virtual-desktop-accessor.dll" hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", VDA_PATH, "Ptr") GetDesktopCountProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetDesktopCount", "Ptr") GetDesktopCount() { global GetDesktopCountProc count := DllCall(GetDesktopCountProc, "Int") return count } CountDesktops() { c := GetDesktopCount() OutputDebug, % "There are " c " virtual desktops" } RegisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RegisterPostMessageHook", "Ptr") DllCall(RegisterPostMessageHookProc, "Ptr", A_ScriptHwnd, "Int", 0x1400 + 30, "Int") OnMessage(0x1400 + 30, "OnChangeDesktop") OnChangeDesktop(wParam, lParam, msg, hwnd) { Critical, 100 OldDesktop := wParam + 1 NewDesktop := lParam + 1 OutputDebug % "Desktop changed from " OldDesktop " to " NewDesktop } F1::CountDesktops() ```
Ciantic commented 1 year ago

What version of Windows is that? Try opening "winver.exe" I have 22621.2283, with lastest DLL the OnChangeDesktop works.

achim-t commented 1 year ago

Well, it works now. I guess I had a mix up with different versions of the DLL. Thank you.