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

📄 sendmsgwndproc.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

				UIGetString(szMenu, 254, IDS_MENU_SMIME_SIGN);
				menuInfo.fMask = MIIM_TYPE;
				menuInfo.fType = MFT_STRING;
				menuInfo.dwTypeData = szMenu;

				SetMenuItemInfo((HMENU) wParam, OE5_SIGN_SMIME_POS, TRUE, 
					&menuInfo);

				UIGetString(szMenu, 254, IDS_MENU_PGP_SIGN);
				menuInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
				menuInfo.fType = MFT_STRING;
				menuInfo.wID = IDC_SIGN_PGP;
				menuInfo.dwTypeData = szMenu;
				
				if (plugin->bSign)
					menuInfo.fState = MFS_ENABLED | MFS_CHECKED;
				else
					menuInfo.fState = MFS_ENABLED;

				InsertMenuItem((HMENU) wParam, OE5_SIGN_PGP_POS, TRUE, 
					&menuInfo);

				return lResult;
			}
			else if (!strcmp(szMenu, "&PGP"))
			{
				lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam, 
							lParam);
				
				menuInfo.cbSize = sizeof(MENUITEMINFO);
				menuInfo.fMask = MIIM_STATE;
				
				if (plugin->bEncrypt)
					menuInfo.fState = MFS_ENABLED | MFS_CHECKED;
				else
					menuInfo.fState = MFS_ENABLED;

				SetMenuItemInfo((HMENU) wParam, IDC_ENCRYPT_PGP, FALSE, 
					&menuInfo);

				if (plugin->bSign)
					menuInfo.fState = MFS_ENABLED | MFS_CHECKED;
				else
					menuInfo.fState = MFS_ENABLED;

				SetMenuItemInfo((HMENU) wParam, IDC_SIGN_PGP, FALSE, 
					&menuInfo);
				
				menuInfo.fState = MFS_ENABLED;

				SetMenuItemInfo((HMENU) wParam, IDC_PGPMENU, FALSE, 
					&menuInfo);
				
				SetMenuItemInfo(plugin->hPGPMenu, IDC_PREFS, FALSE, 
					&menuInfo);
				
				SetMenuItemInfo(plugin->hPGPMenu, IDC_PGPKEYS, FALSE, 
					&menuInfo);
				
				return lResult;
			}
		}
		break;

	case WM_NOTIFY:
		if ((((LPNMHDR) lParam)->code) == TTN_GETDISPINFO) 
		{
			int idCtrl;
			NMTTDISPINFO *pInfo;
			BOOL bTooltip = FALSE;

			idCtrl = ((LPNMHDR) lParam)->idFrom;
			pInfo = (NMTTDISPINFO *) lParam;

			switch (idCtrl)
			{
			case IDC_ENCRYPT_SMIME:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_SMIME_ENCRYPT;
				bTooltip = TRUE;
				break;

			case IDC_SIGN_SMIME:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_SMIME_SIGN;
				bTooltip = TRUE;
				break;

			case IDC_ENCRYPT_PGP:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGP_ENCRYPT;
				bTooltip = TRUE;
				break;

			case IDC_SIGN_PGP:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGP_SIGN;
				bTooltip = TRUE;
				break;

			case IDC_PGPKEYS:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGPKEYS;
				bTooltip = TRUE;
				break;
			}

			if (bTooltip)
			{
				pInfo->hinst = UIGetInstance();
				return 0;
			}
		}
		break;
	}

	return CommonWndProc(hDlg, msg, wParam, lParam);
}


BOOL EncryptSignMessage(HWND hwnd)
{
	HWND hAttach;
	char *szInput = NULL;
	char *szOutput;
	DWORD dwLength;
	PGPSize nOutLength;
	RECIPIENTDIALOGSTRUCT *prds = NULL;
	PGPOptionListRef signOptions = NULL;
	PluginInfo *plugin;
	BOOL bSuccess = FALSE;
	char szExe[256];
	char szDll[256];
	PGPError nError = kPGPError_NoErr;
	
	UIGetString(szExe, sizeof(szExe), IDS_EXE);
	UIGetString(szDll, sizeof(szDll), IDS_DLL);
	
	plugin = GetPluginInfo(hwnd);

	hAttach = FindWindowEx(hwnd, NULL, "SysListView32", NULL);
	
	if (hAttach)
		if (ListView_GetItemCount(hAttach) > 0)
			if (!UIWarnUser(hwnd, IDS_W_ATTACHMENT, "Attachment"))
				return FALSE;

	prds = (RECIPIENTDIALOGSTRUCT *) 
			calloc(sizeof(RECIPIENTDIALOGSTRUCT), 1);

	nError = PGPsdkLoadDefaultPrefs(plugin->pgpContext);
	if (IsPGPError(nError))
	{
		UIDisplayErrorCode(__FILE__, __LINE__, szDll, nError);
		goto EncryptSignMessageError;
	}

	nError = PGPOpenDefaultKeyRings(plugin->pgpContext, 
				(PGPKeyRingOpenFlags)0, &(prds->OriginalKeySetRef));

	if (IsPGPError(nError))
	{
		UIDisplayErrorCode(__FILE__, __LINE__, szDll, nError);
		goto EncryptSignMessageError;
	}

	if (!GetMessageText(hwnd, FALSE, &szInput))
		goto EncryptSignMessageError;

	dwLength = strlen(szInput);
	FixBadSpaces(szInput);

	if (plugin->bEncrypt)
	{
		char *szRecipients;

		if (!GetRecipientText(hwnd, &szRecipients))
			goto EncryptSignMessageError;

		nError = GetRecipients(hwnd, szRecipients, plugin->pgpContext, 
					plugin->tlsContext, prds);
		free(szRecipients);
	}

	if (IsPGPError(nError))
	{
		if (nError != kPGPError_UserAbort)
			UIDisplayErrorCode(__FILE__, __LINE__, szDll, 
				nError);

		goto EncryptSignMessageError; 
	}
			
	nError = EncryptSignBuffer(UIGetInstance(), hwnd, plugin->pgpContext, 
				plugin->tlsContext, szExe, szDll, szInput, dwLength, prds, 
				NULL, &signOptions, (void **) &szOutput, &nOutLength, 
				plugin->bEncrypt, plugin->bSign, FALSE);

	free(szInput);
	szInput = NULL;

	if (IsntPGPError(nError))
	{
		if (!SetMessageText(hwnd, szOutput))
			PGPFreeData(szOutput);
		else
		{
			PGPFreeData(szOutput);
			plugin->bEncrypt = FALSE;
			plugin->bSign = FALSE;
			if (!(plugin->bOE5))
				UpdateMenus(hwnd, plugin);
			bSuccess = TRUE;
		}
	}

EncryptSignMessageError:

	if (signOptions != NULL)
	{
		PGPFreeOptionList(signOptions);
		signOptions = NULL;
	}

	if (prds->OriginalKeySetRef != NULL)
	{
		PGPFreeKeySet(prds->OriginalKeySetRef);
		prds->OriginalKeySetRef = NULL;
	}

	FreeRecipients(prds);
	free(prds);

	if (szInput != NULL)
		free(szInput);

	return bSuccess;
}


void DoubleLineFeeds(char *szOriginal, char *szNew)
{
	int nOrigIndex = 0;
	int nNewIndex = 0;
	BOOL bCRLF = FALSE;

	while (szOriginal[nOrigIndex] != '\0')
	{
		szNew[nNewIndex++] = szOriginal[nOrigIndex++];
		if (szOriginal[nOrigIndex-1] == '\n')
		{
			if (bCRLF)
			{
				szNew[nNewIndex++] = '\r';
				szNew[nNewIndex++] = '\n';
				bCRLF = FALSE;
			}
			else
				bCRLF = TRUE;
		}
	}

	szNew[nNewIndex] = '\0';
	return;
}


static void UpdateMenus(HWND hwnd, PluginInfo *plugin)
{
	if (plugin->bEncrypt)
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_ENCRYPT_PGP, 
			MF_BYCOMMAND | MF_CHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_ENCRYPT_PGP,
			MAKELONG(TRUE, 0));
	}
	else
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_ENCRYPT_PGP, 
			MF_BYCOMMAND | MF_UNCHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_ENCRYPT_PGP,
			MAKELONG(FALSE, 0));
	}
	
	if (plugin->bSign)
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_SIGN_PGP, 
			MF_BYCOMMAND | MF_CHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_SIGN_PGP,
			MAKELONG(TRUE, 0));
	}
	else
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_SIGN_PGP, 
			MF_BYCOMMAND | MF_UNCHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_SIGN_PGP,
			MAKELONG(FALSE, 0));
	}
	
}


LRESULT CALLBACK SendToolbarParentWndProc(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:
		{
			int nIndex;

			if (lpnm->code == TBN_BEGINADJUST)
			{
				nIndex = SendMessage(plugin->hToolbar, TB_COMMANDTOINDEX,
							IDC_PGPKEYS, 0);

				SendMessage(plugin->hToolbar, TB_DELETEBUTTON, nIndex, 0);
				plugin->nPGPKeysButton = -1;

				nIndex = SendMessage(plugin->hToolbar, TB_COMMANDTOINDEX,
							IDC_SIGN_PGP, 0);

				SendMessage(plugin->hToolbar, TB_DELETEBUTTON, nIndex, 0);

				nIndex = SendMessage(plugin->hToolbar, TB_COMMANDTOINDEX,
							IDC_ENCRYPT_PGP, 0);

				SendMessage(plugin->hToolbar, TB_DELETEBUTTON, nIndex, 0);
				SendMessage(plugin->hToolbar, TB_DELETEBUTTON, nIndex - 1, 0);
			}

			if (lpnm->code == TBN_ENDADJUST)
			{
				DWORD dwSize;
				int nX;
				int nY;
				TBBUTTON tbb[4];
				
				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 = plugin->nEncryptImage;
				tbb[1].idCommand = IDC_ENCRYPT_PGP;
				tbb[1].fsState = TBSTATE_ENABLED;
				tbb[1].fsStyle = TBSTYLE_CHECK;
				tbb[1].dwData = 0;
				tbb[1].iString = plugin->nEncryptString;
				
				tbb[2].iBitmap = plugin->nSignImage;
				tbb[2].idCommand = IDC_SIGN_PGP;
				tbb[2].fsState = TBSTATE_ENABLED;
				tbb[2].fsStyle = TBSTYLE_CHECK;
				tbb[2].dwData = 0;
				tbb[2].iString = plugin->nSignString;
				
				tbb[3].iBitmap = plugin->nPGPKeysImage;
				tbb[3].idCommand = IDC_PGPKEYS;
				tbb[3].fsState = TBSTATE_ENABLED;
				tbb[3].fsStyle = TBSTYLE_BUTTON;
				tbb[3].dwData = 0;
				tbb[3].iString = plugin->nPGPKeysString;
				
				dwSize = SendMessage(plugin->hToolbar, TB_GETBUTTONSIZE, 0, 0);
				nX = LOWORD(dwSize);
				nY = HIWORD(dwSize);
				
				SendMessage(plugin->hToolbar, TB_ADDBUTTONS, 4, 
					(LPARAM) &tbb);

				SendMessage(plugin->hToolbar, TB_SETBUTTONSIZE, 0, 
					MAKELONG(nX, nY));
		
				plugin->nPGPKeysButton = SendMessage(plugin->hToolbar,
											TB_COMMANDTOINDEX,
											IDC_PGPKEYS,
											0);
			}

			break;
		}
	}

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


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