Replace functions which called once with their bodies
[pidgin-git.git] / pidgin / win32 / MinimizeToTray.c
blobb4fd22c44873df406599c5682300017b13d9c73d
1 /* MinimizeToTray
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
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>
17 #include <config.h>
18 #include <windows.h>
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"),
27 NULL);
29 if(hShellTrayWnd) {
30 HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL,
31 TEXT("TrayNotifyWnd"), NULL);
33 if(hTrayNotifyWnd) {
34 GetWindowRect(hTrayNotifyWnd,lpTrayRect);
35 return;
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;
57 return;
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;
68 return;
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) {
77 ANIMATIONINFO ai;
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))
88 return;
90 if(GetDoAnimateMinimize()) {
91 RECT rcFrom, rcTo;
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))
105 return;
107 if(GetDoAnimateMinimize()) {
108 RECT rcFrom, rcTo;
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);