3 * A couple of routines to show how to make it produce a custom caption
4 * animation to make it look like we are minimizing to and maximizing
7 * These routines are public domain, but it would be nice if you dropped
8 * me a line if you use them!
10 * 1.0 29.06.2000 Initial version
11 * 1.1 01.07.2000 The window retains it's place in the Z-order of windows
12 * when minimized/hidden. This means that when restored/shown, it doesn't
13 * always appear as the foreground window unless we call SetForegroundWindow
15 * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com>
19 #include "MinimizeToTray.h"
21 #define DEFAULT_RECT_WIDTH 150
22 #define DEFAULT_RECT_HEIGHT 30
24 static void GetTrayWndRect(LPRECT lpTrayRect
) {
25 APPBARDATA appBarData
;
26 HWND hShellTrayWnd
= FindWindowEx(NULL
, NULL
, TEXT("Shell_TrayWnd"),
30 HWND hTrayNotifyWnd
= FindWindowEx(hShellTrayWnd
, NULL
,
31 TEXT("TrayNotifyWnd"), NULL
);
34 GetWindowRect(hTrayNotifyWnd
,lpTrayRect
);
39 appBarData
.cbSize
= sizeof(appBarData
);
40 if(SHAppBarMessage(ABM_GETTASKBARPOS
, &appBarData
)) {
41 switch(appBarData
.uEdge
) {
44 lpTrayRect
->top
= appBarData
.rc
.bottom
- 100;
45 lpTrayRect
->bottom
= appBarData
.rc
.bottom
- 16;
46 lpTrayRect
->left
= appBarData
.rc
.left
;
47 lpTrayRect
->right
= appBarData
.rc
.right
;
51 lpTrayRect
->top
= appBarData
.rc
.top
;
52 lpTrayRect
->bottom
= appBarData
.rc
.bottom
;
53 lpTrayRect
->left
= appBarData
.rc
.right
- 100;
54 lpTrayRect
->right
= appBarData
.rc
.right
- 16;
60 hShellTrayWnd
= FindWindowEx(NULL
, NULL
, TEXT("Shell_TrayWnd"), NULL
);
62 GetWindowRect(hShellTrayWnd
, lpTrayRect
);
63 if(lpTrayRect
->right
-lpTrayRect
->left
> DEFAULT_RECT_WIDTH
)
64 lpTrayRect
->left
= lpTrayRect
->right
- DEFAULT_RECT_WIDTH
;
65 if(lpTrayRect
->bottom
-lpTrayRect
->top
> DEFAULT_RECT_HEIGHT
)
66 lpTrayRect
->top
=lpTrayRect
->bottom
- DEFAULT_RECT_HEIGHT
;
71 SystemParametersInfo(SPI_GETWORKAREA
, 0, lpTrayRect
, 0);
72 lpTrayRect
->left
= lpTrayRect
->right
- DEFAULT_RECT_WIDTH
;
73 lpTrayRect
->top
= lpTrayRect
->bottom
- DEFAULT_RECT_HEIGHT
;
76 static BOOL
GetDoAnimateMinimize(void) {
79 ai
.cbSize
= sizeof(ai
);
80 SystemParametersInfo(SPI_GETANIMATION
, sizeof(ai
), &ai
, 0);
82 return ai
.iMinAnimate
? TRUE
: FALSE
;
85 void MinimizeWndToTray(HWND hWnd
) {
87 if(!IsWindowVisible(hWnd
))
90 if(GetDoAnimateMinimize()) {
93 GetWindowRect(hWnd
, &rcFrom
);
94 GetTrayWndRect(&rcTo
);
96 DrawAnimatedRects(hWnd
, IDANI_CAPTION
, &rcFrom
, &rcTo
);
99 ShowWindow(hWnd
, SW_HIDE
);
102 void RestoreWndFromTray(HWND hWnd
) {
104 if(IsWindowVisible(hWnd
))
107 if(GetDoAnimateMinimize()) {
109 GetTrayWndRect(&rcFrom
);
110 GetWindowRect(hWnd
, &rcTo
);
112 DrawAnimatedRects(hWnd
, IDANI_CAPTION
, &rcFrom
, &rcTo
);
115 ShowWindow(hWnd
, SW_SHOW
);
116 SetActiveWindow(hWnd
);
117 SetForegroundWindow(hWnd
);