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

📄 pgpkeys.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.
	
	PGPkeys.c - PGPkeys WinMain, associated routines, and global variables	

	$Id: PGPkeys.c,v 1.47 2002/11/12 18:57:30 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"

// project header files
#include "PGPkeysx.h"
#include "pgpWin32IPC.h"
#include "pgpImageList.h"

// pgp header files
#include "pgpRandomPool.h"
#include "pgpUnicodeWin32.h"
#include "pgpPDA.h"

// system header files
#include <ole2.h>
#include <zmouse.h>

#define INSTALLER_SWITCH	("/i")

// typedefs
typedef struct _DLGLISTSTRUCT {
	struct	_DLGLISTSTRUCT* next;
	HWND	hwnd;
	BOOL	bDlg;
	BOOL	bProperties;
} WINDOWLISTSTRUCT, *PWINDOWLISTSTRUCT;

// Application global variables
HINSTANCE			g_hinst						= NULL;
HWND				g_hwndMain					= NULL;
HWND				g_hwndActive				= NULL;
HIMAGELIST			g_hilKeys					= NULL;
HICON				g_hiconToken				= NULL;
HICON				g_hiconOpenLock				= NULL;
HICON				g_hiconClosedLock			= NULL;
PGPContextRef		g_context					= kInvalidPGPContextRef;
PGPtlsContextRef	g_tlscontext				= kInvalidPGPtlsContextRef;
PGPBoolean			g_bKeyGenEnabled			= TRUE;
PGPBoolean			g_bX509CertRequestEnabled	= TRUE;
PGPBoolean			g_bKeyReconstructionEnabled	= FALSE;
PGPBoolean			g_bExpertMode				= FALSE;
PGPBoolean			g_bMarginalAsInvalid		= FALSE;
BOOL				g_bShowGroups				= FALSE;
INT					g_iGroupsPercent			= 0;
INT					g_iToolHeight				= 0;
PGPUInt32			g_uNumTokens				= 0;
PGPPDASTRUCT*		g_pPDA						= NULL;

UINT				g_uReloadKeyringMessage			= 0;
UINT				g_uReloadPrefsMessage			= 0;	
UINT				g_uReloadKeyserverPrefsMessage	= 0;	
UINT				g_uMouseWheelMessage			= 0;

// Local globals
static HHOOK				s_hhookKeyboard;		//handle of keyboard hook 
static HHOOK				s_hhookMouse;			//handle of mouse hook 
static PWINDOWLISTSTRUCT	s_pWindowList = NULL;

//	____________________________________
//
//	Check for correct version of Windows

static BOOL 
sIsCorrectVersion (VOID) 
{
	OSVERSIONINFO osid;

	osid.dwOSVersionInfoSize = sizeof (osid);
	GetVersionEx (&osid);

	switch (osid.dwPlatformId) {

	case VER_PLATFORM_WIN32s :
		return FALSE;

	// Windows 95
	case VER_PLATFORM_WIN32_WINDOWS :
 		return TRUE;

	// Windows NT
	case VER_PLATFORM_WIN32_NT :
		if (osid.dwMajorVersion >= 4) return TRUE;
//>>>
		MessageBox (NULL, "PGPkeys is not supported on Windows NT 3.51\n\n"
			"Use at your own risk.",
		"PGPkeys Warning", MB_OK|MB_ICONEXCLAMATION);
		return TRUE;
//<<<
	default :
		return FALSE;
	}
}

//	____________________________________
//
//	Check for previously running instances

static BOOL 
sDoIExist (
		LPSTR lpszSemName, 
		LPSTR lpszClassName, 
		LPSTR lpszWindowTitle) 
{
    HANDLE			hSem;
    HWND			hWndMe;
	COPYDATASTRUCT	cds;

    // Create or open a named semaphore. 
    hSem = CreateSemaphore (NULL, 0, 1, lpszSemName);

    // Close handle and return NULL if existing semaphore was opened.
    if ((hSem != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS)) 
	{
        CloseHandle(hSem);
        hWndMe = FindWindow (lpszClassName, lpszWindowTitle);
        if (hWndMe) 
		{
			if (!IsZoomed (hWndMe)) 
				ShowWindow (hWndMe, SW_RESTORE);

			SetForegroundWindow (hWndMe);
			cds.dwData = PGPPK_IMPORTKEYCOMMANDLINE | PGPPK_SELECTIVEIMPORT;
			cds.lpData = GetCommandLine ();
			cds.cbData = lstrlen (cds.lpData) +1;
			SendMessage (hWndMe, WM_COPYDATA, 0, (LPARAM)&cds);
		}
        return TRUE;
    }

    // If new semaphore was created, return FALSE.
    return FALSE;
}


//	____________________________________
//
//	Check to see if we were run by the installer

static BOOL 
sInstallerInvoked (VOID)
{
	if (strstr (GetCommandLine (), INSTALLER_SWITCH))
		return TRUE;
	else
	    return FALSE;
}


//	____________________________________________________________
//
//	load appropriate imagelist for display

static VOID
sInitImageLists (VOID)
{
	HDC			hdc;
	HBITMAP		hbmp;
	INT			iNumBits;

	// create imagelist and load the appropriate bitmaps based on 
	// current display capabilities.
	hdc = GetDC (NULL);		// DC for desktop
	iNumBits = GetDeviceCaps (hdc, BITSPIXEL) * GetDeviceCaps (hdc, PLANES);
	ReleaseDC (NULL, hdc);

	if (iNumBits <= 8) 
	{
		g_hilKeys = ImageList_Create (16, 16, 
				ILC_COLOR|ILC_MASK, NUM_IMAGELIST_ICONS, 0); 
		hbmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_KEYICONS4BIT));
		ImageList_AddMasked (g_hilKeys, hbmp, RGB(255, 0, 255));
		DeleteObject (hbmp);
	}
	else 
	{
		g_hilKeys = ImageList_Create (16, 16, 
				ILC_COLOR24|ILC_MASK, NUM_IMAGELIST_ICONS, 0); 
		hbmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_KEYICONS24BIT));
		ImageList_AddMasked (g_hilKeys, hbmp, RGB(255, 0, 255));
		DeleteObject (hbmp);
	}

	g_hiconToken = ImageList_GetIcon (
			g_hilKeys, IDX_TOKEN, ILD_TRANSPARENT);
	g_hiconOpenLock = ImageList_GetIcon (
			g_hilKeys, IDX_OPENLOCK, ILD_TRANSPARENT);
	g_hiconClosedLock = ImageList_GetIcon (
			g_hilKeys, IDX_CLOSEDLOCK, ILD_TRANSPARENT);
}


//	____________________________________________
//
//	Initializations for all instances of program

static BOOL 
sInitApplication (
		HINSTANCE	hInstance, 
		BOOL		bIgnoreComctlError) 
{
	WNDCLASS				wndclass;
	PGPError				err;

	// check correct version of windows
	if (!sIsCorrectVersion ()) 
		return FALSE;

	// check for previous instances
	if (sDoIExist (PGPKEYS_SEMAPHORENAME, 
				PGPKEYS_WINCLASSNAME, PGPKEYS_WINDOWTITLE)) 
		return FALSE;

	// save instance handle
	g_hinst = hInstance;

	// check if we are being run by the installer
	if (sInstallerInvoked ())
		return FALSE;

	// register the reload messages
	g_uReloadKeyringMessage = 
			RegisterWindowMessage (kPGPclReloadKeyRingMsg);
	g_uReloadPrefsMessage = 
			RegisterWindowMessage (kPGPclReloadPrefsMsg);
	g_uReloadKeyserverPrefsMessage = 
			RegisterWindowMessage (kPGPclReloadKeyserverPrefsMsg);

	// register the mouse wheel message
	g_uMouseWheelMessage = 
			RegisterWindowMessage (MSH_MOUSEWHEEL);

	// make sure PGPkeys is installed
	if (!PGPclIsComponentInstalled (kPGPclPGPkeys))
	{
		PKMessageBox (NULL, IDS_CAPTIONERROR,
				IDS_NOTINSTALLED, MB_OK|MB_ICONHAND);
		return FALSE;
	}

	// initialize client library
	// note: this fails if common control DLL is not correct version
	err = PGPclInitLibrary (&g_context, 
			kPGPclEnableNewUserWizard | kPGPclForceNewUserWizard);
	if (IsPGPError (err))
	{
		if (err == kPGPError_Win32_InvalidComctl32 && bIgnoreComctlError)
			err = kPGPError_NoErr;
		else if (err == kPGPError_FeatureNotAvailable) 
		{
			PKMessageBox (NULL, IDS_CAPTIONERROR, 
					IDS_SDKEXPIRED, MB_OK|MB_ICONSTOP);
			return FALSE;
		}
		else
		{
			PGPclErrorBox (NULL, err);
			return FALSE;
		}

		PGPclCloseLibrary ();
	}

	PGPclErrorBox (NULL, PGPNewTLSContext (g_context, &g_tlscontext));

	sInitImageLists ();

	wndclass.style = 0;                     
	wndclass.lpfnWndProc = (WNDPROC)PGPkeysWndProc; 
	wndclass.cbClsExtra = 0;              
	wndclass.cbWndExtra = 0;              
	wndclass.hInstance = hInstance;       
	wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_EXEICON));
	wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); 
    wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = PGPKEYS_WINCLASSNAME;

	return (RegisterClass (&wndclass));
}

//	____________________________________
//
//  Hook procedure for WH_MOUSE hook.
  
static LRESULT CALLBACK 
sMouseHookProc (
		INT		iCode, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{ 
    if (iCode >= 0) 
		PGPGlobalRandomPoolMouseMoved ();

	return CallNextHookEx (s_hhookMouse, iCode, wParam, lParam);
} 

//	____________________________________
//
//  Hook procedure for WH_KEYBOARD hook.
  
static LRESULT CALLBACK 
sKeyboardHookProc (
		INT		iCode, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{ 
    if (iCode >= 0) 
	{
		// only add key presses (not releases)
		if (!(lParam & 0x80000000))
		{
			PGPGlobalRandomPoolAddKeystroke (wParam);
		}
	}

	return CallNextHookEx (s_hhookKeyboard, iCode, wParam, lParam);
} 

//	____________________________________
//
//	Send message to all windows in list

VOID
PKSendMessageWindowList (
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam)
{
	PWINDOWLISTSTRUCT pwls;

	pwls = s_pWindowList;

	while (pwls) 
	{
		SendMessage (pwls->hwnd, uMsg, wParam, lParam);
		pwls = pwls->next;
	}
}

//	____________________________________
//
//	Post message to all windows in list

VOID
PKPostMessageWindowList (
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam)
{
	PWINDOWLISTSTRUCT pwls;

	pwls = s_pWindowList;

	while (pwls) 
	{
		PostMessage (pwls->hwnd, uMsg, wParam, lParam);
		pwls = pwls->next;
	}
}

//	____________________________________
//
//	Enable/Disable all windows in list

VOID
PKEnableWindowList (BOOL bEnabled)
{
	PWINDOWLISTSTRUCT pwls;

	pwls = s_pWindowList;

	while (pwls) 
	{
		EnableWindow (pwls->hwnd, bEnabled);
		pwls = pwls->next;
	}
}

//	____________________________________
//
//	Add dlg hwnd to linked list

static VOID
sAddWindowToList (
		HWND	hwnd, 
		BOOL	bDlg,
		BOOL	bProperties)
{
	PWINDOWLISTSTRUCT pwls;

	pwls = pkAlloc (sizeof (WINDOWLISTSTRUCT));
	if (pwls) 
	{
		pwls->hwnd = hwnd;
		pwls->bDlg = bDlg;
		pwls->bProperties = bProperties;
		pwls->next = s_pWindowList;
		s_pWindowList = pwls;
	}
}

//	____________________________________
//
//	Remove dlg hwnd from linked list

static VOID
sRemoveWindowFromList (HWND hwnd)
{
	PWINDOWLISTSTRUCT pwls;
	PWINDOWLISTSTRUCT pwlsPrev;

	if (!s_pWindowList) 
		return;

	pwls = s_pWindowList;

	if (pwls->hwnd == hwnd) 
	{
		s_pWindowList = s_pWindowList->next;
	}
	else 
	{
		pwls = s_pWindowList->next;
		pwlsPrev = s_pWindowList;
		while (pwls) 
		{
			if (pwls->hwnd == hwnd) 
			{
				pwlsPrev->next = pwls->next;
				break;
			}
			pwlsPrev = pwls;
			pwls = pwls->next;
		}
	}

	if (pwls) 
		pkFree (pwls);
}

//	____________________________________
//
//	Add or remove dlg hwnd from linked list

VOID
PKAddRemoveWindowList (
		HWND	hwnd, 
		BOOL	bAdd, 
		BOOL	bDlg,
		BOOL	bProperties)
{
	// if a hwnd is specified, then add/remove if from list

⌨️ 快捷键说明

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