FuPeiJiang / VD.ahk

Windows Virtual Desktop, AutoHotkey, Windows 11 support, Windows Server 2022, switch desktop, move window(wintitle) to current desktop; createDesktop, PinWindow, getCount, getDesktopNumOfWindow -> mute all windows in Virtual Desktop
MIT License
319 stars 45 forks source link

Get array of all windows of specific desktop #20

Open phazei opened 1 year ago

phazei commented 1 year ago

I need to be able to get an array with the identifiers for all windows on a specific desktop in order to properly cascade them. Could also be useful to get all the windows of a desktop with filtering for title or application for finer control but that's beyond this request.

More Detail: Win 11 is missing the ability to "CascadeWindows". In Win10 and prior you could just right click on the task bar and do it. Sometimes I have 8+ desktops with 5-10 windows each. Sometimes they cover each other up. There's still a DLL function that allows you to cascade windows though.

I found this thread here: https://www.autohotkey.com/board/topic/80580-how-to-programmatically-tile-cascade-windows/ where a useful "WinArrange" method is created to easily manage windows in different ways. It takes an optional array of windows for the CascadeWindows function: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-cascadewindows

WORD CascadeWindows(
  [in, optional] HWND       hwndParent,
  [in]           UINT       wHow,
  [in, optional] const RECT *lpRect,
  [in]           UINT       cKids,
  [in, optional] const HWND *lpKids
);

cKids is an array of windows. If it isn't used, it tiles the windows in every single desktop all at once with some weird layering results. So being able to get a specific list of windows for virtual desktops would be super helpful.

Thank you!

phazei commented 1 year ago

Ah, ok, so I just saw https://github.com/FuPeiJiang/VD.ahk/issues/8 so you thought about it before.

And I see https://github.com/FuPeiJiang/VD.ahk/blob/class_VD/other%20examples/list%20VD%20of%20all%20windows.ahk So using that I guess I can filter with VD.getCurrentDesktopNum() as well as somehow to get only visible or non-minimized windows and use that as the array item. Hopefully that array can be used with the cKids array. Really I just found out about AutoHotKey a couple hours ago so it's a lot to figure out all at once. Thanks for this helper library!

Edit: Also, the examples are great, but a description of what they specifically do would be super helpful :D

phazei commented 1 year ago

Got it working and made a repo for it https://github.com/phazei/Win11AutoHotKeyFixes