view plugins/docklet/MinimizeToTray.c @ 13664:4132d997ccec

[gaim-migrate @ 16066] Fix Coverity CID 45: Check to make sure a channel 2 ICBM actually contains an IP address TLV before attempting to use it. This avoids a crash when the server sends us an abnormal channel 2 ICBM. I'm not sure if that ever happens. Fix Coverity CID 204: Don't attempt to send data over a FLAP BOS connection that doesn't exist. This should never happen because the account should get disconnected first. Fix Coverity CID 205: Don't check that a variable 'od' which we know is valid is not equal to NULL in aim_search_address() in family_userlookup.c Fix Coverity CID 206: Don't check that the variable 'od' which we know is valid is not equal to NULL in aim_chat_join() in family_oservice.c Fix Coverity CID 207: I neglected to remove a "return;" line from aim_admin_setnick() in family_admin.c which caused setting your AIM screen name formatting to not work. Fix Coverity CID 208: Remove a duplicate call to gaim_connection_get_account() in peer_connection_propose() in peer.c. Fix Coverity CID 209: Remove the unused variable "username" from incomingim_chan2() in oscar.c. Fix Coverity CID 210: Remove the unused variable "account" from peer_connection_listen_cb() in peer.c. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 20 Apr 2006 04:45:06 +0000
parents 6de39a8cc2c1
children
line wrap: on
line source

/* MinimizeToTray
 *
 * A couple of routines to show how to make it produce a custom caption
 * animation to make it look like we are minimizing to and maximizing
 * from the system tray
 *
 * These routines are public domain, but it would be nice if you dropped
 * me a line if you use them!
 *
 * 1.0 29.06.2000 Initial version
 * 1.1 01.07.2000 The window retains it's place in the Z-order of windows
 *     when minimized/hidden. This means that when restored/shown, it doesn't
 *     always appear as the foreground window unless we call SetForegroundWindow
 *
 * Copyright 2000 Matthew Ellis <m.t.ellis@bigfoot.com>
 */
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "MinimizeToTray.h"

#define DEFAULT_RECT_WIDTH 150
#define DEFAULT_RECT_HEIGHT 30

static void GetTrayWndRect(LPRECT lpTrayRect) {
	APPBARDATA appBarData;
	HWND hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"),
		NULL);

	if(hShellTrayWnd) {
		HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL,
			TEXT("TrayNotifyWnd"), NULL);

		if(hTrayNotifyWnd) {
			GetWindowRect(hTrayNotifyWnd,lpTrayRect);
			return;
		}
	}

	appBarData.cbSize = sizeof(appBarData);
	if(SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) {
		switch(appBarData.uEdge) {
			case ABE_LEFT:
			case ABE_RIGHT:
				lpTrayRect->top = appBarData.rc.bottom - 100;
				lpTrayRect->bottom = appBarData.rc.bottom - 16;
				lpTrayRect->left = appBarData.rc.left;
				lpTrayRect->right = appBarData.rc.right;
				break;
			case ABE_TOP:
			case ABE_BOTTOM:
				lpTrayRect->top = appBarData.rc.top;
				lpTrayRect->bottom = appBarData.rc.bottom;
				lpTrayRect->left = appBarData.rc.right - 100;
				lpTrayRect->right = appBarData.rc.right - 16;
				break;
		}
		return;
	}

	hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
	if(hShellTrayWnd) {
		GetWindowRect(hShellTrayWnd, lpTrayRect);
		if(lpTrayRect->right-lpTrayRect->left > DEFAULT_RECT_WIDTH)
			lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
		if(lpTrayRect->bottom-lpTrayRect->top > DEFAULT_RECT_HEIGHT)
			lpTrayRect->top=lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;

		return;
	}

	SystemParametersInfo(SPI_GETWORKAREA, 0, lpTrayRect, 0);
	lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
	lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;
}

static BOOL GetDoAnimateMinimize(void) {
	ANIMATIONINFO ai;

	ai.cbSize = sizeof(ai);
	SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0);

	return ai.iMinAnimate ? TRUE : FALSE;
}

void MinimizeWndToTray(HWND hWnd) {

	if(!IsWindowVisible(hWnd))
		return;

	if(GetDoAnimateMinimize()) {
		RECT rcFrom, rcTo;

		GetWindowRect(hWnd, &rcFrom);
		GetTrayWndRect(&rcTo);

		DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
	}

	ShowWindow(hWnd, SW_HIDE);
}

void RestoreWndFromTray(HWND hWnd) {

	if(IsWindowVisible(hWnd))
		return;

	if(GetDoAnimateMinimize()) {
		RECT rcFrom, rcTo;
		GetTrayWndRect(&rcFrom);
		GetWindowRect(hWnd, &rcTo);

		DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
	}

	ShowWindow(hWnd, SW_SHOW);
	SetActiveWindow(hWnd);
	SetForegroundWindow(hWnd);
}