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; }
LRESULT WINAPI DoAppSwitch( WPARAM wParam, LPARAM lParam ) { HWND hwndActive; MSG msg; // FIXME: Is loading timing OK? LoadCoolSwitchSettings(); if (!CoolSwitch) return 0; // Already in the loop. if (switchdialog || Esc) return 0; hwndActive = GetActiveWindow(); // Nothing is active so exit. if (!hwndActive) return 0; if (lParam == VK_ESCAPE) { Esc = TRUE; windowCount = 0; EnumWindowsZOrder(EnumerateCallback, 0); if (windowCount < 2) return 0; RotateTasks(GetAsyncKeyState(VK_SHIFT) < 0); hwndActive = GetActiveWindow(); if (hwndActive == NULL) { Esc = FALSE; return 0; } } // Capture current active window. SetCapture( hwndActive ); switch (lParam) { case VK_TAB: if( !CreateSwitcherWindow(User32Instance) ) goto Exit; if( !GetDialogFont() ) goto Exit; if( !ProcessHotKey() ) goto Exit; break; case VK_ESCAPE: 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) { if ( msg.wParam == VK_TAB ) { if (Esc) break; if (GetKeyState(VK_SHIFT) < 0) { MoveLeft(); } else { MoveRight(); } } else if ( msg.wParam == VK_ESCAPE ) { if (!Esc) break; RotateTasks(GetKeyState(VK_SHIFT) < 0); } else if ( msg.wParam == VK_LEFT ) { MoveLeft(); } else if ( msg.wParam == VK_RIGHT ) { MoveRight(); } else if ( msg.wParam == VK_UP ) { MoveUp(); } else if ( msg.wParam == VK_DOWN ) { MoveDown(); } } 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); if (Esc) DestroyAppWindows(); switchdialog = NULL; selectedWindow = 0; windowCount = 0; Esc = FALSE; return 0; }