annotate src/win32/MinimizeToTray.c @ 10462:f7b32dd67bdf

[gaim-migrate @ 11735] Fix for bug 1027454: Blank "Unable to open socket" window if locale is not UTF-8 committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Fri, 31 Dec 2004 15:34:18 +0000
parents 92cbf9713795
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /* MinimizeToTray
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 *
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 * A couple of routines to show how to make it produce a custom caption
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * animation to make it look like we are minimizing to and maximizing
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 * from the system tray
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 *
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * These routines are public domain, but it would be nice if you dropped
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * me a line if you use them!
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 *
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * 1.0 29.06.2000 Initial version
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * 1.1 01.07.2000 The window retains it's place in the Z-order of windows
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 3957
diff changeset
12 * when minimized/hidden. This means that when restored/shown, it doesn't
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * always appear as the foreground window unless we call SetForegroundWindow
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 *
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 #include "stdafx.h"
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 #ifndef IDANI_OPEN
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 #define IDANI_OPEN 1
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 #ifndef IDANI_CLOSE
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 #define IDANI_CLOSE 2
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 #ifndef IDANI_CAPTION
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #define IDANI_CAPTION 3
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #define DEFAULT_RECT_WIDTH 150
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #define DEFAULT_RECT_HEIGHT 30
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 static void GetTrayWndRect(LPRECT lpTrayRect)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 APPBARDATA appBarData;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 HWND hShellTrayWnd=FindWindowEx(NULL,NULL,TEXT("Shell_TrayWnd"),NULL);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 if(hShellTrayWnd)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 HWND hTrayNotifyWnd=FindWindowEx(hShellTrayWnd,NULL,TEXT("TrayNotifyWnd"),NULL);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 if(hTrayNotifyWnd)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 GetWindowRect(hTrayNotifyWnd,lpTrayRect);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 return;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47 appBarData.cbSize=sizeof(appBarData);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 if(SHAppBarMessage(ABM_GETTASKBARPOS,&appBarData))
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 switch(appBarData.uEdge)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 case ABE_LEFT:
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53 case ABE_RIGHT:
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 lpTrayRect->top=appBarData.rc.bottom-100;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 lpTrayRect->bottom=appBarData.rc.bottom-16;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56 lpTrayRect->left=appBarData.rc.left;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57 lpTrayRect->right=appBarData.rc.right;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 break;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60 case ABE_TOP:
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 case ABE_BOTTOM:
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 lpTrayRect->top=appBarData.rc.top;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 lpTrayRect->bottom=appBarData.rc.bottom;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64 lpTrayRect->left=appBarData.rc.right-100;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 lpTrayRect->right=appBarData.rc.right-16;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66 break;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 return;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 hShellTrayWnd=FindWindowEx(NULL,NULL,TEXT("Shell_TrayWnd"),NULL);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 if(hShellTrayWnd)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 GetWindowRect(hShellTrayWnd,lpTrayRect);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 if(lpTrayRect->right-lpTrayRect->left>DEFAULT_RECT_WIDTH)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 if(lpTrayRect->bottom-lpTrayRect->top>DEFAULT_RECT_HEIGHT)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 return;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 SystemParametersInfo(SPI_GETWORKAREA,0,lpTrayRect,0);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86 lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 static int GetDoAnimateMinimize(void)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 ANIMATIONINFO ai;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 ai.cbSize=sizeof(ai);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94 SystemParametersInfo(SPI_GETANIMATION,sizeof(ai),&ai,0);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 return ai.iMinAnimate?TRUE:FALSE;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 void MinimizeWndToTray(HWND hWnd)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 {
3957
7e384ded0d4e [gaim-migrate @ 4139]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
101 if(!IsWindowVisible(hWnd))
7e384ded0d4e [gaim-migrate @ 4139]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
102 return;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 if(GetDoAnimateMinimize())
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 RECT rcFrom,rcTo;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 GetWindowRect(hWnd,&rcFrom);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108 GetTrayWndRect(&rcTo);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 ShowWindow(hWnd,SW_HIDE);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 void RestoreWndFromTray(HWND hWnd)
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 {
3957
7e384ded0d4e [gaim-migrate @ 4139]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
118 if(IsWindowVisible(hWnd))
7e384ded0d4e [gaim-migrate @ 4139]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
119 return;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120 if(GetDoAnimateMinimize())
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 RECT rcFrom,rcTo;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 GetTrayWndRect(&rcFrom);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124 GetWindowRect(hWnd,&rcTo);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126 DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
129 ShowWindow(hWnd,SW_SHOW);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
130 SetActiveWindow(hWnd);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 SetForegroundWindow(hWnd);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
134
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135