* A couple of routines to show how to make it produce a custom caption * animation to make it look like we are minimizing to and maximizing * These routines are public domain, but it would be nice if you dropped * me a line if you use them! * 1.0 29.06.2000 Initial version * 1.1 01.07.2000 The window retains it's place in the Z-order of windows * when minimized/hidden. This means that when restored/shown, it doesn't * always appear as the foreground window unless we call SetForegroundWindow * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com> #define _WIN32_WINNT 0x0500 #include "MinimizeToTray.h" #define DEFAULT_RECT_WIDTH 150 #define DEFAULT_RECT_HEIGHT 30 static void GetTrayWndRect(LPRECT lpTrayRect) { HWND hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL, TEXT("TrayNotifyWnd"), NULL); GetWindowRect(hTrayNotifyWnd,lpTrayRect); appBarData.cbSize = sizeof(appBarData); if(SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) { switch(appBarData.uEdge) { lpTrayRect->top = appBarData.rc.bottom - 100; lpTrayRect->bottom = appBarData.rc.bottom - 16; lpTrayRect->left = appBarData.rc.left; lpTrayRect->right = appBarData.rc.right; lpTrayRect->top = appBarData.rc.top; lpTrayRect->bottom = appBarData.rc.bottom; lpTrayRect->left = appBarData.rc.right - 100; lpTrayRect->right = appBarData.rc.right - 16; hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL); GetWindowRect(hShellTrayWnd, lpTrayRect); if(lpTrayRect->right-lpTrayRect->left > DEFAULT_RECT_WIDTH) lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH; if(lpTrayRect->bottom-lpTrayRect->top > DEFAULT_RECT_HEIGHT) lpTrayRect->top=lpTrayRect->bottom - DEFAULT_RECT_HEIGHT; SystemParametersInfo(SPI_GETWORKAREA, 0, lpTrayRect, 0); lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH; lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT; static BOOL GetDoAnimateMinimize(void) { SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0); return ai.iMinAnimate ? TRUE : FALSE; void MinimizeWndToTray(HWND hWnd) { if(!IsWindowVisible(hWnd)) if(GetDoAnimateMinimize()) { GetWindowRect(hWnd, &rcFrom); DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo); ShowWindow(hWnd, SW_HIDE); void RestoreWndFromTray(HWND hWnd) { if(IsWindowVisible(hWnd)) if(GetDoAnimateMinimize()) { GetWindowRect(hWnd, &rcTo); DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo); ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd);