Skip to content

Commit

Permalink
exporting some alt-tab specific functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciantic committed Jun 2, 2019
1 parent a7aa871 commit 5bc1bba
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 21 deletions.
21 changes: 20 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Download the VirtualDesktopAccessor.dll from directory x64\Release\VirtualDeskto

You probably first need the [VS 2017 runtimes vc_redist.x64.exe and/or vc_redist.x86.exe](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads), if they are not installed already. I've built the DLL using VS 2017, and Microsoft is not providing those runtimes (who knows why) with Windows 10 yet.

## Change log

* 02.06.2019:

Exported the Alt+Tab functions prefixed with `View`, this should allow user of the DLL to create native feeling ALT+Tab switcher, since these functions uses the same `IApplicationView` functions as real Alt+Tab switcher itself.

The function to get Alt+Tab windows is basically `ViewGetByLastActivationOrder`.


## AutoHotkey script as example:

```AutoHotkey
Expand Down Expand Up @@ -96,7 +105,7 @@ VWMess(wParam, lParam, msg, hwnd) {
WinGet, activeHwnd, ID, A
isPinned := DllCall(IsPinnedWindowProc, UInt, activeHwnd)
oldHwnd := activeWindowByDesktop[lParam]
isOnDesktop := DllCall(IsWindowOnCurrentVirtualDesktopProc, UInt, oldHwnd, UInt)
isOnDesktop := DllCall(IsWindowOnCurrentVirtualDesktopProc, UInt, oldHwnd, Int)
if (isOnDesktop == 1 && isPinned != 1) {
WinActivate, ahk_id %oldHwnd%
}
Expand Down Expand Up @@ -153,5 +162,15 @@ VWMess(wParam, lParam, msg, hwnd) {
* int IsWindowOnDesktopNumber(HWND window, int number) /
* void RestartVirtualDesktopAccessor() // Call this during taskbar created message

* int ViewIsShownInSwitchers(HWND hwnd) // Is the window shown in Alt+Tab list?
* int ViewIsVisible(HWND hwnd) // Is the window visible?
* HWND ViewGetThumbnailHwnd(HWND hwnd) // Get thumbnail handle for a window, possibly peek preview of Alt+Tab
* void ViewSetFocus(HWND hwnd) // Set focus like Alt+Tab switcher
* HWND ViewGetFocused() // Get focused window thumbnail handle
* void ViewSwitchTo(HWND hwnd) // Switch to window like Alt+Tab switcher
* uint ViewGetByZOrder(HWND *windows, UINT count, BOOL onlySwitcherWindows, BOOL onlyCurrentDesktop) // Get windows in Z-order (NOT alt-tab order)
* uint ViewGetByLastActivationOrder(HWND *windows, UINT count, BOOL onlySwitcherWindows, BOOL onlyCurrentDesktop) // Get windows in alt tab order
* uint ViewGetLastActivationTimestamp(HWND) // Get last activation timestamp

* void EnableKeepMinimized() // Deprecated, does nothing
* void RestoreMinimized() // Deprecated, does nothing
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
std::wcout << "Console Window's Desktop Number: " << GetWindowDesktopNumber(GetConsoleWindow()) << std::endl;
std::wcout << "Current Desktop Number: " << GetCurrentDesktopNumber() << "\r\n";

HWND arr[1024];
UINT numberOfWindows = ViewGetByLastActivationOrder((HWND*)&arr, 1024, 1, 0);
std::wcout << "Number of windows: " << numberOfWindows << std::endl;


HWND notepad = FindWindow(_T("Notepad"), NULL);
if (notepad != 0) {
int number = GetCurrentDesktopNumber();

std::wcout << "Is notepad on this desktop: " << IsWindowOnDesktopNumber(notepad, number) << std::endl;
std::wcout << "Is notepad on current desktop: " << IsWindowOnCurrentVirtualDesktop(notepad) << std::endl;
std::wcout << "Is notepad shown on alt tab switcher: " << ViewIsShownInSwitchers(notepad) << std::endl;
std::wcout << "Is notepad visible: " << ViewIsVisible(notepad) << std::endl;
std::wcout << "Where is thumbnail of notepad: " << ViewGetThumbnailHwnd(notepad) << std::endl;

// Test pinning it
std::wcout << "Try pinning the notepad (the window)." << std::endl;
Expand Down
38 changes: 19 additions & 19 deletions VirtualDesktopAccessor/Win10Desktops.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ DECLARE_INTERFACE_IID_(IApplicationView, IInspectable, "372E1D3B-38D3-42E4-A15B-
/*** IApplicationView methods ***/
STDMETHOD(SetFocus)(THIS) PURE;
STDMETHOD(SwitchTo)(THIS) PURE;
STDMETHOD(TryInvokeBack)(THIS_ IAsyncCallback*) PURE;
STDMETHOD(GetThumbnailWindow)(THIS_ HWND*) PURE;
STDMETHOD(GetMonitor)(THIS_ IImmersiveMonitor**) PURE;
STDMETHOD(GetVisibility)(THIS_ int*) PURE;
STDMETHOD(SetCloak)(THIS_ APPLICATION_VIEW_CLOAK_TYPE, int) PURE;
STDMETHOD(GetPosition)(THIS_ REFIID, void**) PURE;
STDMETHOD(SetPosition)(THIS_ IApplicationViewPosition*) PURE;
STDMETHOD(InsertAfterWindow)(THIS_ HWND) PURE;
STDMETHOD(GetExtendedFramePosition)(THIS_ RECT*) PURE;
STDMETHOD(GetAppUserModelId)(THIS_ PWSTR*) PURE;
STDMETHOD(SetAppUserModelId)(THIS_ PCWSTR) PURE;
STDMETHOD(IsEqualByAppUserModelId)(THIS_ PCWSTR, int*) PURE;
STDMETHOD(GetViewState)(THIS_ UINT*) PURE;
STDMETHOD(SetViewState)(THIS_ UINT) PURE;
STDMETHOD(GetNeediness)(THIS_ int*) PURE;
STDMETHOD(TryInvokeBack)(THIS_ IAsyncCallback*) PURE; // Proc8
STDMETHOD(GetThumbnailWindow)(THIS_ HWND*) PURE; // Proc9
STDMETHOD(GetMonitor)(THIS_ IImmersiveMonitor**) PURE; // Proc10
STDMETHOD(GetVisibility)(THIS_ int*) PURE; // Proc11
STDMETHOD(SetCloak)(THIS_ APPLICATION_VIEW_CLOAK_TYPE, int) PURE; // Proc12
STDMETHOD(GetPosition)(THIS_ REFIID, void**) PURE; // Proc13
STDMETHOD(SetPosition)(THIS_ IApplicationViewPosition*) PURE; // Proc14
STDMETHOD(InsertAfterWindow)(THIS_ HWND) PURE; // Proc15
STDMETHOD(GetExtendedFramePosition)(THIS_ RECT*) PURE; // Proc16
STDMETHOD(GetAppUserModelId)(THIS_ PWSTR*) PURE; // Proc17
STDMETHOD(SetAppUserModelId)(THIS_ PCWSTR) PURE; // Proc18
STDMETHOD(IsEqualByAppUserModelId)(THIS_ PCWSTR, int*) PURE; // Proc19
STDMETHOD(GetViewState)(THIS_ UINT*) PURE; // Proc20
STDMETHOD(SetViewState)(THIS_ UINT) PURE; // Proc21
STDMETHOD(GetNeediness)(THIS_ int*) PURE; // Proc22
STDMETHOD(GetLastActivationTimestamp)(THIS_ ULONGLONG*) PURE;
STDMETHOD(SetLastActivationTimestamp)(THIS_ ULONGLONG) PURE;
STDMETHOD(GetVirtualDesktopId)(THIS_ GUID*) PURE;
Expand All @@ -92,11 +92,11 @@ DECLARE_INTERFACE_IID_(IApplicationView, IInspectable, "372E1D3B-38D3-42E4-A15B-
STDMETHOD(IsInHighZOrderBand)(THIS_ BOOL*) PURE;
STDMETHOD(IsSplashScreenPresented)(THIS_ BOOL*) PURE;
STDMETHOD(Flash)(THIS) PURE;
STDMETHOD(GetRootSwitchableOwner)(THIS_ IApplicationView**) PURE;
STDMETHOD(EnumerateOwnershipTree)(THIS_ IObjectArray**) PURE;
STDMETHOD(GetRootSwitchableOwner)(THIS_ IApplicationView**) PURE; // proc45
STDMETHOD(EnumerateOwnershipTree)(THIS_ IObjectArray**) PURE; // proc46

STDMETHOD(GetEnterpriseId)(THIS_ PWSTR*) PURE;
STDMETHOD(IsMirrored)(THIS_ BOOL*) PURE;
STDMETHOD(GetEnterpriseId)(THIS_ PWSTR*) PURE; // proc47
STDMETHOD(IsMirrored)(THIS_ BOOL*) PURE; //

STDMETHOD(Unknown1)(THIS_ int*) PURE;
STDMETHOD(Unknown2)(THIS_ int*) PURE;
Expand Down
12 changes: 11 additions & 1 deletion VirtualDesktopAccessor/dllmain.def
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ EXPORTS
EnableKeepMinimized @19
RestoreMinimized @20
IsWindowOnDesktopNumber @21
RestartVirtualDesktopAccessor @22
RestartVirtualDesktopAccessor @22

ViewIsShownInSwitchers @23
ViewIsVisible @24
ViewGetThumbnailHwnd @25
ViewSetFocus @26
ViewSwitchTo @27
ViewGetByZOrder @28
ViewGetFocused @29
ViewGetLastActivationTimestamp @30
ViewGetByLastActivationOrder @31
Loading

0 comments on commit 5bc1bba

Please sign in to comment.