📄 pnmsgprc.c
字号:
/*____________________________________________________________________________
Copyright (C) 1998 Network Associates, Inc.
All rights reserved.
PGPmsgprc.c - PGPnet main window message procedure
$Id: PNmsgprc.c,v 1.72.4.2 1999/06/08 16:32:07 pbj Exp $
____________________________________________________________________________*/
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "PGPnetApp.h"
#include "pgpSDKPrefs.h"
#include "PGPcl.h"
#include "pgpNetIPC.h"
#include "pgpNetLog.h"
#include "pgpNetPaths.h"
#include "PGPnetHelp.h"
#define STATUS_STATUS_PANE 0
#define STATUS_NUMSAS_PANE 1
#define STATUS_NUM_PANES 2
#define STATUS_HEIGHT 20
#define STATUS_SA_WIDTH 200
#define IDC_STATUSBAR 5001
#define SERVICETIMER_ID 4321
#define SERVICETIMER_MS 11000
#define STARTUPTIMER_ID 4322
#define STARTUPTIMER_MS 200
#define OPTIONSTIMER_ID 4323
#define OPTIONSTIMER_MS 200
extern HINSTANCE g_hinst;
extern INT g_iMinWindowWidth;
extern HWND g_hwndTab;
extern HWND g_hwndMain;
extern HWND g_hwndCurrentDlg;
extern HWND g_hwndOptions;
extern BOOL g_bAuthAccess;
extern PGPContextRef g_context;
extern INT g_iCurrentPage;
extern APPOPTIONSSTRUCT g_AOS;
extern UINT g_uReloadKeyringMsg;
extern CHAR g_szHelpFile[];
HWND g_hwndLogDlg = NULL;
HWND g_hwndStatusDlg = NULL;
HWND g_hwndHostDlg = NULL;
HWND g_hwndStatusBar = NULL;
INT g_iStatusBarHeight = 0;
INT g_iSACount = 0;
BOOL g_bGUIDisabled = FALSE;
BOOL g_bWindowShown = FALSE;
HWND g_hwndActive = NULL;
HWND g_hwndForeground = NULL;
INT g_iLogonStatus = PGPNET_LOGGEDOFF;
#define IDC_MAINTABCONTROL 41000
static DWORD aMainIds[] = { // Help IDs
IDC_MAINTABCONTROL, IDH_PNMAIN_TABS,
0,0
};
// ____________________________________
//
// paint the line to separate menu from tab control
static VOID
sPaintDividerLine (HWND hwnd)
{
HDC hdc;
RECT rc;
PAINTSTRUCT ps;
GetClientRect (hwnd, &rc);
hdc = BeginPaint (hwnd, &ps);
DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
EndPaint (hwnd, &ps);
}
// ____________________________________
//
// create the tab control and button controls
static VOID
sCreateControls (HWND hwndParent)
{
RECT rc;
TCITEM tie;
CHAR sz[256];
HFONT hfont;
INT iWidths[STATUS_NUM_PANES];
// first, create the status bar
g_hwndStatusBar = CreateStatusWindow (
WS_CHILD|WS_VISIBLE|SBS_SIZEGRIP,
"", hwndParent, IDC_STATUSBAR);
iWidths[0] = STATUS_SA_WIDTH;
iWidths[STATUS_NUM_PANES-1] = -1;
SendMessage (g_hwndStatusBar, SB_SETPARTS, STATUS_NUM_PANES,
(LPARAM)iWidths);
GetWindowRect (g_hwndStatusBar, &rc);
g_iStatusBarHeight = rc.bottom - rc.top;
// Get the dimensions of the parent window's client area, and
// create a tab control child window of that size.
GetClientRect (hwndParent, &rc);
rc.bottom -= g_iStatusBarHeight;
g_hwndTab = CreateWindow (
WC_TABCONTROL, "",
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
HOR_TAB_OFFSET, TOP_TAB_OFFSET,
rc.right-(2*HOR_TAB_OFFSET),
rc.bottom - TOP_TAB_OFFSET - BOTTOM_TAB_OFFSET,
hwndParent, (HMENU)IDC_MAINTABCONTROL, g_hinst, NULL);
if (g_hwndTab != NULL)
{
// The default tab font is UGLY, so use another
hfont = GetStockObject (DEFAULT_GUI_FONT);
SendMessage (g_hwndTab, WM_SETFONT, (WPARAM)hfont, 0);
// Add the tabs
tie.mask = TCIF_TEXT | TCIF_IMAGE;
tie.iImage = -1;
tie.pszText = sz;
LoadString (g_hinst, IDS_LOG, sz, sizeof(sz));
if (TabCtrl_InsertItem (g_hwndTab, PGPNET_LOGPAGE, &tie) == -1)
DestroyWindow (g_hwndTab);
LoadString (g_hinst, IDS_STATUS, sz, sizeof(sz));
if (TabCtrl_InsertItem (g_hwndTab, PGPNET_STATUSPAGE, &tie) == -1)
DestroyWindow (g_hwndTab);
LoadString (g_hinst, IDS_HOSTS, sz, sizeof(sz));
if (TabCtrl_InsertItem (g_hwndTab, PGPNET_HOSTPAGE, &tie) == -1)
DestroyWindow (g_hwndTab);
TabCtrl_SetCurSel (g_hwndTab, g_iCurrentPage);
g_iCurrentPage = -1;
}
// create the child dialogs
g_hwndStatusDlg = CreateDialog (g_hinst,
MAKEINTRESOURCE(IDD_STATUS), hwndParent,
PNStatusDlgProc);
g_hwndLogDlg = CreateDialog (g_hinst,
MAKEINTRESOURCE(IDD_LOG), hwndParent,
PNLogDlgProc);
g_hwndHostDlg = CreateDialogParam (g_hinst,
MAKEINTRESOURCE(IDD_HOSTOPTIONS), hwndParent,
PNHostDlgProc, (LPARAM)&g_AOS);
}
// ____________________________________
//
// size the tab control and the contained dialog
static VOID
sSizeControls (
WORD wXsize,
WORD wYsize)
{
HDWP hdwp;
RECT rc;
// set the rect to the desired coords of the tab control
SetRect (&rc,
HOR_TAB_OFFSET,
TOP_TAB_OFFSET,
wXsize - HOR_TAB_OFFSET,
wYsize - BOTTOM_TAB_OFFSET - g_iStatusBarHeight);
// size the tab control accordingly
hdwp = BeginDeferWindowPos (2);
DeferWindowPos (hdwp, g_hwndTab, NULL,
rc.left, rc.right,
rc.right - rc.left, rc.bottom - rc.top,
SWP_NOMOVE|SWP_NOZORDER);
// calculate the display area from the tab control window size
TabCtrl_AdjustRect (g_hwndTab, FALSE, &rc);
// size the contained dialog box accordingly
DeferWindowPos (hdwp,
g_hwndCurrentDlg, NULL,
rc.left, rc.top,
rc.right-rc.left, rc.bottom-rc.top, 0);
EndDeferWindowPos(hdwp);
}
// ____________________________________
//
// create and activate new dialog page
static VOID
sNewPage (HWND hwndMain, HWND hwndTab)
{
RECT rc;
INT iNewPage = TabCtrl_GetCurSel (hwndTab);
if (iNewPage == g_iCurrentPage)
return;
// hide current dialog
if (g_hwndCurrentDlg)
ShowWindow (g_hwndCurrentDlg, SW_HIDE);
// select new dialog
g_iCurrentPage = iNewPage;
switch (iNewPage) {
case PGPNET_STATUSPAGE :
g_hwndCurrentDlg = g_hwndStatusDlg;
break;
case PGPNET_LOGPAGE :
g_hwndCurrentDlg = g_hwndLogDlg;
break;
case PGPNET_HOSTPAGE :
g_hwndCurrentDlg = g_hwndHostDlg;
break;
}
// initialize the size of the dialog to fit the tab control
GetClientRect (hwndMain, &rc);
sSizeControls ((WORD)rc.right, (WORD)rc.bottom);
// visualize world peace (and the dialog)
ShowWindow (g_hwndCurrentDlg, SW_SHOW);
SendMessage (g_hwndCurrentDlg, PGPNET_M_ACTIVATEPAGE, 0, 0);
UpdateWindow (g_hwndCurrentDlg);
SetFocus (hwndTab);
}
// ____________________________________
//
// Put PGPnet application window position into registry
static VOID
sPutWindowPosToRegistry (
HWND hwnd)
{
WINDOWPLACEMENT wp;
HKEY hKey;
LONG lResult;
DWORD dw;
CHAR sz[256];
INT iX, iY, iWidth, iHeight;
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement (hwnd, &wp);
iX = wp.rcNormalPosition.left;
iY = wp.rcNormalPosition.top;
iWidth = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
iHeight = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
LoadString (g_hinst, IDS_PGPNETREGKEY, sz, sizeof(sz));
lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, sz, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw);
if (lResult == ERROR_SUCCESS) {
LoadString (g_hinst, IDS_WINDOWPOS, sz, sizeof(sz));
dw = MAKELONG (iX, iY);
RegSetValueEx (hKey, sz, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
LoadString (g_hinst, IDS_WINDOWSIZE, sz, sizeof(sz));
dw = MAKELONG (iWidth, iHeight);
RegSetValueEx (hKey, sz, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
RegCloseKey (hKey);
}
}
// ____________________________________
//
// display status bar text
UINT
PNDisplayStatusBarText (VOID)
{
CHAR sz1[64];
CHAR sz2[64];
UINT uStatus;
uStatus = PNGetServiceStatus (g_hwndMain);
switch (uStatus) {
case PGPNET_SERVICENOTRESPONDING :
LoadString (g_hinst, IDS_STATUSSERVICENOTRESPOND, sz2, sizeof(sz2));
break;
case PGPNET_SERVICENOTAVAILABLE :
LoadString (g_hinst, IDS_STATUSSERVICENOTAVAIL, sz2, sizeof(sz2));
break;
case PGPNET_DRIVERNOTAVAILABLE :
LoadString (g_hinst, IDS_STATUSDRIVERNOTAVAIL, sz2, sizeof(sz2));
break;
case PGPNET_DRIVERDISABLED :
LoadString (g_hinst, IDS_STATUSDRIVERDISABLED, sz2, sizeof(sz2));
break;
case PGPNET_DRIVERENABLED :
switch (g_iLogonStatus) {
case PGPNET_LOGGEDOFF :
LoadString (g_hinst, IDS_STATUSLOGGEDOFF, sz2, sizeof(sz2));
break;
case PGPNET_LOGGEDON :
LoadString (g_hinst, IDS_STATUSLOGGEDON, sz2, sizeof(sz2));
break;
case PGPNET_NOLOGONREQUIRED :
LoadString (g_hinst, IDS_STATUSNOLOGONREQUIRED, sz2, sizeof(sz2));
break;
case PGPNET_LOGONINPROCESS :
LoadString (g_hinst, IDS_STATUSLOGONINPROCESS, sz2, sizeof(sz2));
break;
}
break;
}
SendMessage (g_hwndStatusBar, SB_SETTEXT,
STATUS_STATUS_PANE, (LPARAM)sz2);
LoadString (g_hinst, IDS_NUMSASFORMAT, sz2, sizeof(sz2));
wsprintf (sz1, sz2, g_iSACount);
SendMessage (g_hwndStatusBar, SB_SETTEXT,
STATUS_NUMSAS_PANE, (LPARAM)sz1);
return uStatus;
}
VOID
PNSetStatusSACount (
INT iCount)
{
g_iSACount = iCount;
PNDisplayStatusBarText ();
}
VOID
PNIncStatusSACount (VOID)
{
g_iSACount++;
PNDisplayStatusBarText ();
}
VOID
PNDecStatusSACount (VOID)
{
g_iSACount--;
PNDisplayStatusBarText ();
}
// ____________________________________
//
// relay the WM_COPYDATA message to the appropriate window
static LRESULT
sRelayCopyDataMessage (
WPARAM wParam,
LPARAM lParam)
{
PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)lParam;
switch (pcds->dwData) {
case PGPNET_LOGONSTATUS :
g_iLogonStatus = *((DWORD*)(pcds->lpData));
PNDisplayStatusBarText ();
return TRUE;
case PGPNET_STATUSFULL:
case PGPNET_STATUSNEWSA :
case PGPNET_STATUSREMOVESA :
SendMessage (g_hwndStatusDlg,
PGPNET_M_INTERNALCOPYDATA, wParam, lParam);
SendMessage (g_hwndHostDlg,
PGPNET_M_UPDATELIST, wParam, lParam);
return TRUE;
case PGPNET_LOGUPDATE :
SendMessage (g_hwndLogDlg,
PGPNET_M_INTERNALCOPYDATA, wParam, lParam);
return TRUE;
}
return FALSE;
}
// ____________________________________
//
// display messagebox on basis of service/driver status
static UINT
sDisplayStatusMessageBox (
HWND hwnd)
{
CHAR sz1[128];
CHAR sz2[128];
UINT uStatus;
uStatus = PNDisplayStatusBarText ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -