make gui appear on the other desktop in windows 10 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
k1dr0ck
Posts: 13
Joined: 21 Mar 2017, 22:10

make gui appear on the other desktop in windows 10

22 Mar 2017, 02:01

hi my initial problem was always on top gui but solved it after a search
but now i found a problem
when i switch to another desktop using the script below
the desktop i switched to would not show the gui
is it possible to also show the gui in all the desktop when its initially ran?
or is it possible to move the gui to the desktop that is switched to after clicking the button?


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.

gui, +AlwaysOnTop
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}
 }
return

sub2:
 {
   SendInput ^#{Right}
 }
return

guiclose:
 {
   exitapp
 }
return
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: make gui appear on the other desktop in windows 10  Topic is solved

22 Mar 2017, 17:07

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 :-)
Last edited by qwerty12 on 24 Mar 2017, 07:52, edited 2 times in total.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 351 guests