int OnTrayIcon(HWND hwnd) { NOTIFYICONDATA nid; nid.cbSize = sizeof(nid); nid.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_MAIN)); nid.hWnd = hwnd; strcpy(nid.szTip, "작업관리자 Ver1.0"); nid.uCallbackMessage= WM_TRAYMESSAGE; nid.uID = 1; nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; Shell_NotifyIcon(NIM_ADD, &nid); //------------------------------------------------------- // Animation 기능을 구현하기 위한 코드 int cx = GetSystemMetrics(SM_CXSCREEN); int cy = GetSystemMetrics(SM_CYSCREEN); RECT rcWin; GetWindowRect(hwnd, &rcWin); // taskbar의 현재 크기의 개념... RECT rcTray = { cx-50, cy-50, cx, cy }; DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcWin, &rcTray); //--------------------------------------------------------- ShowWindow(hwnd, SW_HIDE); return 0; }
void CSystemTray::MaximiseFromTray(HWND hWnd) { #ifndef _WIN32_WCE if (GetDoWndAnimation()) { RECT rectTo; ::GetWindowRect(hWnd, &rectTo); RECT rectFrom; GetTrayWndRect(&rectFrom); ::SetParent(hWnd, NULL); DrawAnimatedRects(hWnd, IDANI_CAPTION, &rectFrom, &rectTo); } else ::SetParent(hWnd, NULL); SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_VISIBLE); RedrawWindow(hWnd, NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_FRAME | RDW_INVALIDATE | RDW_ERASE); // Move focus away and back again to ensure taskbar icon is recreated if (::IsWindow(m_hWndInvisible)) SetActiveWindow(m_hWndInvisible); SetActiveWindow(hWnd); SetForegroundWindow(hWnd); #endif }
void _UnflipFromTray(UINT i, UINT uCmd) { if (MyIsHungAppWindow(g_pWti[i].hwnd)) return; DeleteTrayIcon(g_hwndMain, g_pWti[i].uID); if (IsWindow(g_pWti[i].hwnd)) { RECT rcTray = { 0 }; if (g_pWti[i].fAnimate && uCmd == SC_RESTORE) { ANIMATIONINFO ai; ai.cbSize = sizeof(ANIMATIONINFO); ai.iMinAnimate = FALSE; SystemParametersInfo(SPI_GETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE); if (ai.iMinAnimate) { HWND hwndTray = FindTrayToolbarWindow(); if (hwndTray) { GetWindowRect(hwndTray, &rcTray); rcTray.bottom = rcTray.top; rcTray.right = rcTray.left; #pragma FIX_LATER(tray animation <-> taskbar pos) KillTimer(g_hwndMain, TIMER_SETANIMATION); ai.iMinAnimate = 0; SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE); SetTimer(g_hwndMain, TIMER_SETANIMATION, 500, NULL); DrawAnimatedRects(g_hwndMain, IDANI_CAPTION, &rcTray, &g_pWti[i].rcWnd); } } } //ShowWindow(g_pWti[i].hwnd, SW_SHOW); SetWindowPos(g_pWti[i].hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); if (uCmd == SC_RESTORE || uCmd == SC_CLOSE) { //ShowWindow(g_pWti[i].hwnd, SW_RESTORE); MySwitchToThisWindow(g_pWti[i].hwnd); if (uCmd == SC_CLOSE) PostMessage(g_pWti[i].hwnd, WM_SYSCOMMAND, SC_CLOSE, 0); } } if (i - 1 != g_cWti) { MoveMemory(g_pWti + i, g_pWti + i + 1, (g_cWti - i - 1) * sizeof(WNDTRAYINFO)); } g_pWti[--g_cWti].hwnd = NULL; }
void MinimizeWndToTray(HWND hWnd) { if(!IsWindowVisible(hWnd)) return; if(GetDoAnimateMinimize()) { RECT rcFrom,rcTo; GetWindowRect(hWnd,&rcFrom); GetTrayWndRect(&rcTo); DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo); } ShowWindow(hWnd,SW_HIDE); }
void CSystemTray::MinimiseToTray(HWND hWnd) { #ifndef _WIN32_WCE if (GetDoWndAnimation()) { RECT rectFrom, rectTo; GetWindowRect(hWnd, &rectFrom); GetTrayWndRect(&rectTo); DrawAnimatedRects(hWnd, IDANI_CAPTION, &rectFrom, &rectTo); } RemoveTaskbarIcon(hWnd); SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) &~ WS_VISIBLE); #endif }
void RestoreWndFromTray(HWND hWnd) { if(IsWindowVisible(hWnd)) return; if(GetDoAnimateMinimize()) { RECT rcFrom,rcTo; GetTrayWndRect(&rcFrom); GetWindowRect(hWnd,&rcTo); DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo); } ShowWindow(hWnd,SW_SHOW); SetActiveWindow(hWnd); SetForegroundWindow(hWnd); }
BOOL FlipToTray(HWND hwnd) { if (g_cWti >= MAX_WNDTRAY) return(FALSE); if (!IsWindow(hwnd)) return(FALSE); HWND hwndShell = GetShellWindow(), hwndTmp, hwndOwner; hwndTmp = hwndOwner = hwnd; do { hwndOwner = hwndTmp; hwndTmp = GetWindow(hwndTmp, GW_OWNER); } while (hwndTmp && hwndTmp != hwndShell); DWORD dw = GetWindowLongPtr(hwndOwner, GWL_STYLE); if (!(dw & WS_MINIMIZEBOX) || dw & WS_CHILD) return(FALSE); //SetForegroundWindow(g_hwndMain); //MySwitchToThisWindow(GetShellWindow()); for (UINT i = 0; i < g_cWti; i++) { if (g_pWti[i].hwnd == hwndOwner) { if (IsWindowVisible(hwndOwner)) _UnflipFromTray(i, 0); else return(FALSE); } } UINT uID = IDC_FIRSTTRAYICON; if (g_cWti > 0) { while (uID < IDC_FIRSTTRAYICON + MAX_WNDTRAY) { BOOL fIs1 = TRUE; for (UINT i = 0; i < g_cWti; i++) { if (g_pWti[i].uID == uID) fIs1 = FALSE; } if (fIs1) break; uID++; } } HICON hIcon, hIconSm; GetWindowIcons(hwndOwner, &hIcon, &hIconSm); WCHAR szCaption[MAX_CAPTION]; InternalGetWindowText(hwndOwner, szCaption, MAX_CAPTION); if (szCaption[0] == L'\0' && hwnd != hwndOwner) { InternalGetWindowText(hwnd, szCaption, MAX_CAPTION); } if (MyIsHungAppWindow(hwndOwner)) return(FALSE); RECT rcTray = { 0 }; g_pWti[g_cWti].fAnimate = FALSE; if (!(dw & WS_MINIMIZE)) { GetWindowRect(hwnd, &g_pWti[g_cWti].rcWnd); ANIMATIONINFO ai; ai.cbSize = sizeof(ANIMATIONINFO); ai.iMinAnimate = FALSE; SystemParametersInfo(SPI_GETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE); if (ai.iMinAnimate) { HWND hwndTray = FindTrayToolbarWindow(); if (hwndTray) { GetWindowRect(hwndTray, &rcTray); rcTray.bottom = rcTray.top; rcTray.right = rcTray.left; KillTimer(g_hwndMain, TIMER_SETANIMATION); g_pWti[g_cWti].fAnimate = TRUE; ai.iMinAnimate = 0; SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE); SetTimer(g_hwndMain, TIMER_SETANIMATION, 500, NULL); DrawAnimatedRects(g_hwndMain, IDANI_CAPTION, &g_pWti[g_cWti].rcWnd, &rcTray); } } //ShowWindow(hwndOwner, SW_MINIMIZE); if (!SendMessageTimeout(hwndOwner, WM_SYSCOMMAND, SC_MINIMIZE, 0, SMTO_ABORTIFHUNG, 500, &dw)) return(FALSE); } //ShowWindow(hwndOwner, SW_HIDE); SetWindowPos(hwndOwner, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW); //if (g_pWti[g_cWti].fAnimate) { //} g_pWti[g_cWti].hwnd = hwndOwner; g_pWti[g_cWti].uID = uID; g_pWti[g_cWti].hIconSm = hIconSm; g_cWti++; AddTrayIcon(g_hwndMain, uID, hIconSm, szCaption); return(TRUE); }