3630
|
1 /* MinimizeToTray
|
|
2 *
|
|
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
|
|
5 * from the system tray
|
|
6 *
|
|
7 * These routines are public domain, but it would be nice if you dropped
|
|
8 * me a line if you use them!
|
|
9 *
|
|
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 doen't
|
|
13 * always appear as the foreground window unless we call SetForegroundWindow
|
|
14 *
|
|
15 * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com>
|
|
16 */
|
|
17 #include "stdafx.h"
|
|
18
|
|
19 #ifndef IDANI_OPEN
|
|
20 #define IDANI_OPEN 1
|
|
21 #endif
|
|
22 #ifndef IDANI_CLOSE
|
|
23 #define IDANI_CLOSE 2
|
|
24 #endif
|
|
25 #ifndef IDANI_CAPTION
|
|
26 #define IDANI_CAPTION 3
|
|
27 #endif
|
|
28
|
|
29 #define DEFAULT_RECT_WIDTH 150
|
|
30 #define DEFAULT_RECT_HEIGHT 30
|
|
31
|
|
32 static void GetTrayWndRect(LPRECT lpTrayRect)
|
|
33 {
|
|
34 APPBARDATA appBarData;
|
|
35 HWND hShellTrayWnd=FindWindowEx(NULL,NULL,TEXT("Shell_TrayWnd"),NULL);
|
|
36
|
|
37 if(hShellTrayWnd)
|
|
38 {
|
|
39 HWND hTrayNotifyWnd=FindWindowEx(hShellTrayWnd,NULL,TEXT("TrayNotifyWnd"),NULL);
|
|
40 if(hTrayNotifyWnd)
|
|
41 {
|
|
42 GetWindowRect(hTrayNotifyWnd,lpTrayRect);
|
|
43 return;
|
|
44 }
|
|
45 }
|
|
46
|
|
47 appBarData.cbSize=sizeof(appBarData);
|
|
48 if(SHAppBarMessage(ABM_GETTASKBARPOS,&appBarData))
|
|
49 {
|
|
50 switch(appBarData.uEdge)
|
|
51 {
|
|
52 case ABE_LEFT:
|
|
53 case ABE_RIGHT:
|
|
54 lpTrayRect->top=appBarData.rc.bottom-100;
|
|
55 lpTrayRect->bottom=appBarData.rc.bottom-16;
|
|
56 lpTrayRect->left=appBarData.rc.left;
|
|
57 lpTrayRect->right=appBarData.rc.right;
|
|
58 break;
|
|
59
|
|
60 case ABE_TOP:
|
|
61 case ABE_BOTTOM:
|
|
62 lpTrayRect->top=appBarData.rc.top;
|
|
63 lpTrayRect->bottom=appBarData.rc.bottom;
|
|
64 lpTrayRect->left=appBarData.rc.right-100;
|
|
65 lpTrayRect->right=appBarData.rc.right-16;
|
|
66 break;
|
|
67 }
|
|
68
|
|
69 return;
|
|
70 }
|
|
71
|
|
72 hShellTrayWnd=FindWindowEx(NULL,NULL,TEXT("Shell_TrayWnd"),NULL);
|
|
73 if(hShellTrayWnd)
|
|
74 {
|
|
75 GetWindowRect(hShellTrayWnd,lpTrayRect);
|
|
76 if(lpTrayRect->right-lpTrayRect->left>DEFAULT_RECT_WIDTH)
|
|
77 lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH;
|
|
78 if(lpTrayRect->bottom-lpTrayRect->top>DEFAULT_RECT_HEIGHT)
|
|
79 lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT;
|
|
80
|
|
81 return;
|
|
82 }
|
|
83
|
|
84 SystemParametersInfo(SPI_GETWORKAREA,0,lpTrayRect,0);
|
|
85 lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH;
|
|
86 lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT;
|
|
87 }
|
|
88
|
|
89 static int GetDoAnimateMinimize(void)
|
|
90 {
|
|
91 ANIMATIONINFO ai;
|
|
92
|
|
93 ai.cbSize=sizeof(ai);
|
|
94 SystemParametersInfo(SPI_GETANIMATION,sizeof(ai),&ai,0);
|
|
95
|
|
96 return ai.iMinAnimate?TRUE:FALSE;
|
|
97 }
|
|
98
|
|
99 void MinimizeWndToTray(HWND hWnd)
|
|
100 {
|
|
101 if(GetDoAnimateMinimize())
|
|
102 {
|
|
103 RECT rcFrom,rcTo;
|
|
104
|
|
105 GetWindowRect(hWnd,&rcFrom);
|
|
106 GetTrayWndRect(&rcTo);
|
|
107
|
|
108 DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
|
|
109 }
|
|
110
|
|
111 ShowWindow(hWnd,SW_HIDE);
|
|
112 }
|
|
113
|
|
114 void RestoreWndFromTray(HWND hWnd)
|
|
115 {
|
|
116 if(GetDoAnimateMinimize())
|
|
117 {
|
|
118 RECT rcFrom,rcTo;
|
|
119 GetTrayWndRect(&rcFrom);
|
|
120 GetWindowRect(hWnd,&rcTo);
|
|
121
|
|
122 DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
|
|
123 }
|
|
124
|
|
125 ShowWindow(hWnd,SW_SHOW);
|
|
126 SetActiveWindow(hWnd);
|
|
127 SetForegroundWindow(hWnd);
|
|
128
|
|
129 }
|
|
130
|
|
131
|
|
132
|