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

📄 readmsgwndproc.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 2 页
字号:

	nError = DecryptVerifyBuffer(UIGetInstance(), hwnd, plugin->pgpContext, 
				plugin->tlsContext, szExe, szDll,
				szInput, dwLength, FALSE, FALSE, FALSE, (void **) &szOutput, 
				&nOutLength, &FYEO);

	if (IsntPGPError(nError) && (szOutput != NULL) && (nOutLength > 0))
	{
		if (nOutLength == dwLength)
			PGPFreeData(szOutput);
		else if((FYEO)||(PGPscGetSecureViewerPref((void *)plugin->pgpContext)))
		{
			PGPscTempestViewer((void *)plugin->pgpContext,hwnd,
				szOutput,nOutLength,FYEO);

			PGPFreeData(szOutput);
		}
		else
		{
			if (plugin->szOutput != NULL)
			{
				free(plugin->szOutput);
				plugin->szOutput = NULL;
			}

			bSuccess = TRUE;
			plugin->szOutput = (char *) calloc(dwLength + nOutLength + 1, 1);
			if(NULL != plugin->szOutput)
				strcpy(plugin->szOutput, szOutput);
			PGPFreeData(szOutput);

			GetClientRect(plugin->hMessage, &rc);
			ShowWindow(plugin->hMessage, SW_HIDE);

			if (plugin->hEdit)
				DestroyWindow(plugin->hEdit);

			plugin->hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, 
				"EDIT", plugin->szOutput, 
				WS_VISIBLE | WS_CHILD | 
				WS_VSCROLL | 
				ES_MULTILINE | ES_WANTRETURN | 
				ES_AUTOVSCROLL,
				rc.left, rc.top, 
				rc.right - rc.left, 
				rc.bottom - rc.top,
				hDocHost, NULL, 
				UIGetInstance(), NULL);
		
			hFont = (HFONT) GetStockObject(ANSI_VAR_FONT);
			PostMessage(plugin->hEdit, WM_SETFONT, (WPARAM) hFont, 
				MAKELPARAM(TRUE, 0));

			if (plugin->bOE5)
				hNoteHdr = FindWindowEx(hwnd, NULL, "OE_Envelope", NULL);
			else
				hNoteHdr = FindWindowEx(hwnd, NULL, "ATH_NoteHdr", NULL);
		
			SetWindowPos(plugin->hEdit, HWND_TOP, 
				rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
				SWP_SHOWWINDOW);

			hTo = FindWindowEx(hNoteHdr, NULL, "RICHEDIT", NULL);
			SetFocus(hTo);
			SetFocus(plugin->hEdit);

			EnableMenus(hwnd, plugin, FALSE);
		}
	}
		
	free(szInput);

	return bSuccess;		
}


void EnableMenus(HWND hwnd, PluginInfo *plugin, BOOL bEnable)
{
	MENUITEMINFO menuInfo;
	UINT uFlags = MF_BYPOSITION;

	menuInfo.cbSize = sizeof(MENUITEMINFO);
	menuInfo.fMask = MIIM_SUBMENU;

	if (bEnable)
		uFlags |= MF_ENABLED;
	else
		uFlags |= MF_GRAYED;

	if (plugin->bOE5)
		plugin->bDisableMenus = !bEnable;
	else
	{
		GetMenuItemInfo(plugin->hMainMenu, FILE_MENU_POS, TRUE, &menuInfo);
		EnableMenuItem(menuInfo.hSubMenu, FILESAVEAS_MENU_POS, uFlags);
		EnableMenuItem(menuInfo.hSubMenu, FILESTATIONERY_MENU_POS, uFlags);
		EnableMenuItem(menuInfo.hSubMenu, FILEMOVE_MENU_POS, uFlags);
		EnableMenuItem(menuInfo.hSubMenu, FILECOPY_MENU_POS, uFlags);
		EnableMenuItem(menuInfo.hSubMenu, FILEPRINT_MENU_POS, uFlags);
		
		GetMenuItemInfo(plugin->hMainMenu, VIEW_MENU_POS, TRUE, &menuInfo);
		EnableMenuItem(menuInfo.hSubMenu, VIEWFONTS_MENU_POS, uFlags);
		EnableMenuItem(menuInfo.hSubMenu, VIEWLANG_MENU_POS, uFlags);
		
		DrawMenuBar(hwnd);
		
		SendMessage(plugin->hToolbar, TB_ENABLEBUTTON, IDC_SAVE,
			MAKELONG(bEnable, 0));
		SendMessage(plugin->hToolbar, TB_ENABLEBUTTON, IDC_PRINT,
			MAKELONG(bEnable, 0));
	}

	return;
}


LRESULT CALLBACK ReadToolbarParentWndProc(HWND hDlg, 
										  UINT msg,
										  WPARAM wParam, 
										  LPARAM lParam)
{
	WNDPROC lpOldProc;
	PluginInfo *plugin;
	LPNMHDR lpnm;
	LPNMTOOLBAR lptb;

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

	lpnm = (LPNMHDR) lParam;
	lptb = (LPNMTOOLBAR) lParam;

	switch(msg)
	{
		case WM_NOTIFY:
			{
				switch(lpnm->code)
				{
					case TBN_BEGINADJUST:
						//if we have inserted our stuff into the toolbar already
						if(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE)
							RemoveReadToolbarButtons(plugin);//de-initialize/remove stuff
						break;

					case TBN_ENDADJUST:
						{
							LRESULT lResult=0;
							
							lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam, 
										lParam);

							//if we have not inserted our stuff into the toolbar already
							if(!(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE))
							{
								//insert our stuff as necessary
								pgpAssert(-1 == plugin->nPGPKeysButton);
								AddReadToolbarButtons(plugin);								
							}

							/*SendMessage(plugin->hToolbar, TB_SETBUTTONSIZE, 0, 
								MAKELONG(nX, nY));*/
							return lResult;
						}
						break;
					default:
						break;
				}
			}
			break;

		default:
			break;
	}

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


void AddReadToolbarButtons(PluginInfo *lppilPlugInf)
{
	TBBUTTON tbb[4]={0};
	char szText[255] = {0};
	int nX = -1;
	int nDecryptBMP = -1;
	int nPGPkeysBMP = -1;
	LONG lResult = 0;
	int nDecryptSTR = -1;
	int nPGPkeysSTR = -1;
	int nRet = 0;

	//we should not be called out of sequence
	pgpAssert(lppilPlugInf->dwInitState & PIIF_MAINUIELEMENTS_FOUND);
	pgpAssert(!(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE));
	if(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE)
		return;//we have already inserted ourselves to the toolbar
	
	//get the no of buttons in the toolbar currently
	//nX = SendMessage(lppilPlugInf->hToolbar, TB_BUTTONCOUNT, 0, 0);
	//if (nX < 2)//if less than 2 buttons
	//	return;//bail. try again later ?!!

	//we should not be there already. alternately OE could not be using
	//our command id for itself
	pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX, IDC_DECRYPT, 0));
	pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX, IDC_PGPKEYS, 0));
	
	//add the decrypt bitmap to the imagelists
	nDecryptBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_DECRYPT);
	pgpAssert(-1 != nDecryptBMP);

	//remember the decrypt image index
	pgpAssert(-1 == lppilPlugInf->nDecryptImage);
	lppilPlugInf->nDecryptImage = nDecryptBMP;

	//load the pgpkeys bitmap
	nPGPkeysBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_PGPKEYS);
	pgpAssert(-1 != nPGPkeysBMP);

	//remember the keys bitmap image index
	pgpAssert(-1 == lppilPlugInf->nPGPKeysImage);
	lppilPlugInf->nPGPKeysImage = nPGPkeysBMP;

	//set the normal image list back
	//SendMessage(lppilPlugInf->hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hilToolbar);
	
	if (lppilPlugInf->bOE5)
	{
	
		//set the hot imagelist back. this is not necessary since we are not creating
		//a separate imagelist. just appending to the existing
		//SendMessage(lppilPlugInf->hToolbar, TB_SETHOTIMAGELIST, 0, (LPARAM) hilHotToolbar);
		
		//add the strings for decrypt and pgpkeys

		//if we have not already added the string for decrypt button
		if(-1 == lppilPlugInf->nDecryptString)
		{
			UIGetString(szText, 254, IDS_TOOLTIP_DECRYPT);
			nDecryptSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0, (LPARAM) szText);
			pgpAssert(-1 != nDecryptSTR);

			lppilPlugInf->nDecryptString = nDecryptSTR;
		}

		//if we have not already added the string for pgpkeys button
		if(-1 == lppilPlugInf->nPGPKeysString)
		{
			UIGetString(szText, 254, IDS_TOOLTIP_PGPKEYS);
			nPGPkeysSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0, (LPARAM) szText);
			pgpAssert(-1 != nPGPkeysSTR);

			lppilPlugInf->nPGPKeysString = nPGPkeysSTR;
		}	
		
	}//end if (lppilPlugInf->bOE5)
	
	//add our buttons with a separator from the rest
	tbb[0].iBitmap = -1;
	tbb[0].idCommand = -1;
	tbb[0].fsState = TBSTATE_ENABLED;
	tbb[0].fsStyle = TBSTYLE_SEP;
	tbb[0].dwData = 0;
	tbb[0].iString = -1;
	
	tbb[1].iBitmap = nDecryptBMP;
	tbb[1].idCommand = IDC_DECRYPT;
	tbb[1].fsState = TBSTATE_ENABLED;
	tbb[1].fsStyle = TBSTYLE_BUTTON;
	tbb[1].dwData = 0;
	tbb[1].iString = lppilPlugInf->nDecryptString;
	
	tbb[2].iBitmap = -1;
	tbb[2].idCommand = -1;
	tbb[2].fsState = TBSTATE_HIDDEN;
	tbb[2].fsStyle = TBSTYLE_SEP;
	tbb[2].dwData = 0;
	tbb[2].iString = -1;

	tbb[3].iBitmap = nPGPkeysBMP;
	tbb[3].idCommand = IDC_PGPKEYS;
	tbb[3].fsState = TBSTATE_ENABLED;
	tbb[3].fsStyle = TBSTYLE_BUTTON;
	tbb[3].dwData = 0;
	tbb[3].iString = lppilPlugInf->nPGPKeysString;
	
	//we must send TB_BUTTONSTRUCTSIZE before sending TB_ADDBITMAP 
	//or TB_ADDBUTTONS  message NOTE: this message has side effects
	SendMessage(lppilPlugInf->hToolbar, TB_BUTTONSTRUCTSIZE, 
			(WPARAM) sizeof(TBBUTTON), 0);

	//add the buttons
	lResult = SendMessage(lppilPlugInf->hToolbar, TB_ADDBUTTONS, 4, (LPARAM) &tbb);
	pgpAssert(TRUE == lResult);
	if(TRUE == lResult)//if successful
	{
		//retrieve and store the index of pgpkeys button
		pgpAssert(-1 == lppilPlugInf->nPGPKeysButton);
		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_DECRYPT, 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 RemoveReadToolbarButtons(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;
	}

	//remove the separator before the pgpkeys 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);


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

	//remove the separator before the decrypt 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 decrypt image from both image lists
	pgpAssert(-1 != lppilPlugInf->nDecryptImage);
	if( -1 != lppilPlugInf->nDecryptImage)
	{
		bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nDecryptImage);
		pgpAssert(0 != bRet);

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

		lppilPlugInf->nDecryptImage = -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);
}

/*__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 + -