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

📄 searchproc.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1998 Network Associates, Inc.
	All rights reserved.

	$Id: SearchProc.c,v 1.106 1999/04/08 14:08:43 pbj Exp $
____________________________________________________________________________*/

// System Headers 
#include <windows.h>
#include <windowsx.h>
#include <winsock.h>
#include <commctrl.h>

// PGPsdk Headers
#include "pgpKeys.h"
#include "pgpErrors.h"
#include "pgpKeyServer.h"
#include "pgpKeyServerPrefs.h"
#include "pgpBuildFlags.h"
#include "pgpUtilities.h"
#include "pgpClientPrefs.h"

// Shared Headers 
#include "PGPcl.h"
#include "PGPpkHlp.h" 

// Project Headers
#include "Search.h"
#include "Choice.h"
#include "SearchFilter.h"
#include "SearchCommon.h"
#include "resource.h"

typedef struct _SEARCHTHREADSTRUCT
{
	HWND				hwnd;
	HANDLE				threadHandle;
	DWORD				threadID;
	PGPFilterRef		filter;
	PGPKeyServerEntry	keyserverEntry;
	PGPKeySetRef		keySet;		
	PGPKeyServerRef		server;
	BOOL				bCancel;
	BOOL				bAlreadyAsked;

}SEARCHTHREADSTRUCT,*PSEARCHTHREADSTRUCT;


extern PGPContextRef	g_Context; 
extern PGPtlsContextRef g_TLSContext;
extern HINSTANCE		g_hInst;
extern CHAR				g_szHelpFile[MAX_PATH];

static DWORD aSearchIds[] = {			// Help IDs
    IDC_SEARCH,		IDH_PGPPKSEARCH_SEARCH, 
    IDC_STOP,		IDH_PGPPKSEARCH_STOP, 
    IDC_CLEAR,		IDH_PGPPKSEARCH_CLEAR, 
    IDC_LOCATION,	IDH_PGPPKSEARCH_LOCATION, 
    IDC_ATTRIBUTE,	IDH_PGPPKSEARCH_ATTRIBUTE, 
    IDC_VERB,		IDH_PGPPKSEARCH_VERB, 
    IDC_MORE,		IDH_PGPPKSEARCH_MORE, 
    IDC_FEWER,		IDH_PGPPKSEARCH_FEWER, 
    IDC_PENDING,	IDH_PGPPKSEARCH_PENDING,
    0,0 
}; 

PGPError PerformSearch(HWND hwndLocation, 
					   PSEARCHTHREADSTRUCT psts,
					   BOOL	bPending,
					   long* flags,
					   PGPKeySetRef* pKeySetOut);

PGPError SearchEventHandler(PGPContextRef context,
							PGPEvent *event, 
							PGPUserValue userValue);

DWORD WINAPI SearchThreadRoutine( LPVOID lpvoid);

void GrabUserIdStrings(HWND hwnd, 
					   char** string,
					   int* length);

BOOL 
CALLBACK 
SearchProc(	HWND hwnd, 
			UINT msg, 
			WPARAM wParam, 
			LPARAM lParam )
{ 
	static int offsetButtons	= 0;
	static int offsetBoxes		= 0;
	static int originalWidth	= 0;
	int oldWidth				= (int)GetProp(hwnd, "oldWidth");
	int oldHeight				= (int)GetProp(hwnd, "oldHeight");

	switch(msg)
	{
		case WM_INITDIALOG:
		{
			RECT rectWindow, rectButton, rectBox;
			HWND hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO);
			HWND hwndButton = GetDlgItem(hwnd, IDC_SEARCH);
			HWND hwndPending = GetDlgItem(hwnd, IDC_PENDING);
			HWND hwndTime = NULL;
			RECT rect;
			PSEARCHTHREADSTRUCT psts;
			CRITICAL_SECTION* keyserverLock;

			GetClientRect(hwndBox, &rect);
			MapWindowPoints(hwndBox, hwnd, (LPPOINT)&rect, 2);

			hwndTime = CreateWindowEx (0, DATETIMEPICK_CLASS,
							"DateTime",
							WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP,
							rect.left, rect.top-1, 
							rect.right-rect.left, rect.bottom-rect.top+2, 
							hwnd, NULL, g_hInst, NULL);

			SetWindowPos (hwndTime, GetDlgItem (hwnd, IDC_VERB),
							0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
			SendMessage (hwndTime, DTM_SETMCCOLOR, 
						MCSC_MONTHBK, (LPARAM)GetSysColor (COLOR_3DFACE));
			ShowWindow(hwndTime, SW_HIDE);
			SetProp( hwnd, "hwndTime", hwndTime); 

	
			GetWindowRect(hwnd, &rectWindow);
			GetWindowRect(hwndButton, &rectButton);
			GetWindowRect(hwndBox, &rectBox);

			offsetButtons = rectWindow.right - rectButton.right;
			offsetBoxes = rectButton.left - rectBox.right;
			oldWidth = rectWindow.right - rectWindow.left;
			SetProp( hwnd, "oldWidth",(HANDLE) oldWidth); 
			oldHeight = rectWindow.bottom - rectWindow.top;
			SetProp( hwnd, "oldHeight",(HANDLE) oldHeight);
			originalWidth  = oldWidth; 

			SetProp( hwnd, "ChoiceList",(HANDLE) 0);

			keyserverLock = 
				(CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION));
			
			if(keyserverLock)
			{
				InitializeCriticalSection(keyserverLock);

				SetProp(hwnd,"KeyserverLock", (HANDLE) keyserverLock ); 
			}

			EnterCriticalSection(keyserverLock);

			InitializeControlValues(hwnd, 0);

			LeaveCriticalSection(keyserverLock);

			psts = (PSEARCHTHREADSTRUCT) malloc( sizeof(SEARCHTHREADSTRUCT));

			if(psts)
			{
				memset(psts, 0x00, sizeof(SEARCHTHREADSTRUCT));
				SetProp(hwnd,"SearchInfo", (HANDLE) psts ); 
			}

			// subclass datetime control
			SetProp(hwndTime,"hwnd", hwnd ); 
			SetProp (hwndTime, "oldproc", 
						(HANDLE)GetWindowLong( hwndTime, GWL_WNDPROC ) ); 
			SetWindowLong(	hwndTime, 
							GWL_WNDPROC, 
							(DWORD)SearchSubclassWndProc );

			// subclass combo box
			hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO);
			SetProp(hwndBox,"hwnd", hwnd ); 
			SetProp (hwndBox, "oldproc", 
						(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) ); 
			SetWindowLong(	hwndBox, 
							GWL_WNDPROC, 
							(DWORD)SearchSubclassWndProc );

			// subclass combo box
			hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO_LIST);
			SetProp(hwndBox,"hwnd", hwnd ); 
			SetProp (hwndBox, "oldproc", 
						(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) ); 
			SetWindowLong(	hwndBox, 
							GWL_WNDPROC, 
							(DWORD)SearchSubclassWndProc );

			// subclass edit box
			hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_EDIT);
			SetProp(hwndBox,"hwnd", hwnd ); 
			SetProp (hwndBox, "oldproc", 
						(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) ); 
			SetWindowLong(	hwndBox, 
							GWL_WNDPROC, 
							(DWORD)SearchSubclassWndProc );

			SetFocus(hwndBox);


			#if PGP_BUSINESS_SECURITY
			if (PGPclIsAdminInstall ())
				ShowWindow(hwndPending, SW_SHOW);
			#endif	// PGP_BUSINESS_SECURITY

			return FALSE;
		}

		case WM_DESTROY:
		{
			HINSTANCE			hinst			= GetModuleHandle(NULL);
			PCHOICE				choice			= NULL;
			HWND				hwndChoice		= NULL;
			HWND				hwndLocation	= NULL;
			LPARAM				itemData		= 0;
			int					searchPathIndex	= 0;
			int					locationSelection = 0;
			char				szString[256]	= {0x00};
			PSEARCHTHREADSTRUCT	psts			= NULL;
			CRITICAL_SECTION*	keyserverLock	= NULL;
			PSEARCHPATH			path			= NULL;
			
			psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");

			if(psts)
			{
				if(psts->threadHandle)
					TerminateThread(psts->threadHandle, 0); 
				free(psts);
			}

			keyserverLock = (CRITICAL_SECTION*) GetProp(hwnd, 
														"KeyserverLock");

			if(keyserverLock)
			{
				EnterCriticalSection(keyserverLock);
				DeleteCriticalSection( keyserverLock ); 
				free(keyserverLock);
			}

			// remove all the choice windows
			do
			{
				choice = RemoveLastChoice(hwnd, &hwndChoice);
				DestroyWindow( hwndChoice );

			}while( choice );

			// free the prefs struct I am using
			
			hwndLocation = GetDlgItem(hwnd, IDC_LOCATION);
			locationSelection = ComboBox_GetCurSel(hwndLocation);

			path = (PSEARCHPATH) GetProp(hwnd, "SearchPath");

			if(path)
			{
				PGPDisposePrefData(path->prefRef, path->keyserverList);

				PGPSetPrefNumber (	path->prefRef,
							kPGPPrefLastSearchWindowSelection, 
							(PGPUInt32)locationSelection);

				PGPclCloseClientPrefs (	path->prefRef, TRUE);
				free(path);
			}

			CloseSearch ();
			return TRUE;
		}

#define DividerItem 1

		case WM_MEASUREITEM:     
		{
		    LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam; 
		     		    
            if (lpmis->itemID != -1) 
            {
                lpmis->itemHeight += 2;
 			}
 			
  			return TRUE; 
		}
		
		//  Draw the listbox
	  	case WM_DRAWITEM:                                    
	  	{
			LPDRAWITEMSTRUCT lpDs	= (LPDRAWITEMSTRUCT)lParam;
			int iTextVOff			=	2;
			RECT Rect, EtchRect;
			HBRUSH hBrush;
			char szText[ 256 ];
			
			//  If nothing to draw, exit now
			if( lpDs->itemID == CB_ERR )     
			{     
				return( FALSE );
			}
			
			Rect.left = lpDs->rcItem.left;
			Rect.top = lpDs->rcItem.top;
			Rect.right = lpDs->rcItem.right;
			Rect.bottom = lpDs->rcItem.bottom;
			
			//  Create a brush using the item's background color
			hBrush = CreateSolidBrush( GetSysColor(COLOR_WINDOW ));
			
			//  Fill entire item area
			FillRect( lpDs->hDC, &Rect, hBrush );   
			
			//  Delete the brush when done
			DeleteObject( hBrush );       
			
			//  Highlight if selected
			if( lpDs->itemState & ODS_FOCUS )
			{
				if (!(lpDs->itemState & ODS_COMBOBOXEDIT)) {
					if (lpDs->itemID == DividerItem) {
						iTextVOff = 1;
	               		Rect.bottom -= 2;
					}
					else if (lpDs->itemID == DividerItem+1)
						Rect.top += 1;
				}

				//  Create a brush using the item's background color
				hBrush = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT ));
			
				//  Fill entire item area
				FillRect( lpDs->hDC, &Rect, hBrush );   
			
				//  Delete the brush when done
				DeleteObject( hBrush );  
			}       
			
			//  Get the item string
			SendMessage(lpDs->hwndItem, 
						CB_GETLBTEXT , 
						lpDs->itemID,
						(LPARAM)szText );
						
			
			SetBkMode( lpDs->hDC, TRANSPARENT );
			
			SetTextColor( 	lpDs->hDC, 
							GetSysColor(( (lpDs->itemState & ODS_FOCUS) ?
									COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT) ));

			//  and display the text
			TextOut(lpDs->hDC, 
					4, 
					lpDs->rcItem.top + iTextVOff, 
					szText,
			      	strlen( szText ) );  
			 
 			
 			EtchRect = lpDs->rcItem;
 			
 			if (!(lpDs->itemState & ODS_COMBOBOXEDIT) &&
				 (lpDs->itemID == DividerItem)) 
			{
       			EtchRect.top = EtchRect.bottom-1;
        		
            	DrawEdge( 	lpDs->hDC,
 							&EtchRect, 
 							EDGE_ETCHED, 
 							BF_TOP ); 
			}
			      	                      	
			return TRUE;

		} //  End of WM_DRAWITEM

		case WM_GETDLGCODE:
		{
			return DLGC_WANTMESSAGE;	
		}

		case WM_CONTEXTMENU: 
		{
			WinHelp ((HWND) wParam, g_szHelpFile, HELP_CONTEXTMENU, 
				(DWORD) (LPVOID) aSearchIds); 
			break; 
		}

		case SEARCH_SET_LOCAL_KEYSET:
		{
			HINSTANCE hinst		= GetModuleHandle(NULL);
			HWND hwndBox		= NULL;
			char szString[256]	= {0x00};
			int i				= 0;

			hwndBox = GetDlgItem(hwnd, IDC_LOCATION);

			LoadString(hinst, IDS_LOCAL_KEYRING, szString, sizeof(szString));
			i = ComboBox_FindString(hwndBox, -1, szString);
			ComboBox_SetItemData(hwndBox, i, lParam);

			break;
		}

		case SEARCH_SET_CURRENT_SEARCH:
		{
			HINSTANCE hinst		= GetModuleHandle(NULL);
			HWND hwndBox		= NULL;
			char szString[256]	= {0x00};
			int i				= 0;

			hwndBox = GetDlgItem(hwnd, IDC_LOCATION);

			LoadString(hinst, IDS_CURRENT_SEARCH, szString, sizeof(szString));
			i = ComboBox_FindString(hwndBox, -1, szString);
			ComboBox_SetItemData(hwndBox, i, lParam);

			break;
		}

		case SEARCH_SET_FOCUS:
		{
			SetFocus (GetDlgItem (hwnd, IDC_SEARCH));
			break;
		}

		case WM_NOTIFY:
		{
			LPNMHDR pnmh = (LPNMHDR) lParam;
			
			switch(pnmh->code)
			{
				case REFRESH_KEYSERVER_LIST:
				{
					CRITICAL_SECTION* keyserverLock = 
						(CRITICAL_SECTION*) GetProp(hwnd, "KeyserverLock");

					EnterCriticalSection(keyserverLock);
					
					ReloadKeyserverList(hwnd);

					LeaveCriticalSection(keyserverLock);

					break;
				}
			}

			break;
		}

		case WM_SIZE:
		{
			BOOL fwSizeType = wParam;      // resizing flag 
			WORD newWidth = LOWORD(lParam);  // width of client area 
			WORD newHeight = HIWORD(lParam); // height of client area 
			int	 delta =  newWidth - oldWidth;
			RECT rectControl;
			HWND hwndControl;


			if( newWidth < originalWidth )
			{
				delta = originalWidth - oldWidth;
				newWidth = originalWidth;
				
			}

			if( newWidth >= originalWidth )
			{
				PCHOICE choice = NULL;

				oldWidth = newWidth;
				SetProp( hwnd, "oldWidth",(HANDLE) oldWidth);

				// move Search Button
				hwndControl = GetDlgItem(hwnd, IDC_SEARCH);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left + delta,
							rectControl.top,
							rectControl.right - rectControl.left,
							rectControl.bottom - rectControl.top,
							TRUE);

				// move Stop Button
				hwndControl = GetDlgItem(hwnd, IDC_STOP);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left + delta,
							rectControl.top,
							rectControl.right - rectControl.left,
							rectControl.bottom - rectControl.top,
							TRUE);

				// move Clear Button
				hwndControl = GetDlgItem(hwnd, IDC_CLEAR);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left + delta,
							rectControl.top,
							rectControl.right - rectControl.left,
							rectControl.bottom - rectControl.top,
							TRUE);


				// move Help Button
				hwndControl = GetDlgItem(hwnd, IDHELP);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left + delta,
							rectControl.top,
							rectControl.right - rectControl.left,
							rectControl.bottom - rectControl.top,
							TRUE);

				// move the Boxes
				hwndControl = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left,
							rectControl.top,
							rectControl.right - rectControl.left + delta,
							rectControl.bottom - rectControl.top,
							TRUE);

				hwndControl = GetDlgItem(hwnd, IDC_SPECIFIER_EDIT);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left,
							rectControl.top,
							rectControl.right - rectControl.left  + delta,
							rectControl.bottom - rectControl.top,
							TRUE);

				hwndControl = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO_LIST);
				GetWindowRect(hwndControl, &rectControl);
				MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
				MoveWindow(	hwndControl, 
							rectControl.left,
							rectControl.top,
							rectControl.right - rectControl.left + delta,
							rectControl.bottom - rectControl.top,
							TRUE);

				// move all the choice windows
				choice = FirstChoice(hwnd);

				while( choice )
				{
					hwndControl =  choice->hwnd;
					GetWindowRect(hwndControl, &rectControl);
					MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
					MoveWindow(	hwndControl, 
								rectControl.left,
								rectControl.top ,
								rectControl.right - rectControl.left + delta,
								rectControl.bottom - rectControl.top,
								TRUE);

					choice = NextChoice(hwnd, choice);
				}

				// move the more and less buttons and the pending checkbox
				if(oldHeight != newHeight)
				{
					delta = newHeight - oldHeight;

					oldHeight = newHeight;
					SetProp( hwnd, "oldHeight",(HANDLE) oldHeight);

					hwndControl = GetDlgItem(hwnd, IDC_MORE);
					GetWindowRect(hwndControl, &rectControl);
					MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
					MoveWindow(	hwndControl, 
								rectControl.left,
								rectControl.top + delta,
								rectControl.right - rectControl.left,
								rectControl.bottom - rectControl.top,
								TRUE);

					hwndControl = GetDlgItem(hwnd, IDC_FEWER);
					GetWindowRect(hwndControl, &rectControl);
					MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
					MoveWindow(	hwndControl, 
								rectControl.left,
								rectControl.top + delta,
								rectControl.right - rectControl.left,
								rectControl.bottom - rectControl.top,
								TRUE);

					hwndControl = GetDlgItem(hwnd, IDC_PENDING);
					GetWindowRect(hwndControl, &rectControl);
					MapWindowPoints(NULL, hwnd, (LPPOINT)&rectControl, 2);
					MoveWindow(	hwndControl, 
								rectControl.left,
								rectControl.top + delta,
								rectControl.right - rectControl.left,
								rectControl.bottom - rectControl.top,
								TRUE);

				}
			}
			
			return TRUE;
		}

		case WM_PAINT:
		{
			RECT rect, rectParent;

⌨️ 快捷键说明

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