comparison gtk/win32/MinimizeToTray.c @ 14681:2c1781ea074c

[gaim-migrate @ 17433] Depluginize the docklet. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 05 Oct 2006 23:24:00 +0000
parents
children
comparison
equal deleted inserted replaced
14680:fa285d018c71 14681:2c1781ea074c
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 doesn'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 #define _WIN32_WINNT 0x0500
18 #include <windows.h>
19 #include "MinimizeToTray.h"
20
21 #define DEFAULT_RECT_WIDTH 150
22 #define DEFAULT_RECT_HEIGHT 30
23
24 static void GetTrayWndRect(LPRECT lpTrayRect) {
25 APPBARDATA appBarData;
26 HWND hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"),
27 NULL);
28
29 if(hShellTrayWnd) {
30 HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL,
31 TEXT("TrayNotifyWnd"), NULL);
32
33 if(hTrayNotifyWnd) {
34 GetWindowRect(hTrayNotifyWnd,lpTrayRect);
35 return;
36 }
37 }
38
39 appBarData.cbSize = sizeof(appBarData);
40 if(SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) {
41 switch(appBarData.uEdge) {
42 case ABE_LEFT:
43 case ABE_RIGHT:
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;
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 }
59
60 hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
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;
67
68 return;
69 }
70
71 SystemParametersInfo(SPI_GETWORKAREA, 0, lpTrayRect, 0);
72 lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
73 lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;
74 }
75
76 static BOOL GetDoAnimateMinimize(void) {
77 ANIMATIONINFO ai;
78
79 ai.cbSize = sizeof(ai);
80 SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0);
81
82 return ai.iMinAnimate ? TRUE : FALSE;
83 }
84
85 void MinimizeWndToTray(HWND hWnd) {
86
87 if(!IsWindowVisible(hWnd))
88 return;
89
90 if(GetDoAnimateMinimize()) {
91 RECT rcFrom, rcTo;
92
93 GetWindowRect(hWnd, &rcFrom);
94 GetTrayWndRect(&rcTo);
95
96 DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
97 }
98
99 ShowWindow(hWnd, SW_HIDE);
100 }
101
102 void RestoreWndFromTray(HWND hWnd) {
103
104 if(IsWindowVisible(hWnd))
105 return;
106
107 if(GetDoAnimateMinimize()) {
108 RECT rcFrom, rcTo;
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);
118 }
119