plugins/docklet/MinimizeToTray.c

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

mercurial