/** Clean up memory. * This is called after the X connection is closed. * Note that it is possible for this to be called more than once. */ void Destroy(void) { DestroyBackgrounds(); DestroyBorders(); DestroyClients(); DestroyClock(); DestroyColors(); DestroyCommands(); DestroyCursors(); DestroyDesktops(); #ifndef DISABLE_CONFIRM DestroyDialogs(); #endif DestroyDock(); DestroyFonts(); DestroyGroups(); DestroyHints(); DestroyIcons(); DestroyKeys(); DestroyPager(); DestroyPlacement(); DestroyPopup(); DestroyRootMenu(); DestroyScreens(); DestroySettings(); DestroySwallow(); DestroyTaskBar(); DestroyTray(); DestroyTrayButtons(); }
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static BOOL s_fConfirmActive = FALSE; static UINT s_uTaskbarCreated = 0; switch (uMsg) { case WM_HOTKEY: { switch (wParam) { case IDH_NEXTTASK: case IDH_PREVTASK: case IDH_WINNEXTTASK: case IDH_WINPREVTASK: case IDH_INSTNEXT: case IDH_INSTPREV: case IDH_STNEXTTASK: case IDH_STINEXTTASK: ShowTaskSwitchWnd((UINT)wParam); break; case IDH_MINIMIZETRAY: FlipToTray(GetForegroundWindow()); break; case IDH_RESTORETRAY: if (g_cWti > 0) _UnflipFromTray(g_cWti - 1); break; case IDH_SHOWHIDE: ShowTrayIcon(!(g_dwFlags & TSF_SHOWTRAYICON)); break; case IDH_CONFIG: ConfigTaskSwitchXP(); break; case IDH_ALTAPPLIST: //MessageBox (0, L"This must display alternative task switching window\r\n" // L"(or the same window but in alternative mode)", L"klvov says:", MB_OK); //ShowAltTSWindow(); //OutputDebugString(L"IDH_ALTAPPLIST message received\n"); ShowTaskSwitchWnd((UINT)wParam); break; case IDH_EXIT: if (!(g_dwFlags & TSF_NOCONFIRMEXIT)) { if (s_fConfirmActive) { // activate confirm dialog #pragma FIX_LATER(multiple exit confirmations) break; /*HWND hwndMsg = FindWindowEx(NULL, NULL, L"#32770", L"TaskSwitchXP confirmation"); if (hwndMsg) { SetForegroundWindow(hwndMsg); break; }*/ } s_fConfirmActive = TRUE; if (ConfirmMessage(IDS_CONFIRM_EXIT)) DestroyWindow(hwnd); s_fConfirmActive = FALSE; } else DestroyWindow(hwnd); break; } break; } case WM_TIMER: if (wParam == TIMER_RIGHTUP) { KillTimer(hwnd, TIMER_RIGHTUP); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTUP, _ptRClick.x, _ptRClick.y, _dwRData, _dwRExtraInfo); } else if (wParam == TIMER_SETANIMATION) { KillTimer(hwnd, TIMER_SETANIMATION); ANIMATIONINFO ai; ai.cbSize = sizeof(ANIMATIONINFO); ai.iMinAnimate = TRUE; SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE); } else if (wParam == TIMER_CHECKTRAYWND) { for (UINT i = 0; i < g_cWti; i++) { if (!IsWindow(g_pWti[i].hwnd) || IsWindowVisible(g_pWti[i].hwnd)) _UnflipFromTray(i, SC_MINIMIZE); } } else if (wParam == TIMER_RELOADICONS) { if (!(g_dwFlags & TSF_RELOADICONS)) KillTimer(hwnd, TIMER_RELOADICONS); ReloadTsTrayIcons(); } else if (wParam == TIMER_CHECKCOLORS) { KillTimer(hwnd, TIMER_CHECKCOLORS); if (CheckColorTheme()) CheckDefaultColors(); } else if (wParam == TIMER_CLOSEDESK) { if (WaitForSingleObject(g_hThreadTs, 0) == WAIT_OBJECT_0) { KillTimer(hwnd, TIMER_CLOSEDESK); //_RPT0(_CRT_WARN, "close desk\n"); if (g_hThreadTs) { CloseHandle(g_hThreadTs); g_hThreadTs = NULL; } if (g_hDesk) { CloseDesktop(g_hDesk); g_hDesk = NULL; } } } break; case WM_REMOTECMD: SwitchToThisWindow(hwnd, TRUE); if (wParam & CCLF_ESCAPE) { if (g_hwndTs) PostMessage(g_hwndTs, WM_TASKSWITCH, IDH_ESCAPE, 0); } else if (wParam & CCLF_STINEXTTASK) { ShowTaskSwitchWnd(IDH_STINEXTTASK); } else if (wParam & CCLF_STNEXTTASK) { ShowTaskSwitchWnd(IDH_STNEXTTASK); } break; case WM_MYTRAYMSG: if (wParam == IDI_TASKSWITCHXP) { if ((UINT)lParam == g_uTrayMenu) { ShowTrayMenu(); } else if ((UINT)lParam == g_uTrayConfig) { ConfigTaskSwitchXP(); } else if ((UINT)lParam == g_uTrayNext) { ShowTaskSwitchWnd(IDH_STTRAYNEXT); } else if ((UINT)lParam == g_uTrayPrev) { ShowTaskSwitchWnd(IDH_STITRAYNEXT); } } else { if (lParam == WM_LBUTTONUP) { UnflipFromTrayID((UINT)wParam); } else if (lParam == WM_RBUTTONUP) { ShowFlippedSystemMenu((UINT)wParam); } else if (lParam == WM_MBUTTONUP) UnflipFromTrayID((UINT)wParam, 0); } break; case WM_EXTMOUSE: if (wParam == HTMINBUTTON) { FlipToTray((HWND)lParam); } else if (wParam == HTMAXBUTTON) { HWND h = (HWND)lParam; DWORD dwExStyle = GetWindowLongPtr(h, GWL_EXSTYLE); SetWindowPos(h, ((dwExStyle & WS_EX_TOPMOST) ? HWND_NOTOPMOST : HWND_TOPMOST), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } break; case WM_FLIPTOTRAY: return(FlipToTray((HWND)wParam)); //break; case WM_UNFLIPFROMTRAY: UnflipFromTray((HWND)wParam, (UINT)lParam); break; case WM_GETTRAYWINDOWS: if (wParam) { HWND *phWnd = (HWND*)wParam; int cWti = 0; while (cWti < MIN((int)lParam, (int)g_cWti)) { phWnd[cWti] = g_pWti[cWti].hwnd; cWti++; } return(cWti); } else return(g_cWti); break; case WM_RELOADSETTINGS: if (!LoadSettings()) { ReportError(IDS_ERR_LOADSETTINGS); DestroyWindow(hwnd); } break; case WM_THEMECHANGED: if (CheckColorTheme()) CheckDefaultColors(); SetTimer(hwnd, TIMER_CHECKCOLORS, 1000, NULL); break; case WM_CREATE: { s_uTaskbarCreated = RegisterWindowMessage(L"TaskbarCreated"); g_hwndMain = hwnd; SendMessage(hwnd, WM_SETICON, ICON_BIG, (LONG)(LONG_PTR)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR)); SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LONG)(LONG_PTR)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR)); if (!LoadSettings()) { ReportError(IDS_ERR_LOADSETTINGS); return(-1); } if (!InitPreviewThread()) return(-1); // Weird huh? I cannot understand this... if (g_dwShowDelay && g_dwFlagsPv & TSFPV_DESKTOP && g_dwFlagsPv & TSFPV_TASKBAR) { RECT rcPvEx; rcPvEx.left = rcPvEx.top = 0; rcPvEx.right = 102; rcPvEx.bottom = 76; HDC hdcScreen = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(hdcScreen); HBITMAP hbitmapMem = CreateCompatibleBitmap(hdcScreen, rcPvEx.right - rcPvEx.left, rcPvEx.bottom - rcPvEx.top); ReleaseDC(NULL, hdcScreen); if (hbitmapMem) { HBITMAP hbitmapOld = (HBITMAP)SelectObject(hdcMem, hbitmapMem); SetForegroundWindow(g_hwndMain); MyPrintWindow(FindWindow(L"Shell_TrayWnd", L""), hdcMem, &rcPvEx, &rcPvEx, MPW_NOCHECKPOS); SelectObject(hdcMem, hbitmapOld); DeleteObject(hbitmapMem); } DeleteDC(hdcMem); } SetTimer(hwnd, TIMER_CHECKTRAYWND, 1000, NULL); if (g_dwCmdLine & CCLF_STINEXTTASK) { ShowTaskSwitchWnd(IDH_STINEXTTASK); } else if (g_dwCmdLine & CCLF_STNEXTTASK) { ShowTaskSwitchWnd(IDH_STNEXTTASK); } break; } case WM_CLOSE: break; case WM_DESTROY: KillTimer(hwnd, TIMER_CHECKTRAYWND); DestroySettings(); DestroyPreviewThread(); for (int i = (int)g_cWti - 1; i >= 0; i--) _UnflipFromTray((UINT)i, 0); PostQuitMessage(0); break; default: if (uMsg == s_uTaskbarCreated) { ReloadTsTrayIcons(); } else return(DefWindowProc(hwnd, uMsg, wParam, lParam)); break; } return(0); }