Virtual desktop preview

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dilof
Posts: 4
Joined: 20 Mar 2018, 08:07

Virtual desktop preview

20 Mar 2018, 09:32

Hi,
Windows 10 has a built-in live preview of active virtual desktops (activated by Win+Tab), that looks like this:

Image

Now I was wondering, is there any way to access a particular desktop preview and draw it in a GUI?
I want to be able to use my first desktop, while having a little preview on what's on the second desktop:

Image

If you have any ideas, please share with me!
Thanks in advance
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Virtual desktop preview

20 Mar 2018, 16:38

Code: Select all

#NoEnv
#SingleInstance force

F1::
Gui, destroy
Gui,+LastFound +AlwaysOnTop ToolWindow
Gui, Color, Black, Black
Gui, Font, s11 cWhite
num_win = 
WinGet, id, list
Loop, %id%
{	
	this_id := id%A_Index%
	If NOT IsWindow(WinExist("ahk_id" . this_id))
		continue
	hWnd := WinExist("ahk_id " . this_ID)
	If IsWindowOnCurrentVirtualDesktop(hWnd)
		continue
	num_win += 1
}
If (num_win = "")
{
	MsgBox, No windows on other desktop(s)
		return
}
Height := num_win*35
Gui, Add, ListView, w350 h%Height%  -E0x200  -Hdr  gListViewClick, Icon|Title
GoSub, RefreshWindowList
Gui, show, AutoSize, windows on other desktop(s)
return

;------------------------------------
; Activate selected window
;------------------------------------
ListViewClick:
if (A_GuiEvent = "DoubleClick")
{
	Gui, submit
	rowNum:= LV_GetNext(0)
	stringtrimleft, window_id, id_array%rowNum%, 0
	WinGetTitle, WinTitle, ahk_id %window_id%
	WinActivate, ahk_id %window_id%
}
return

;--------------------------------------
; Refresh the list of windows
;--------------------------------------
RefreshWindowList:
; https://autohotkey.com/boards/viewtopic.php?t=9466
	list = 
	num_win = 
	num_allwin = 
	WinGet, id, list
	Loop, %id%
	{
		this_id := id%A_Index%
		If NOT IsWindow(WinExist("ahk_id" . this_id))
			continue
		hWnd := WinExist("ahk_id " . this_ID)
		If IsWindowOnCurrentVirtualDesktop(hWnd)
			continue
		WinGetTitle, title, ahk_id %this_id%	
		num_allwin += 1
		allwin_array%num_allwin% = %title%
		allwinid_array%num_allwin% = %this_id%
	}
	num_win = 0
	Loop, %num_allwin%
	{
		StringTrimRight, title, allwin_array%a_index%, 0
		StringTrimRight, this_id, allwinid_array%a_index%, 0
		num_win += 1
		win_array%num_win% = %title%	
		id_array%num_win%= %this_id%
	}
	ImageListID1 := IL_Create(num_win,1,1)
	LV_SetImageList(ImageListID1, 1)
	LV_Delete()
	empty=0
	iconId_array:=Object()
	iconTitle_array:=Object()
	iconId_Num=0
	loop,%num_win%,
	{
	  ele:=win_array%a_index%
	  wid := id_array%a_index%
	  WinGet, es, ExStyle, ahk_id %wid%
	  iconTitle_array.Insert(win_array%a_index%)
	  iconId_array.Insert(wid)
	  iconId_Num+=1
	  WinGetClass, Win_Class, ahk_id %wid%
	  WinGetTitle, wintitle, ahk_id %wid%
		If (Win_Class = "ApplicationFrameWindow")
		{
			IconNumber := IL_Add(ImageListID1, A_WinDir "\System32\SHELL32.dll" , 3)
			LV_Add("Icon" . IconNumber,a_index-empty ,ele)
		}
		else
		{
			WinGet, Path, ProcessPath, ahk_id %wid%
			IconNumber := IL_Add(ImageListID1, Path,,0)
			  LV_Add("Icon" . IconNumber,a_index-empty ,ele)	
		}
	}
	num_win:=iconId_Num
	for i ,ele in iconId_array{
	   id_array%i%:=ele
	   win_array%i%:=iconTitle_array[i]
	}		
return

;----------------------------------------------------------------------
; Check whether the target window is activation target
;----------------------------------------------------------------------
IsWindow(hWnd){
	WinGet, dwStyle, Style, ahk_id %hWnd%
	if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
		return false
	}
	WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
	if (dwExStyle & 0x00000080) {
		return false
	}
	WinGetClass, szClass, ahk_id %hWnd%
	if (szClass = "TApplication") {
		return false
	}
	return true
}

; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; https://autohotkey.com/boards/viewtopic.php?f=5&t=12388&p=64256#p64256
;------------------------------------------------------------------------------------------------------
; Indicates whether the prvided window is on the currently active virtual desktop.
;------------------------------------------------------------------------------------------------------
IsWindowOnCurrentVirtualDesktop(hWnd) {
	onCurrentDesktop := ""
	CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
	IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
	IVirtualDesktopManager := ComObjCreate(CLSID, IID)	
	Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
	ObjRelease(IVirtualDesktopManager)	
	if !(Error=0)
		return false, ErrorLevel := true
	return onCurrentDesktop, ErrorLevel := false
}
dilof
Posts: 4
Joined: 20 Mar 2018, 08:07

Re: Virtual desktop preview

20 Mar 2018, 16:47

Hey,
Unfortunately this only shows what windows are open on a particular virtual desktop.
I'm looking for a way to get the actual image of what's on the second desktop, so I can redraw it.

Is there a way to take a screenshot of another virtual desktop?
dilof
Posts: 4
Joined: 20 Mar 2018, 08:07

Re: Virtual desktop preview

20 Mar 2018, 18:55

I've managed what I needed to do with GDI's Gdip_BitmapFromHWND on a fullscreen application on a virtual desktop and it works, a bit CPU-intensive though.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Virtual desktop preview

21 Mar 2018, 13:02

Possibly you could use dwm. It will be much lighter on CPU.

Cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Joey5 and 243 guests