icqtoolbar.c

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 425 行

C
425
字号
/*__________________________________________________________________________
 Copyright (C) 2002 PGP Corporation
 All rights reserved.
 
 $Id: ICQtoolbar.c,v 1.9 2002/08/06 20:09:42 dallen Exp $
__________________________________________________________________________*/
#include "precomp.h"

#define TRANSPARENT_COLOR RGB(255, 0, 0)

LRESULT CALLBACK SendMailToolbarWndProc(HWND hDlg, 
							 UINT msg,
							 WPARAM wParam, 
							 LPARAM lParam)
{
	WNDPROC lpOldProc;
	PPLUGININFO plugin;

	lpOldProc = (WNDPROC)GetProp( hDlg, "oldproc" );
	plugin=GetPluginInfo(hDlg);

	switch(msg)
	{
		case WM_NOTIFY:
		{
			static char szTooltip[256] = {0x00};
			LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) lParam;;

			switch (((LPNMHDR)lParam)->code)
			{
				case TTN_NEEDTEXTA:
				{
					if(lpToolTipText->hdr.idFrom >= IDC_ENCRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_PGPKEYS )
					{
						int StringId = lpToolTipText->hdr.idFrom -   
										IDC_ENCRYPT + IDS_ENCRYPTTOOL;

						LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						lpToolTipText->lpszText = szTooltip;
						
						return 0;
					}
				}

				case TTN_NEEDTEXTW:
				{
					static wchar_t wideBuf[256];

					if(lpToolTipText->hdr.idFrom >= IDC_ENCRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_PGPKEYS )
					{
						int StringId = lpToolTipText->hdr.idFrom -   
										IDC_ENCRYPT + IDS_ENCRYPTTOOL;
					
    					LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						MultiByteToWideChar(CP_ACP, 
											MB_PRECOMPOSED, 
											szTooltip, 
											-1, 
											wideBuf, 
											256);

						lpToolTipText->lpszText = (char*)wideBuf;

						return 0;
					}
				}
			}
			break;
		}

		case WM_DESTROY:
		{
			RemoveProp(hDlg, "oldproc");
			SetWindowLong(hDlg, GWL_WNDPROC, (DWORD) lpOldProc);
			break;
		}

		case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
				/*
				case IDC_PGPKEYS:
				{
					plugin->bSendKey=!plugin->bSendKey;

					if(plugin->bSendKey)
					{
						if(!CheckForICQUserID(plugin->hwndCurrent,PGPsc,PGPtls))
						{
							ICQWizard();
						}
					}

//					SaveSettings(plugin->bEncrypt,plugin->bSendKey);
					break;
				}*/
	
				case IDC_ENCRYPT:
				{
					plugin->bEncrypt=!plugin->bEncrypt;

					AddUserState(&g_userstate,
						plugin->szICQ,
						plugin->bEncrypt);

					if(plugin->bEncrypt)
					{
						if(!CheckForICQUserID(plugin->hwndCurrent,PGPsc,PGPtls))
						{
							ICQWizard(plugin->hwndCurrent,PGPsc,PGPtls);
						}
					}

//					SaveSettings(plugin->bEncrypt,plugin->bSendKey);
					return 0;
				}
			}
			break;
		}
	}

	return CallWindowProc(lpOldProc, hDlg, msg, wParam, lParam);
}

void SizeToolbar(PPLUGININFO plugin)
{
	RECT rcbutton;
	int shift;

	GetWindowRect(plugin->hwndBack,&rcbutton);

	MapWindowPoints(NULL, 
		plugin->hwndTool,
		(POINT*)&rcbutton, 
		2);

	shift=rcbutton.right-rcbutton.left+5;

	rcbutton.left=rcbutton.right;
	rcbutton.right=rcbutton.left+100;

	if(!plugin->b2001b)
	{
		rcbutton.top=rcbutton.top-2;
		rcbutton.bottom=rcbutton.bottom+2;
	}

	InvalidateRect(plugin->hwndToolbar,NULL,TRUE);

	MoveWindow(plugin->hwndToolbar,
		rcbutton.left,rcbutton.top,
		rcbutton.right-rcbutton.left+70,
		rcbutton.bottom-rcbutton.top,
		TRUE);	
}

#define TOOLBARXOFFSET			4
#define TOOLBARYOFFSET			4

#define BITMAP_CX			16
#define BITMAP_CY			16

HWND CreateToolbarSend(HWND hwndParent,BOOL b2001b)
{
	TBBUTTON tbread[]= {
				{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
//				{0,IDC_PGPKEYS,TBSTATE_ENABLED,TBSTYLE_CHECK,0,0,0,0},
				{1,IDC_ENCRYPT,TBSTATE_ENABLED,TBSTYLE_CHECK,0,0,0,0},
				};

	static HBITMAP hTransparentBMP	= NULL;

	HBITMAP	hSendToolbar			= NULL; 
	HBITMAP	hOldBitmap				= NULL;
	HDC		hdc						= NULL;
	HDC		hdcMem					= NULL;
	HBRUSH	hBrush					= NULL;
	HBRUSH	hOldBrush				= NULL;
	HWND	hwndToolbar				= NULL;
	HDC		hDC;
	int		iNumBits;

	// all this work just to load a bitmap and make it transparent...
	hDC = GetDC (NULL);		// DC for desktop
	iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * 
		GetDeviceCaps (hDC, PLANES);
	ReleaseDC (NULL, hDC);

	if(b2001b)
	{
		HIMAGELIST	himl;

		if (iNumBits <= 8) 
		{
			hSendToolbar = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_SEND2001B4));
			himl = ImageList_Create (BITMAP_CX, BITMAP_CY, ILC_COLOR|ILC_MASK, 
											2, 0); 
		}
		else
		{
			hSendToolbar = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_SEND2001B8));
			himl = ImageList_Create (BITMAP_CX, BITMAP_CY, ILC_COLOR24|ILC_MASK, 
											2, 0); 
		}

		ImageList_AddMasked (himl, hSendToolbar, TRANSPARENT_COLOR);

		DeleteObject (hSendToolbar);

		// create the toolbar control.
		hwndToolbar = CreateWindowEx(
						WS_EX_TOOLWINDOW,
						TOOLBARCLASSNAME,
						NULL,
						WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | 
						WS_CLIPSIBLINGS | CCS_NODIVIDER |
						CCS_NOPARENTALIGN | CCS_NORESIZE | 
						TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 
						TOOLBARXOFFSET,TOOLBARYOFFSET,0,0, 
						hwndParent, (HMENU)NULL,
						g_hinst, NULL); 


		// sets the size of the TBBUTTON structure.
		SendMessage (hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);

		// set the bitmap size.
		SendMessage	(hwndToolbar, TB_SETBITMAPSIZE,
				   0, (LPARAM)MAKELONG (BITMAP_CX, BITMAP_CY));

	//	SendMessage( hwndToolbar, TB_SETPADDING, 0, MAKELPARAM( 4, 4 ) );
 
		// set the button size.
		SendMessage	(hwndToolbar, TB_SETBUTTONSIZE,
				   0, (LPARAM)MAKELONG (BITMAP_CX+6, BITMAP_CY+6));

		SendMessage (hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl);
 
		// add the buttons
		SendMessage (hwndToolbar,
				   TB_ADDBUTTONS, (UINT)(sizeof(tbread)/sizeof(TBBUTTON)), (LPARAM)tbread);

		return hwndToolbar;
	}

	if (iNumBits <= 8) 
	{
		hSendToolbar = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_SENDTOOLBAR4));
	}
	else
	{
		hSendToolbar = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_SENDTOOLBAR8));
	}

	hdc = CreateIC("DISPLAY",NULL,NULL,NULL);
	hdcMem = CreateCompatibleDC(hdc);
	hBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));

	hTransparentBMP =  CreateCompatibleBitmap(hdc,90,18);
	hOldBitmap = SelectObject(hdcMem,hTransparentBMP);
	hOldBrush = SelectObject(hdcMem,hBrush);
	PatBlt(hdcMem,0,0,90,18,PATCOPY);
	TransparentBitmap(hSendToolbar, 90, 18, TRANSPARENT_COLOR, hdcMem, 0,0);
	SelectObject(hdcMem,hOldBitmap);
	SelectObject(hdcMem,hOldBrush);
	DeleteObject(hBrush);
	DeleteObject(hSendToolbar);
	DeleteDC(hdcMem);
	DeleteDC(hdc);

	// now we can create the actual toolbar
	hwndToolbar = CreateToolbarEx(
				hwndParent,
				TBSTYLE_TOOLTIPS|WS_VISIBLE|WS_CHILD|
				WS_CLIPSIBLINGS|CCS_TOP|CCS_NODIVIDER|CCS_NORESIZE,
				IDB_SENDTOOLBAR,
				2,
				NULL,
				(UINT)hTransparentBMP,
				tbread,
				sizeof(tbread)/sizeof(TBBUTTON),
				12,
				12,
				12,
				12,
				sizeof(TBBUTTON));
	
	return hwndToolbar;
}

void InitToolbar(PPLUGININFO plugin)
{
	plugin->hwndToolbar=CreateToolbarSend(plugin->hwndTool,plugin->b2001b);

	// Set the proc address as a property 
	// of the window so it can get it
	SetProp(plugin->hwndTool, PLUGIN_INFO_PROP, 
		(HANDLE) plugin);

	SetProp(plugin->hwndTool, 
		"oldproc",
		(HANDLE)GetWindowLong( plugin->hwndTool, GWL_WNDPROC ) ); 
	
	// Subclass the window
	SetWindowLong(	plugin->hwndTool, 
		GWL_WNDPROC, 
		(DWORD)SendMailToolbarWndProc );  
/*
	GetSettings(&(plugin->bEncrypt),&(plugin->bSendKey));

	if(plugin->bEncrypt)
	{
		SendMessage(plugin->hwndToolbar,TB_SETSTATE,
			(WPARAM)IDC_ENCRYPT,
			(LPARAM)MAKELONG(TBSTATE_CHECKED|TBSTATE_ENABLED, 0));
	}

	if(plugin->bSendKey)
	{
		SendMessage(plugin->hwndToolbar,TB_SETSTATE,
			(WPARAM)IDC_PGPKEYS,
			(LPARAM)MAKELONG(TBSTATE_CHECKED|TBSTATE_ENABLED, 0));
	}
*/
	SizeToolbar(plugin);
}

void SizeSendKey(PPLUGININFO plugin)
{
	RECT rcbutton;
	int shift;

	if(plugin->b2001b)
	{
		RECT rcSendby;

		GetWindowRect(plugin->hwndSend,&rcbutton);

		MapWindowPoints(NULL, 
			plugin->hwndMain,
			(POINT*)&rcbutton, 
			2);

		shift=rcbutton.right-rcbutton.left+5;

		GetWindowRect(plugin->hwndSKMark,&rcSendby);

		MapWindowPoints(NULL, 
			plugin->hwndMain,
			(POINT*)&rcSendby, 
			2);

		shift=shift+(rcbutton.left-rcSendby.left);
	}
	else
	{
		GetWindowRect(plugin->hwndSKMark,&rcbutton);

		MapWindowPoints(NULL, 
			plugin->hwndMain,
			(POINT*)&rcbutton, 
			2);

		shift=rcbutton.right-rcbutton.left+5;
	}

	rcbutton.left=rcbutton.left-shift;
	rcbutton.right=rcbutton.right-shift;

	InvalidateRect(plugin->hwndSendKey,NULL,TRUE);

	MoveWindow(plugin->hwndSendKey,
		rcbutton.left,rcbutton.top,
		rcbutton.right-rcbutton.left,
		rcbutton.bottom-rcbutton.top,
		TRUE);	
}

void InitSendKey(PPLUGININFO plugin)
{
	LOGFONT lf;

	SystemParametersInfo(SPI_GETICONTITLELOGFONT,
		sizeof(LOGFONT), &lf, 0);
	
	plugin->hFont = CreateFontIndirect (&lf);

	plugin->hwndSendKey=CreateWindow ("BUTTON", "Send &Key",
		WS_TABSTOP | WS_CHILD | WS_VISIBLE,// | BS_ICON,
		0,0,0,0,
		plugin->hwndMain, (HMENU) IDC_PGPKEYS, g_hinst, NULL) ; 

	SendMessage(plugin->hwndSendKey,WM_SETFONT,
	   (WPARAM)plugin->hFont,(LPARAM)MAKELPARAM(TRUE,0));

//	SetWindowLong(hwndMain, GWL_WNDPROC, 
//		(DWORD) SendMessageWndProc);

//	SendMessage(plugin->hwndSendKey,BM_SETIMAGE,
//		(WPARAM)IMAGE_ICON,
//		(LPARAM)LoadIcon(g_hinst,MAKEINTRESOURCE(bd[i].idicon)));

	SizeSendKey(plugin);
}

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?