void CompleteSwitch(BOOL doSwitch) { if (!isOpen) return; isOpen = FALSE; TRACE("[ATbot] CompleteSwitch Hiding Window.\n"); ShowWindow(switchdialog, SW_HIDE); if(doSwitch) { if(selectedWindow >= windowCount) return; // FIXME: workaround because reactos fails to activate the previous window correctly. //if(selectedWindow != 0) { HWND hwnd = windowList[selectedWindow]; GetWindowTextW(hwnd, windowText, 1023); TRACE("[ATbot] CompleteSwitch Switching to 0x%08x (%ls)\n", hwnd, windowText); MakeWindowActive(hwnd); } } windowCount = 0; }
BOOL ProcessHotKey(VOID) { if (!isOpen) { windowCount=0; EnumWindowsZOrder(EnumerateCallback, 0); if (windowCount == 0) return FALSE; if (windowCount == 1) { selectedWindow = 0; CompleteSwitch(TRUE); return TRUE; } selectedWindow = 1; TRACE("[ATbot] HotKey Received. Opening window.\n"); ShowWindow(switchdialog, SW_SHOWNORMAL); MakeWindowActive(switchdialog); isOpen = TRUE; } else { TRACE("[ATbot] HotKey Received Rotating.\n"); selectedWindow = (selectedWindow + 1)%windowCount; InvalidateRect(switchdialog, NULL, TRUE); } return TRUE; }
void RotateTasks(BOOL bShift) { HWND hwndFirst, hwndLast; DWORD Size; if (windowCount < 2 || !Esc) return; hwndFirst = windowList[0]; hwndLast = windowList[windowCount - 1]; if (bShift) { SetWindowPos(hwndLast, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREPOSITION); MakeWindowActive(hwndLast); Size = (windowCount - 1) * sizeof(HWND); MoveMemory(&windowList[1], &windowList[0], Size); windowList[0] = hwndLast; } else { SetWindowPos(hwndFirst, hwndLast, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREPOSITION); MakeWindowActive(windowList[1]); Size = (windowCount - 1) * sizeof(HWND); MoveMemory(&windowList[0], &windowList[1], Size); windowList[windowCount - 1] = hwndFirst; } }
void ProcessHotKey() { if (!isOpen) { windowCount=0; EnumWindowsZOrder(EnumerateCallback, 0); if (windowCount < 2) return; selectedWindow = 1; TRACE("[ATbot] HotKey Received. Opening window.\n"); ShowWindow(switchdialog, SW_SHOWNORMAL); MakeWindowActive(switchdialog); isOpen = TRUE; } else { TRACE("[ATbot] HotKey Received Rotating.\n"); selectedWindow = (selectedWindow + 1)%windowCount; InvalidateRect(switchdialog, NULL, TRUE); } }
LRESULT WINAPI DoAppSwitch( WPARAM wParam, LPARAM lParam ) { HWND hwnd, hwndActive; MSG msg; BOOL Esc = FALSE; INT Count = 0; WCHAR Text[1024]; // Already in the loop. if (switchdialog) return 0; hwndActive = GetActiveWindow(); // Nothing is active so exit. if (!hwndActive) return 0; // Capture current active window. SetCapture( hwndActive ); switch (lParam) { case VK_TAB: if( !CreateSwitcherWindow(User32Instance) ) goto Exit; if( !GetDialogFont() ) goto Exit; ProcessHotKey(); break; case VK_ESCAPE: windowCount = 0; Count = 0; EnumWindowsZOrder(EnumerateCallback, 0); if (windowCount < 2) goto Exit; if (wParam == SC_NEXTWINDOW) Count = 1; else { if (windowCount == 2) Count = 0; else Count = windowCount - 1; } TRACE("DoAppSwitch VK_ESCAPE 1 Count %d windowCount %d\n",Count,windowCount); hwnd = windowList[Count]; GetWindowTextW(hwnd, Text, 1023); TRACE("[ATbot] Switching to 0x%08x (%ls)\n", hwnd, Text); MakeWindowActive(hwnd); Esc = TRUE; break; default: goto Exit; } // Main message loop: while (1) { for (;;) { if (PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE )) { if (!CallMsgFilterW( &msg, MSGF_NEXTWINDOW )) break; /* remove the message from the queue */ PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE ); } else WaitMessage(); } switch (msg.message) { case WM_KEYUP: { PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE ); if (msg.wParam == VK_MENU) { CompleteSwitch(TRUE); } else if (msg.wParam == VK_RETURN) { CompleteSwitch(TRUE); } else if (msg.wParam == VK_ESCAPE) { TRACE("DoAppSwitch VK_ESCAPE 2\n"); CompleteSwitch(FALSE); } goto Exit; //break; } case WM_SYSKEYDOWN: { PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE ); if (HIWORD(msg.lParam) & KF_ALTDOWN) { INT Shift; if ( msg.wParam == VK_TAB ) { if (Esc) break; Shift = GetKeyState(VK_SHIFT) & 0x8000 ? SC_PREVWINDOW : SC_NEXTWINDOW; if (Shift == SC_NEXTWINDOW) { selectedWindow = (selectedWindow + 1)%windowCount; } else { selectedWindow = selectedWindow - 1; if (selectedWindow < 0) selectedWindow = windowCount - 1; } InvalidateRect(switchdialog, NULL, TRUE); } else if ( msg.wParam == VK_ESCAPE ) { if (!Esc) break; if (windowCount < 2) goto Exit; if (wParam == SC_NEXTWINDOW) { Count = (Count + 1)%windowCount; } else { Count--; if (Count < 0) Count = windowCount - 1; } hwnd = windowList[Count]; GetWindowTextW(hwnd, Text, 1023); MakeWindowActive(hwnd); } } break; } case WM_LBUTTONUP: PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE ); ProcessMouseMessage(msg.message, msg.lParam); goto Exit; default: if (PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE )) { TranslateMessage(&msg); DispatchMessageW(&msg); } break; } } Exit: ReleaseCapture(); if (switchdialog) DestroyWindow(switchdialog); switchdialog = NULL; selectedWindow = 0; windowCount = 0; return 0; }