Hi,
k1dr0ck wrote:or is it possible to move the gui to the desktop that is switched to after clicking the button?
This is an
unreliable way of doing it using the neutered
IVirtualDesktopManager interface. IVirtualDesktopManagerInternal is much better and far more reliable, but sadly, unless you know what to change (and how to find the new values needed), code using it will break with each new Windows 10 major release, so it's best to stick with something like this.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoTrayIcon
#SingleInstance force
gui, +AlwaysOnTop +HwndhwndGui
gui, add, button, x10 y5 h20 w35 gsub1, <-
gui, add, button, x55 y5 h20 w35 gsub2, ->
gui, show, x15 y680 h30 w100
return
sub1:
{
SendInput ^#{Left}
movewindow(hwndGui)
}
return
sub2:
{
SendInput ^#{Right}
movewindow(hwndGui)
}
return
guiclose:
{
exitapp
}
return
movewindow(guiHwnd)
{
static desktopID
if (!VarSetCapacity(desktopID))
VarSetCapacity(desktopID, 16)
try IVirtualDesktopManager := ComObjCreate("{aa509086-5ca9-4c25-8f95-589d3c07b48a}", "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}")
if (IVirtualDesktopManager) {
Loop 10 { ; wait to see until our main GUI is not on the starting virtual desktop
hr := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", guiHwnd, "Int*", onCurrentDesktop)
if (hr == "" || hr < 0) {
ObjRelease(IVirtualDesktopManager)
return
}
Sleep 100
if (!onCurrentDesktop)
break
}
if (!onCurrentDesktop) {
gui tmp: +Hwndfuckms ; create a new temporary GUI belonging to our process on the new virtual desktop
gui tmp: show
hr := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 4 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", fuckms, "Ptr", &desktopID) ; get the GUID of the virtual desktop hosting our temporary window
Gui tmp: destroy
if (hr == 0 && DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 5 * A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", guiHwnd, "Ptr", &desktopID) == 0) ; move the main window to the same desktop
WinActivate ahk_id %guiHwnd% ; re-activate the window
}
ObjRelease(IVirtualDesktopManager)
}
}
EDIT: You're welcome