📄 pgpkeys.c
字号:
if (hwnd)
{
if (bAdd)
sAddWindowToList (hwnd, bDlg, bProperties);
else
sRemoveWindowFromList (hwnd);
}
}
// ___________________________________________________
//
// Find the hwnd of one of our windows given a point on the screen
BOOL
PKFindWindowFromPoint (
POINT* ppt,
HWND* phwnd)
{
PWINDOWLISTSTRUCT pwls;
RECT rc;
if (!phwnd)
return FALSE;
*phwnd = NULL;
if (!ppt)
return FALSE;
if (!s_pWindowList)
return FALSE;
pwls = s_pWindowList;
while (pwls)
{
GetWindowRect (pwls->hwnd, &rc);
if (PtInRect (&rc, *ppt))
{
//the point is within one of our main windows
HWND hActiveWindow=GetForegroundWindow();
//check if we are active currently
if(NULL != hActiveWindow)
{
if(hActiveWindow == pwls->hwnd)
{
//we are in the foreground
*phwnd = pwls->hwnd;
return TRUE;
}
return FALSE;//we are not in the foreground
}
//NOTE: there may not be any window in foreground
//extra logic here will slow down DoDragDrop (ssd)
}
pwls = pwls->next;
}
return TRUE;
}
// ___________________________________________________
//
// create an array of structs which include info of
// PDA menu items
static PGPPDASTRUCT*
sCreatePDAStructArray (void)
{
PGPPDASTRUCT* pPDA = NULL;
UINT uCount = 0;
HMODULE hmod;
CHAR szPath[MAX_PATH];
WIN32_FIND_DATA wfd;
HANDLE hFind;
PGPclGetPath (kPGPclInstallFolder, szPath, sizeof(szPath));
lstrcat (szPath, "PGPpda*.DLL");
hFind = FindFirstFile (szPath, &wfd);
if (hFind == INVALID_HANDLE_VALUE)
return NULL;
do
{
PGPclGetPath (kPGPclInstallFolder, szPath, sizeof(szPath));
lstrcat (szPath, wfd.cFileName);
hmod = LoadLibrary (szPath);
if (IsntNull (hmod))
{
BOOL bPda = FALSE;
PGPUInt32 (*pGetPdaAPI)(void);
pGetPdaAPI = (PGPUInt32 (*)(void))
GetProcAddress (hmod, "PGPpdaGetAPIVersion");
if (IsntNull (pGetPdaAPI))
{
PGPUInt32 uAPIVersion = (*pGetPdaAPI)();
// we only support API version 1.0
if ((uAPIVersion >= 0x00010000) &&
(uAPIVersion < 0x00020000))
{
PGPUInt32 (*pPdaAPIEx)(PGPpdaAPIStruct*);
bPda = TRUE;
pPdaAPIEx = (PGPUInt32 (*)(PGPpdaAPIStruct*))
GetProcAddress (hmod, "PGPpdaAPIVersionInfo");
if (IsntNull (pPdaAPIEx))
{
PGPpdaAPIStruct pas;
pgpClearMemory (&pas, sizeof(pas));
// tell the plugin which API version we support
pas.uPGPkeysVersion = MAKELONG (
MAKEWORD (PGPVERSIONSUBMINOR, PGPVERSIONMINOR),
MAKEWORD (PGPVERSIONMAJOR, 0));
pas.uPGPkeysAPIVersion = kPGPpda_APIVersion;
pas.uPGPkeysAPIFlags = 0;
(*pPdaAPIEx)(&pas);
bPda = TRUE;
}
}
}
if (bPda)
{
if (IsntNull (GetProcAddress (
hmod, "PGPpdaOpenKeyset")))
{
UINT uNew, uNewEx, uCountNew;
UINT u, uPlatform, uVersion;
PGPpdaIdStruct pis;
PGPUInt32 (*pGetPdaOpCount)(void);
PGPUInt32 (*pGetPdaOpCountEx)(PGPUInt32);
PGPError (*pGetPdaId)(PGPpdaIdStruct*);
pGetPdaId = (PGPError (*)(PGPpdaIdStruct*))
GetProcAddress (hmod, "PGPpdaGetIdentification");
uPlatform = kPGPpda_PlatformPalmOS;
uVersion = 0x0001000;
if (IsntNull (pGetPdaId))
{
if (IsntPGPError ((*pGetPdaId)(&pis)))
{
uPlatform = pis.uPlatform;
uVersion = pis.uVersion;
}
}
// we only allow one plugin per platform
for (u=0; u<uCount; u++)
{
if (pPDA[u].uPlatform == uPlatform)
{
if (pPDA[u].uVersion >= uVersion)
{
bPda = FALSE;
break;
}
else
{
// flag that this item is not to be used
pPDA[u].uPlatform = 0;
}
}
}
if (bPda)
{
pGetPdaOpCount = (PGPUInt32 (*)(void))
GetProcAddress (hmod, "PGPpdaGetOperationCount");
if (IsntNull (pGetPdaOpCount))
uNew = (*pGetPdaOpCount)();
pGetPdaOpCountEx = (PGPUInt32 (*)(PGPUInt32))
GetProcAddress (hmod, "PGPpdaGetOperationCountEx");
uNewEx = 0;
if (IsntNull (pGetPdaOpCountEx))
{
uNew = (*pGetPdaOpCountEx)(kPGPpdaOpType_MainWindow);
uNewEx = (*pGetPdaOpCountEx)(kPGPpdaOpType_PDAWindow);
}
uCountNew = uCount+uNew+uNewEx +1;
pPDA = realloc (pPDA,
(uCountNew +1) * sizeof(PGPPDASTRUCT));
pPDA[uCount].bKeyring = TRUE;
pPDA[uCount].hmod = hmod;
pPDA[uCount].hwnd = NULL;
pPDA[uCount].uOp = 0;
pPDA[uCount].uPlatform = uPlatform;
pPDA[uCount].uVersion = uVersion;
pPDA[uCount].uFlags = 0;
for (u=uCount+1; u<uCount+uNew+1; u++)
{
pPDA[u].bKeyring = FALSE;
pPDA[u].hmod = hmod;
pPDA[u].hwnd = NULL;
pPDA[u].uOp = u-(uCount+1);
pPDA[u].uPlatform = uPlatform;
pPDA[u].uVersion = uVersion;
pPDA[u].uFlags = 0;
}
for (; u<uCountNew; u++)
{
pPDA[u].bKeyring = FALSE;
pPDA[u].hmod = hmod;
pPDA[u].hwnd = NULL;
pPDA[u].uOp = u-(uCount+1);
pPDA[u].uPlatform = uPlatform;
pPDA[u].uVersion = uVersion;
pPDA[u].uFlags = PK_PDAWINDOWOP;
}
pPDA[uCountNew].bKeyring = FALSE;
pPDA[uCountNew].hmod = NULL;
pPDA[uCountNew].hwnd = NULL;
pPDA[uCountNew].uOp = 0;
pPDA[uCountNew].uPlatform = 0;
pPDA[uCountNew].uVersion = 0;
pPDA[uCountNew].uFlags = 0;
uCount = uCountNew;
}
}
else
bPda = FALSE;
}
if (!bPda)
FreeLibrary (hmod);
}
} while (FindNextFile (hFind, &wfd));
if (hFind)
FindClose (hFind);
return pPDA;
}
// ___________________________________________________
//
// destroy the array of PDA structs
static void
sDestroyPDAStructArray (
PGPPDASTRUCT* pPDA)
{
if (IsntNull (pPDA))
{
PGPPDASTRUCT* p = pPDA;
while (p->bKeyring && IsntNull (p->hmod))
{
FreeLibrary (p->hmod);
p++;
}
free (pPDA);
}
}
// ____________________________________
//
// Main Windows routine
INT APIENTRY
WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
PGPPrefRef prefref = kInvalidPGPPrefRef;
MSG msg;
HACCEL haccelMain, haccelDialog;
INT lWindowPosX, lWindowPosY, lWindowWidth, lWindowHeight;
DWORD dwShow;
CHAR sz[128];
HMENU hMenuMain;
BOOL bDlgMessage;
BOOL bIgnoreComctlError;
PWINDOWLISTSTRUCT pwls, pwlsNext;
HWND hwndThis;
PGPError err;
// initialize OLE
OleInitialize (NULL);
// initialize application stuff
LoadString (hInstance, IDS_COMCTLERRORSWITCH, sz, sizeof(sz));
if (strstr (lpCmdLine, sz))
bIgnoreComctlError = TRUE;
else
bIgnoreComctlError = FALSE;
if (!sInitApplication (hInstance, bIgnoreComctlError))
return 0;
// attempt to set event hooks
s_hhookMouse = SetWindowsHookEx (WH_MOUSE, sMouseHookProc,
NULL, GetCurrentThreadId());
s_hhookKeyboard = SetWindowsHookEx (WH_KEYBOARD, sKeyboardHookProc,
NULL, GetCurrentThreadId());
if (!s_hhookMouse || !s_hhookKeyboard)
return 0;
// check that admin file can be found
err = PGPclPeekClientLibPrefRefs (&prefref, NULL);
if (IsPGPError (err))
return 0;
PGPlnLicenseCheck (g_context);
if(PGPlnEnterprise())
{
PGPGetPrefBoolean (prefref,
kPGPPrefAllowKeyGeneration, &g_bKeyGenEnabled);
PGPGetPrefBoolean (prefref,
kPGPPrefAllowManualX509CertRequest, &g_bX509CertRequestEnabled);
PGPGetPrefStringBuffer (prefref,
kPGPPrefLDAPReconServer, sizeof(sz), sz);
g_bKeyReconstructionEnabled = (sz[0] != '\0');
}
// get window position and size information from registry
PGPGetPrefBoolean (prefref,
kPGPPrefDisplayMarginalValidity, &g_bExpertMode);
PGPGetPrefBoolean (prefref,
kPGPPrefMarginalIsInvalid, &g_bMarginalAsInvalid);
PKGetPrivatePrefData (&dwShow, &lWindowPosX, &lWindowPosY,
&lWindowWidth, &lWindowHeight, &g_bShowGroups,
&g_iGroupsPercent, &g_iToolHeight);
// load up the PGPpda DLL, if installed
g_pPDA = sCreatePDAStructArray ();
hMenuMain = LoadMenu (hInstance, MAKEINTRESOURCE (IDR_MENUKEYMAN));
g_hwndMain = CreateWindow (PGPKEYS_WINCLASSNAME, PGPKEYS_WINDOWTITLE,
WS_OVERLAPPEDWINDOW, lWindowPosX,
lWindowPosY, lWindowWidth,
lWindowHeight, NULL, hMenuMain, hInstance, NULL);
if (!g_hwndMain)
return 0;
ShowWindow (g_hwndMain, nCmdShow); // Show the window
UpdateWindow (g_hwndMain); // Sends WM_PAINT message
haccelMain =
LoadAccelerators (g_hinst, MAKEINTRESOURCE (IDR_KEYMANACCEL));
haccelDialog =
LoadAccelerators (g_hinst, MAKEINTRESOURCE (IDR_DIALOGACCEL));
while (GetMessage (&msg, NULL, 0,0))
{
if (s_pWindowList)
{
bDlgMessage = FALSE;
pwls = s_pWindowList;
while (pwls)
{
pwlsNext = pwls->next;
if (pwls->bDlg)
{
hwndThis = pwls->hwnd;
if (pwls->bProperties)
{
if (PropSheet_IsDialogMessage (hwndThis, &msg))
{
if (msg.message == WM_KEYDOWN)
{
if (msg.wParam == VK_ESCAPE)
{
PKDeletePropertiesWindow (hwndThis);
break;
}
}
TranslateAccelerator (
hwndThis, haccelDialog, &msg);
bDlgMessage = TRUE;
break;
}
}
else
{
if (IsDialogMessage (hwndThis, &msg))
{
TranslateAccelerator (
hwndThis, haccelDialog, &msg);
bDlgMessage = TRUE;
break;
}
}
}
pwls = pwlsNext;
}
if (bDlgMessage)
continue;
}
if (!TranslateAccelerator (g_hwndActive, haccelMain, &msg))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
sDestroyPDAStructArray (g_pPDA);
if (PGPtlsContextRefIsValid (g_tlscontext))
PGPFreeTLSContext (g_tlscontext);
// remove hook procedures
UnhookWindowsHookEx (s_hhookKeyboard);
UnhookWindowsHookEx (s_hhookMouse);
// clean out caches and shutdown sdk
PGPclCloseLibrary ();
// uninitialize OLE
OleUninitialize ();
if (g_hilKeys)
ImageList_Destroy (g_hilKeys);
if (g_hiconToken)
DestroyIcon (g_hiconToken);
if (g_hiconOpenLock)
DestroyIcon (g_hiconOpenLock);
if (g_hiconClosedLock)
DestroyIcon (g_hiconClosedLock);
return (msg.wParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -