⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendmsgwndproc.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 3 页
字号:
		lppilPlugInf->nPGPKeysButton = SendMessage(lppilPlugInf->hToolbar,
								TB_COMMANDTOINDEX, IDC_PGPKEYS,	0);
		pgpAssert(-1 != lppilPlugInf->nPGPKeysButton);
		if(-1 != lppilPlugInf->nPGPKeysButton)//if we could get the index of pgpkeys button
			lppilPlugInf->dwInitState |= PIIF_TOOLSINSERTION_DONE;//all success
	}


	if (lppilPlugInf->bOE5)
	{
		int nIndex = -1;
		TBBUTTON tb = {0};

		nIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
					IDC_ENCRYPT_PGP, 0);
		if(-1 != nIndex)
		{
			lResult = SendMessage(lppilPlugInf->hToolbar, TB_GETBUTTON, nIndex - 2, 
				(LPARAM) &tb);

			pgpAssert(TRUE == lResult);
			pgpAssert(tb.fsStyle & TBSTYLE_SEP);
			if ((TRUE == lResult) && (tb.fsStyle & TBSTYLE_SEP))
				SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, nIndex - 2, 0);
		}

		/*if (nY > 26)
		{
			SendMessage(lppilPlugInf->hToolbar, TB_SETBUTTONSIZE, 0, 
				MAKELONG(nX, nY));
			lppilPlugInf->nButtonSizeX = nX;
			lppilPlugInf->nButtonSizeY = nY;
		}*/
	}
	
	return;
}

void RemoveSendToolbarButtons(PluginInfo *lppilPlugInf)
{
	HIMAGELIST hTbImgList = NULL, hTbHotImgList = NULL;
	BOOL bRet = FALSE;
	INT iIndex = -1;
	LONG lResult = 0;
	TBBUTTON tbBtn={0};

	//check parameters
	pgpAssert(NULL != lppilPlugInf);
	if(NULL == lppilPlugInf)
		return;

	//if we have not inserted our stuff into the toolbar already
	if(!(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE))
		return;

	pgpAssert(-1 != lppilPlugInf->nPGPKeysButton);

	//REMOVE THE BUTTONS

	//find the button index for pgp keys button
	iIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
				IDC_PGPKEYS, 0);
	pgpAssert(-1 != iIndex);
	
	if(-1 != iIndex)
	{
		//the button index should be the same as we know already
		pgpAssert(iIndex == lppilPlugInf->nPGPKeysButton);

		//delete the button 
		lResult = SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, iIndex, 0);
		pgpAssert(TRUE == lResult);

		if(TRUE == lResult)
			lppilPlugInf->nPGPKeysButton = -1;
	}

	//find the button index for sign button
	iIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
				IDC_SIGN_PGP, 0);
	pgpAssert(-1 != iIndex);
	
	if(-1 != iIndex)
	{
		//delete the sign button 
		lResult = SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, iIndex, 0);
		pgpAssert(TRUE == lResult);
	}

	//find the button index for encrypt button
	iIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
				IDC_ENCRYPT_PGP, 0);
	pgpAssert(-1 != iIndex);
	
	if(-1 != iIndex)
	{
		//delete the encrypt button 
		lResult = SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, iIndex, 0);
		pgpAssert(TRUE == lResult);
	}

	//remove the separator before the encrypt button (that we had inserted)
	lResult = SendMessage(lppilPlugInf->hToolbar, TB_GETBUTTON, iIndex-1, (LPARAM) &tbBtn);
	pgpAssert(TRUE == lResult);
	pgpAssert(tbBtn.fsStyle & TBSTYLE_SEP);
	if ((TRUE == lResult) && (tbBtn.fsStyle & TBSTYLE_SEP))
		SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, iIndex - 1, 0);


	//REMOVE BITMAP INSERTIONS FOR THE BUTTONS

	//get the normal imagelist
	hTbImgList = (HIMAGELIST) SendMessage(lppilPlugInf->hToolbar, 
										TB_GETIMAGELIST, 0, 0);
	pgpAssert(NULL != hTbImgList);

	//get the hot imagelist
	hTbHotImgList = (HIMAGELIST) SendMessage(lppilPlugInf->hToolbar, 
										TB_GETHOTIMAGELIST, 0, 0);
	pgpAssert(NULL != hTbHotImgList);


	//remove the pgpkeys image from both image lists
	pgpAssert(-1 != lppilPlugInf->nPGPKeysImage);
	if( -1 != lppilPlugInf->nPGPKeysImage)
	{
		bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nPGPKeysImage);
		pgpAssert(0 != bRet);

		bRet = ImageList_Remove(hTbHotImgList, lppilPlugInf->nPGPKeysImage);
		pgpAssert(0 != bRet);

		lppilPlugInf->nPGPKeysImage = -1;
	}

	//remove the sign image from both image lists
	pgpAssert(-1 != lppilPlugInf->nSignImage);
	if( -1 != lppilPlugInf->nSignImage)
	{
		bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nSignImage);
		pgpAssert(0 != bRet);

		bRet = ImageList_Remove(hTbHotImgList, lppilPlugInf->nSignImage);
		pgpAssert(0 != bRet);

		lppilPlugInf->nSignImage = -1;
	}

	//remove the encrypt image from both image lists
	pgpAssert(-1 != lppilPlugInf->nEncryptImage);
	if( -1 != lppilPlugInf->nEncryptImage)
	{
		bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nEncryptImage);
		pgpAssert(0 != bRet);

		bRet = ImageList_Remove(hTbHotImgList, lppilPlugInf->nEncryptImage);
		pgpAssert(0 != bRet);

		lppilPlugInf->nEncryptImage = -1;
	}

	
	//REMOVE THE STRINGS ADDED TO TOOLBAR

	//there is currently no way to do this. TODO: change stuff so that we
	//do not need to have this side effect

	//state maintenance - toolbar insertion is not done anymore
	lppilPlugInf->dwInitState &= (~PIIF_TOOLSINSERTION_DONE);
}

int LoadAppropriateBitmaps(PluginInfo *plugin, UINT uiCommandId)
{
	HDC hDC=NULL;
	int iBpp=0, iImgIndex=-1, iHotImgIndex=-1;
	int iRsrcId=-1, iHotRsrcId=-1;
	int iIconWidth=0, iIconHeight=0;
	int iHotIconWidth=0, iHotIconHeight=0;
	HIMAGELIST hTbImgList=NULL, hTbHotImgList=NULL;
	HBITMAP hbmBitMap=NULL, hbmHotBitMap=NULL;

	//check parameters
	pgpAssert((NULL != plugin) && (NULL != plugin->hToolbar));
	if((NULL == plugin) || (NULL == plugin->hToolbar))
		return -1;//bail 

	//get the normail imagelist of the toolbar
	hTbImgList = (HIMAGELIST) SendMessage(plugin->hToolbar, TB_GETIMAGELIST, 0, 0);
	pgpAssert(NULL != hTbImgList);
	if(NULL == hTbImgList)
		return -1;

	//get the hot image list on OE5 onwards
	if(TRUE == plugin->bOE5)
	{
		//get the hot image list of the toolbar
		hTbHotImgList = (HIMAGELIST) SendMessage(plugin->hToolbar, TB_GETHOTIMAGELIST, 0, 0);
		pgpAssert(NULL != hTbHotImgList);
	}


	//if the version is prior to OE5
	if (FALSE == plugin->bOE5)
	{
		switch(uiCommandId)
		{
			case IDC_ENCRYPT_PGP:
				iRsrcId = IDB_ENCRYPT;
				break;
			case IDC_SIGN_PGP:
				iRsrcId = IDB_SIGN;
				break;
			case IDC_PGPKEYS:
				iRsrcId = IDB_PGPKEYS;
				break;
			case IDC_DECRYPT:
				iRsrcId = IDB_DECRYPT;
				break;
			default:
				break;
		}

		goto loadbitmap;
	}

	//NOTE: plugin->bOE5 is true henceforth until loadbitmap

	//get the bpp (bits per pixel)
	hDC = GetDC(NULL);// DC for desktop
	pgpAssert(NULL != hDC);

	if(NULL != hDC)
	{
		iBpp = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
		pgpAssert(iBpp > 0);

		ReleaseDC(NULL, hDC);
		hDC = NULL;
	}

	//get the size of icons in the imagelist. In OE6 - big icons seem to be at 24w x 24h
	//and small icons at 16w x 24h. (geticonsize on the normal imagelist). In OE5 - big
	//icons are at 22w x 20h and small icons at 16w x 16h. So we treat width less than 20 
	//to be small icon here (ssd)
	ImageList_GetIconSize(hTbImgList, &iIconWidth, &iIconHeight);
	ImageList_GetIconSize(hTbHotImgList, &iHotIconWidth, &iHotIconHeight);
	pgpAssert(iHotIconWidth <= iIconWidth);
	pgpAssert(iHotIconHeight <= iIconHeight);

	//if we dont have these icons big icons do not work in OE6
	if (iIconHeight == 24)
	{
		switch(uiCommandId)
		{
			case IDC_ENCRYPT_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_ENCRYPTXPO:IDB_ENCRYPTXPOFF;//IDB_ENCRYPTXPO:IDB_ENCRYPTXPOFF
				iHotRsrcId = (iIconWidth < 20)?IDB_ENCRYPTXP:IDB_ENCRYPTXPLARGE;//IDB_ENCRYPTXP:IDB_ENCRYPTXPLARGE
				break;
			case IDC_SIGN_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_SIGNXPO:IDB_SIGNXPOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_SIGNXP:IDB_SIGNXPLARGE;
				break;
			case IDC_PGPKEYS:
				iRsrcId = (iIconWidth < 20)?IDB_PGPKEYSXPO:IDB_PGPKEYSXPOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_PGPKEYSXP:IDB_PGPKEYSXPLARGE;
				break;
			case IDC_DECRYPT:
				iRsrcId = (iIconWidth < 20)?IDB_DECRYPTXPO:IDB_DECRYPTXPOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_DECRYPTXP:IDB_DECRYPTXPLARGE;
				break;
				
			default:
				break;
		}
		goto loadbitmap;
	}

	if (iBpp > 8)
	{
		switch(uiCommandId)
		{
			case IDC_ENCRYPT_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_ENCRYPTO:IDB_ENCRYPTOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_ENCRYPT:IDB_ENCRYPTLARGE;
				break;
			case IDC_SIGN_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_SIGNO:IDB_SIGNOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_SIGN:IDB_SIGNLARGE;
				break;
			case IDC_PGPKEYS:
				iRsrcId = (iIconWidth < 20)?IDB_PGPKEYSO:IDB_PGPKEYSOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_PGPKEYS:IDB_PGPKEYSLARGE;
				break;
			case IDC_DECRYPT:
				iRsrcId = (iIconWidth < 20)?IDB_DECRYPTO:IDB_DECRYPTOFF;
				iHotRsrcId = (iIconWidth < 20)?IDB_DECRYPT:IDB_DECRYPTLARGE;
				break;
			default:
				break;
		}
		goto loadbitmap;
	}
	else
	{
		switch(uiCommandId)
		{
			case IDC_ENCRYPT_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_ENCRYPTO4:IDB_ENCRYPTOFF4;
				iHotRsrcId = (iIconWidth < 20)?IDB_ENCRYPT4:IDB_ENCRYPTLARGE4;
				break;
			case IDC_SIGN_PGP:
				iRsrcId = (iIconWidth < 20)?IDB_SIGNO4:IDB_SIGNOFF4;
				iHotRsrcId = (iIconWidth < 20)?IDB_SIGN4:IDB_SIGNLARGE4;
				break;
			case IDC_PGPKEYS:
				iRsrcId = (iIconWidth < 20)?IDB_PGPKEYSO4:IDB_PGPKEYSOFF4;
				iHotRsrcId = (iIconWidth < 20)?IDB_PGPKEYS4:IDB_PGPKEYSLARGE4;
				break;
			case IDC_DECRYPT:
				iRsrcId = (iIconWidth < 20)?IDB_DECRYPTO4:IDB_DECRYPTOFF4;
				iHotRsrcId = (iIconWidth < 20)?IDB_DECRYPT4:IDB_DECRYPTLARGE4;
				break;
			default:
				break;
		}
		goto loadbitmap;
	}

	
	loadbitmap:


	//if we have found the resouce to load
	if(-1 != iRsrcId)
	{
		//load the bitmap
		pgpAssert(NULL == hbmBitMap);
		hbmBitMap = LoadBitmap(UIGetInstance(), MAKEINTRESOURCE(iRsrcId));
		pgpAssert(NULL != hbmBitMap);
	}

	if(-1 != iHotRsrcId)
	{
		int iImgCnt = 0, iHotImgCnt = 0;//image counts

		//load the bitmap
		pgpAssert(NULL == hbmHotBitMap);
		hbmHotBitMap = LoadBitmap(UIGetInstance(), MAKEINTRESOURCE(iHotRsrcId));
		pgpAssert(NULL != hbmHotBitMap);

		//check if the imagelists are of same size

		//get the image counts of both lists first
		iImgCnt = ImageList_GetImageCount(hTbImgList),
		iHotImgCnt = ImageList_GetImageCount(hTbHotImgList);

		if(iImgCnt != iHotImgCnt)//if not same size
		{
			//indexes returned will be different when we call ImageList_AddMasked
			//we need to take care of this before calling AddMasked on the real
			//bitmaps

			//load some other bitmap. this will be used to fill up the difference 
			//this is necessary since AddMasked changes the hBitmap passed
			HBITMAP hbmTempBmp = LoadImage(UIGetInstance(), MAKEINTRESOURCE(IDB_SIGNXP), 
				IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
			pgpAssert(NULL != hbmTempBmp);
			
			//until both lists are of equal size
			while(iHotImgCnt != iImgCnt)
			{
				if(iHotImgCnt < iImgCnt)
				{
					//add the temp bitmap to hot imagelist
					iHotImgCnt = ImageList_AddMasked(hTbHotImgList, hbmTempBmp, TRANSPARENT_COLOR);
					iHotImgCnt++;
				}
				else
				{
					//add the temp bitmap to the normal imagelist
					iImgCnt = ImageList_AddMasked(hTbImgList, hbmTempBmp, TRANSPARENT_COLOR);
					iImgCnt++;
				}
			}

			//cleanup
			if(NULL != hbmTempBmp)
			{
				DeleteObject(hbmTempBmp);
				hbmTempBmp=NULL;
			}
		}
	}


	//add the bitmap to the imagelist
	iImgIndex = ImageList_AddMasked(hTbImgList, hbmBitMap, TRANSPARENT_COLOR);

	//add the hot bitmap if that is what we need to do here
	if((TRUE == plugin->bOE5) && (NULL != hbmHotBitMap))
	{
		pgpAssert(NULL != hTbHotImgList);
		iHotImgIndex = ImageList_AddMasked(hTbHotImgList, hbmHotBitMap, TRANSPARENT_COLOR);

		//should be of the same index as the normal list
		pgpAssert(iHotImgIndex == iImgIndex);
	}

	//cleanup
	if(NULL != hbmBitMap)
	{
		
		DeleteObject(hbmBitMap);
		hbmBitMap = NULL;
	}

	if(NULL != hbmHotBitMap)
	{
		
		DeleteObject(hbmHotBitMap);
		hbmHotBitMap = NULL;
	}

	return iImgIndex;
}

void DumpToolbarInfo(HWND hTBWnd)
{
	int iNoOfButtons=0;
	int iIndex=0;
	LONG lResult=0;
	COLORSCHEME csClrScheme={sizeof(COLORSCHEME), 0};
	TBBUTTON tbbBtn={0};
	TBBUTTONINFO tbbBtnInfo={0};
	char szText[255]={0};

	PGPOeTrace("Dumping details of toolbar hWnd = %#x\n", hTBWnd);
	PGPOeTrace("============================================\n");
	PGPOeTrace("\tNoOfButtons=%d\n", 
			iNoOfButtons = SendMessage(hTBWnd, TB_BUTTONCOUNT, 0, 0));

	PGPOeTrace("\tUsingUnicode=%s\n", 
			(0 == SendMessage(hTBWnd, TB_GETUNICODEFORMAT, 0, 0))?"NO":"YES");

	lResult = SendMessage(hTBWnd, TB_GETBITMAPFLAGS, 0, 0);
	PGPOeTrace("\tBitmapFlags= ");
	if(lResult & TBBF_LARGE)
		PGPOeTrace("TBBF_LARGE ");
	PGPOeTrace("\n");
	
	lResult = SendMessage(hTBWnd, TB_GETCOLORSCHEME, 0, (LPARAM)&csClrScheme);
	PGPOeTrace("\tColorScheme= clrBtnHighlight:%#x clrBtnShadow:%#x \n",
		csClrScheme.clrBtnHighlight, csClrScheme.clrBtnShadow);

	lResult = SendMessage(hTBWnd, TB_GETBUTTONSIZE, 0, 0);
	PGPOeTrace("\tButtonSize= width:%#x height:%#x \n",
		LOWORD(lResult), HIWORD(lResult));

	lResult = SendMessage(hTBWnd, TB_GETPADDING, 0, 0);
	PGPOeTrace("\tPadding= horizontal:%#x vertical:%#x \n",
		LOWORD(lResult), HIWORD(lResult));

	
	//for each button
	for(iIndex=0; iIndex < iNoOfButtons; iIndex++)
	{
		PGPOeTrace("\t\tBUTTON # %d\n", iIndex);

		ZeroMemory(&tbbBtn, sizeof(tbbBtn));

		lResult = SendMessage(hTBWnd, TB_GETBUTTON, iIndex, (LPARAM)&tbbBtn);
		PGPOeTrace("\t\t\t idCommand=%d\n", tbbBtn.idCommand);
		PGPOeTrace("\t\t\t iBitmap=%d\n", tbbBtn.iBitmap);
		PGPOeTrace("\t\t\t fsStyle=%#x\n", tbbBtn.fsStyle);
		PGPOeTrace("\t\t\t fsState=%#x\n", tbbBtn.fsState);
		PGPOeTrace("\t\t\t dwData=%#x\n", tbbBtn.dwData);

		tbbBtnInfo.cbSize=sizeof(TBBUTTONINFO);
		tbbBtnInfo.dwMask=TBIF_IMAGE|TBIF_SIZE|TBIF_TEXT;
		tbbBtnInfo.pszText=szText;
		tbbBtnInfo.cchText=sizeof(szText);

		lResult = SendMessage(hTBWnd, TB_GETBUTTON, tbbBtn.idCommand, (LPARAM)&tbbBtnInfo);
		PGPOeTrace("\t\t\t pszText=%s\n", szText);
		PGPOeTrace("\t\t\t width in pixels=%d\n", tbbBtnInfo.cx);
	}

}

void DumpImageListInfo(HIMAGELIST hilImgList)
{
	int iWidth=0, iHeight=0;
	int iIndex=0;
	int iTemp=0;
	COLORREF clrColor;
	IMAGEINFO imgInfo={0};
	BOOL bRet=ImageList_GetIconSize(hilImgList, &iWidth, &iHeight);

	PGPOeTrace("IMAGELIST INFO\n");
	PGPOeTrace("\tIconSize= Width: %d Height: %d\n", iWidth, iHeight);

	clrColor=ImageList_GetBkColor(hilImgList);
	PGPOeTrace("\tBkColor = %#x Our color = %#x\n", clrColor, TRANSPARENT_COLOR);

	iTemp=ImageList_GetImageCount(hilImgList);
	PGPOeTrace("\tImageCount= %d\n", iTemp);

	//for each button
	for(iIndex=0; iIndex < iTemp; iIndex++)
	{
		PGPOeTrace("\t\tImage Info # %d\n", iIndex);

		ZeroMemory(&imgInfo, sizeof(imgInfo));

		bRet=ImageList_GetImageInfo(hilImgList, iIndex, &imgInfo);
		if(TRUE == bRet)
		{
			PGPOeTrace("\t\t\t hbmImage=%#x\n", imgInfo.hbmImage);
			PGPOeTrace("\t\t\t hbmMask=%#x\n", imgInfo.hbmMask);
			PGPOeTrace("\t\t\t Unused1=%#x\n", imgInfo.Unused1);
			PGPOeTrace("\t\t\t Unused2=%#x\n", imgInfo.Unused2);
			PGPOeTrace("\t\t\t rcImage left=%d, right=%d, top=%d, bottom=%d\n", 
				imgInfo.rcImage.left, imgInfo.rcImage.right, imgInfo.rcImage.top, imgInfo.rcImage.bottom);
		}
	}

}


/*__Editor_settings____

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

⌨️ 快捷键说明

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