Jump to content

Virtual Desktop Manager under Windows 10


Nine
 Share

Recommended Posts

  • 3 weeks later...

your job is stunning and a great start. Let's see if i can help with a little more CODE

Local $tagIVirtualDesktopPinnedApps = _
    "IsAppIdPinned hresult(wstr,bool*);" & _        ; this is the hwnd but might need to be passed as (string appId)
    "PinAppID hresult(wstr);" & _
    "UnpinAppID hresult(wstr);" & _
    "IsViewPinned hresult(ptr,bool*);" & _
    "PinView hresult(ptr);" & _
    "UnpinView hresult(ptr);"
       
   ; ------
        
$oService.QueryService($tCLSID_VirtualDesktopPinnedApps, $tIID_IVirtualDesktopPinnedApps, $pVirtualDesktopPinnedApps)
ConsoleWrite("Virtual Desktop Pinned Apps = " & $pVirtualDesktopPinnedApps & @CRLF)
Local $oVirtualDesktopPinnedApps = ObjCreateInterface($pVirtualDesktopPinnedApps, $IID_IVirtualDesktopPinnedApps, $tagIVirtualDesktopPinnedApps)
ConsoleWrite("Virtual Desktop Pinned Apps = " & IsObj($oVirtualDesktopPinnedApps) & @CRLF)

;-------------
$iHresult = $oVirtualDesktopPinnedApps.PinView($pView)
ConsoleWrite("Pinned View = " & $iHresult & @CRLF)
$iHresult = $oVirtualDesktopPinnedApps.UnpinView($pView)
ConsoleWrite("UnPinned View = " & $iHresult & @CRLF)

while everying works great if we pin the view i cannot get the PinAppID mode to work correctly. As a matter of fact it requires the appId to work and I do not know how to source that information properly.

Trust somebody can complete this, so we can finally create an amazing virtual desktop manager for win10/11 with few simple Autoit lines

Link to comment
Share on other sites

Here I think how you could do. 

1- Get the ptr view of the hwnd with ApplicationViewCollection object (as already shown in my example)

2- Create an ApplicationView object with this ptr

3- Use GetAppUserModelId method to obtain the wstr of the AppID

4- Use that string within *AppId* method of VirtualDesktopPinnedApps object.

Untested.

If that works, please provide FULL snippet of the code you have created.  Thanks.

Link to comment
Share on other sites

Local $IID_IApplicationView = "{372E1D3B-38D3-42E4-A15B-8AB2B178F513}"
; need to define tag of this here

...

$hWnd = WinGetHandle("[CLASS:Notepad]")
$iHresult = $oApplicationViewCollection.GetViewForHwnd($hWnd, $pView)
ConsoleWrite("View from handle = " & $pView & "/" & $iHresult & @CRLF)

Local $oView = ObjCreateInterface($pView, $IID_IApplicationView, "")  ; no need for tag to create object
ConsoleWrite("Application view = " & IsObj($oView) & @CRLF)

Works for me...So step 2 resolved :)

Link to comment
Share on other sites

  •  ☺️
  •  may be you want to edit
  • since you did most of the work you might want to add the option to pin a view to all desktops, it is tested and works.
  • I still need to test the possibility to pin the appID which will allow all sub-windows opened by the app to stay pinned to all desktops
  • I am currently building the whole app to have a small virtual-desktop manager up and running in the Taskbar. With your permission I might upload the whole code when finished in my area

 

$eRightDirection=4

Link to comment
Share on other sites

29 minutes ago, Hermano said:

$eRightDirection=4

No need to specify = 4 since the previous is at 3.

30 minutes ago, Hermano said:

With your permission I might upload the whole code when finished in my area

Glad you can run on my example.  No problem.

Link to comment
Share on other sites

😓

VIRTUAL DESKTOP MANAGER LIBRARY FOR WINDOWS 10 (11 NOT TESTED)

it has been a lot of work and testing. I could find some minor imperfections in the previous snippets we wrote and finally here is the full library to properly manage win10 virtual desktop system. Every function has been tested but I am sure that our great community will find several improvements and adds-on we did not think of. Without all your contribution this would not have been possible.

The library has 4 examples embedded and commented (please do not hesitate to add more). The objects created offers lots of extra tags that I did not use

The core objects created where:

Global $oVirtualDesktopManagerInternal
Global $oApplicationViewCollection
Global $oVirtualDesktopPinnedApps
Local $oApplicationView

I list them here so that anyone interested in using the same objects for other functions can easily find a reference

Enjoy  😃

 

VritDsktLibrary.au3

Edited by Hermano
Link to comment
Share on other sites

  • 3 months later...

Up to now I am not really using Virtual Desktops, but this library made me think about it.  
I tried a wallpaper changer found in this forum to set individual desktops, but the new wallpaper is set for all VDT, just as if I do it via Windows desktop settings. 
So a static approach does not seem to work.

I wonder if a dynamic approach would work.
Could I use this library to react on a VDT switch (Ctrl+Win+Arrow) and set the wallpaper individually for the new VDT?

Edited by PowerJack
Link to comment
Share on other sites

@PowerJack Sorry for the late reply, I was busy on another project.  I believe there is an interface that can actually set wallpaper individually.  It is called IActiveDesktop with the method SetWallpaper.  I will try to find some times to look it up more closely but it seems promising.

Edited by Nine
Link to comment
Share on other sites

Well, well, my current OS (Win10 21H1) does not allow me to set individual wallpaper for each virtual desktops.  So I cannot test if this interface is working or not.  At present time, it changes the wallpaper to all VDT.  To test if you are allowed or not, press Win+Tab, right-click on the VDT you want to change, it should offer you the possibility (Choose background).  Like me, if it does not, it means your OS has not that feature.

Link to comment
Share on other sites

Here is the code to change the wallpaper of individual virtual desktop.  If someone can test it, it would be greatly appreciated.  Just create a new VDT, navigate to it and run this script.  Since my OS does not allow it (see previous post), I do not know if it is actually working like expected.  

Opt("MustDeclareVars", True)

If @OSVersion <> "WIN_10" Then Exit MsgBox($MB_SYSTEMMODAL, "", "This script only runs on Win 10")

Global Const $AD_GETWP_IMAGE = 1
Global Const $AD_APPLY_ALL = 7

Global $CLSID_ActiveDesktop = "{75048700-ef1f-11d0-9888-006097deacf9}"
Global $IID_IActiveDesktop = "{f490eb00-1240-11d1-9888-006097deacf9}"

; implemented only first 3 methods
Global $tagIActiveDesktop = _
  "ApplyChanges hresult(dword);" & _
  "GetWallpaper hresult(struct*;uint;dword);" & _
  "SetWallpaper hresult(wstr;dword)"

; create object
Local $oActiveDesktop = ObjCreateInterface($CLSID_ActiveDesktop, $IID_IActiveDesktop, $tagIActiveDesktop)
ConsoleWrite(IsObj($oActiveDesktop) & @CRLF)

; get current wallpaper
Local $iHresult, $iLength = 100
Local $tName = DllStructCreate("wchar string[" & $iLength & "]")
$iHresult = $oActiveDesktop.GetWallpaper(DllStructGetPtr($tName), $iLength, $AD_GETWP_IMAGE)
ConsoleWrite($tName.string & "/" & $iHresult & @CRLF)

; set new wallpaper
$iHresult = $oActiveDesktop.SetWallpaper("C:\Windows\Web\Wallpaper\acer01.jpg", 0)  ; <<<<<<<<<<< set correct path to WP file
ConsoleWrite($iHresult & @CRLF)
$iHresult = $oActiveDesktop.ApplyChanges($AD_APPLY_ALL)
ConsoleWrite($iHresult & @CRLF)

Thank you all.

Link to comment
Share on other sites

Thank you @Nine.

My Windows doesn’t support it either. My idea was to catch a VDT switch done by the user and then set a new wallpaper (for all DT). But the more I think about It the more it feels like overkill. 

I think your code example comes in handy as soon as Microsoft have done their homework on my PC or when I upgrade to Win11.

Link to comment
Share on other sites

  • 4 months later...

Hi, I have a few questions:

1) will this work under Windows 11 as well? I ask because I notice that some virtual desktop tools I've been using before on win10 don't seem to work on win11

2) where can I find this 

Quote

__uuidof()

function ?

Link to comment
Share on other sites

Link to comment
Share on other sites

I get 

Quote

: ==> Variable must be of type "Object".:
$iHresult = $oVirtualDesktopManagerInternal.GetCount($iCount)
$iHresult = $oVirtualDesktopManagerInternal^ ERROR

so I guess the answer is no, it doesn't work on windows 11 (

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...