📄 mainwndproc.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: MainWndProc.c,v 1.12 2002/10/03 04:18:05 sdas Exp $
____________________________________________________________________________*/
#include <windows.h>
#include <commctrl.h>
#include "PluginInfo.h"
#include "HookProcs.h"
#include "UIutils.h"
#include "pgpClientLib.h"
#include "pgpDebug.h"
#include "resource.h"
void CreateMainWindowGUI(HWND hDlg, PluginInfo *plugin);
void FindAndStoreMainUIElements(HWND hMainWnd, PluginInfo *lppilPlugInf);
void PreparePGPMenu(PluginInfo *lppilPlugInf);
void InitMainToolbar(PluginInfo *lppilPlugInf);
void DeInitMainToolbar(PluginInfo *lppilPlugInf);
extern int LoadAppropriateBitmaps(PluginInfo *plugin, UINT uiCommandId);
static LRESULT CALLBACK ToolbarParentWndProc(HWND hDlg,
UINT msg,
WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK MainWndProc(HWND hDlg,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
WNDPROC lpOldProc;
PluginInfo *plugin;
lpOldProc = (WNDPROC)GetProp(hDlg, "oldproc");
plugin = GetPluginInfo(hDlg);
switch(msg)
{
case WM_SETTINGCHANGE:
case WM_PALETTECHANGED:
case WM_FONTCHANGE:
case WM_SYSCOLORCHANGE:
{
LONG lResult = CommonWndProc(hDlg, msg, wParam, lParam);
//if we have inserted our stuff into the toolbar already
if(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE)
{
DeInitMainToolbar(plugin);//de-initialize/remove stuff
InitMainToolbar(plugin);
}
return lResult;
}
case WM_DESTROY:
{
KillTimer(hDlg, WATCH_TOOLBAR_TIMER);
break;
}
case WM_PARENTNOTIFY:
if (LOWORD(wParam) == WM_CREATE)
CreateMainWindowGUI(hDlg, plugin);
break;
case WM_TIMER:
if (wParam == WATCH_TOOLBAR_TIMER)
{
int nState=0;
LONG lRet=0;
//if we have found the toolbar already
if(NULL != plugin->hToolbar)
{
//get the button state of pgpkeys button
nState = SendMessage(plugin->hToolbar, TB_GETSTATE,
IDC_PGPKEYS, 0);
//if we got valid button state
if(-1 != nState)
{
//check if it is enabled
if (nState & TBSTATE_ENABLED)
return 0;//we are done
//enable the button
nState |= TBSTATE_ENABLED;
lRet=SendMessage(plugin->hToolbar, TB_SETSTATE, IDC_PGPKEYS,
MAKELONG(nState, 0));
//pgpAssert(TRUE == lRet);
}
}
return 0;
}
break;
case WM_INITMENUPOPUP:
{
int nOptions;
MENUITEMINFO menuInfo;
char szOptions[256];
char szMenu[256];
LRESULT lResult;
// For some reason, the old window proc disables the
// menu items in the PGP popup menu. We'll enable
// the items after the old proc disables them
if ((HMENU) wParam == plugin->hPGPMenu)
{
lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam,
lParam);
EnableMenuItem(plugin->hPGPMenu, IDC_PREFS,
MF_BYCOMMAND | MF_ENABLED);
EnableMenuItem(plugin->hPGPMenu, IDC_PGPKEYS,
MF_BYCOMMAND | MF_ENABLED);
return lResult;
}
else if (plugin->bOE5)
{
UIGetString(szOptions, 254, IDS_MENU_OEOPTIONS);
nOptions = GetMenuItemCount((HMENU) wParam);
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID;
menuInfo.dwTypeData = szMenu;
menuInfo.cch = 255;
GetMenuItemInfo((HMENU) wParam, nOptions - 1, TRUE,
&menuInfo);
if (!strcmp(szMenu, szOptions))
{
lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam,
lParam);
strcpy(szMenu, "&PGP");
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_SUBMENU |
MIIM_STATE;
menuInfo.fType = MFT_STRING;
menuInfo.fState = MFS_ENABLED;
menuInfo.wID = IDC_PGPMENU;
menuInfo.hSubMenu = plugin->hPGPMenu;
menuInfo.dwTypeData = szMenu;
InsertMenuItem((HMENU) wParam, nOptions, TRUE, &menuInfo);
plugin->nPGPPosition = nOptions;
return lResult;
}
else if (!strcmp(szMenu, "&PGP"))
{
lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam,
lParam);
DestroyMenu(plugin->hPGPMenu);
plugin->hPGPMenu = CreatePopupMenu();
UIGetString(szMenu, 254, IDS_MENU_PREFS);
AppendMenu(plugin->hPGPMenu, MF_STRING, IDC_PREFS,
szMenu);
UIGetString(szMenu, 254, IDS_MENU_PGPKEYS);
AppendMenu(plugin->hPGPMenu, MF_STRING, IDC_PGPKEYS,
szMenu);
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_SUBMENU | MIIM_STATE;
menuInfo.fState = MFS_ENABLED;
menuInfo.hSubMenu = plugin->hPGPMenu;
SetMenuItemInfo((HMENU) wParam, IDC_PGPMENU, FALSE,
&menuInfo);
menuInfo.fMask = MIIM_STATE;
SetMenuItemInfo(plugin->hPGPMenu, IDC_PREFS, FALSE,
&menuInfo);
SetMenuItemInfo(plugin->hPGPMenu, IDC_PGPKEYS, FALSE,
&menuInfo);
return lResult;
}
}
break;
}
}
return CommonWndProc(hDlg, msg, wParam, lParam);
}
void CreateMainWindowGUI(HWND hDlg, PluginInfo *plugin)
{
char szText[255]={0};
//find and store the main UI elements we will be playing with
FindAndStoreMainUIElements(hDlg, plugin);
//if we have not found the main menu/toolbars yet
if(!(plugin->dwInitState&PIIF_MAINUIELEMENTS_FOUND))
return;
//if we have not prepared the menu already
if(NULL == plugin->hPGPMenu)
{
//make the pgp popup menu to be put in the OE menu
PreparePGPMenu(plugin);
}
//if the menu is made and this is not OE5.
//NOTE: we dont return if things dont work out here
if((NULL != plugin->hPGPMenu) && (!plugin->bOE5))
{
if(!(plugin->dwInitState&PIIF_MENUINSERTION_DONE))
{
BOOL bRet=FALSE;
//we insert pgp menu at index 4 of the menu bar
plugin->nPGPPosition = 4;
//insert our popup menu
bRet = InsertMenu(plugin->hMainMenu, plugin->nPGPPosition,
MF_BYPOSITION | MF_STRING | MF_POPUP,
(UINT)plugin->hPGPMenu, "&PGP");
pgpAssert(TRUE == bRet);
if(TRUE == bRet)//if menu successfully inserted
{
plugin->dwInitState |= PIIF_MENUINSERTION_DONE;//remember we have already inserted
DrawMenuBar(hDlg);//draw the menu bar
}
}
}
//attempt adding our buttons to OE toolbar
InitMainToolbar(plugin);
//if we have not already started the toolbar timer
if(!(plugin->dwInitState&PIIF_TOOLBARTIMER_SET))
{
int nTimerId=-1;
//set the timer on the toolbar
nTimerId = SetTimer(hDlg, WATCH_TOOLBAR_TIMER, WATCH_TOOLBAR_TIMER_LENGTH, NULL);
pgpAssert(0 != nTimerId);
if(0 != nTimerId)//if timer was created successfully
plugin->dwInitState |= PIIF_TOOLBARTIMER_SET;//remember success
}
//if we have not already subclassed the rebar control
//and we have already inserted our tools into the toolbar
if((!(plugin->dwInitState&PIIF_REBARCTRL_SUBCLASSED)) &&
(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE))
{
//subclass the rebar control
HWND hSizableRebar=NULL, hReBar=NULL;
BOOL bRet=FALSE;
hSizableRebar = FindWindowEx(hDlg, NULL, "SizableRebar", NULL);
hReBar = FindWindowEx(hSizableRebar, NULL, "ReBarWindow32", NULL);
if(NULL != hReBar)
{
//out custom property should not already be in there
pgpAssert(NULL == GetProp(hReBar, "oldproc"));
//save away toolbar parent window proc
bRet = SetProp(hReBar, "oldproc", (HANDLE)GetWindowLong(hReBar, GWL_WNDPROC));
if(TRUE == bRet)
{
//save plugin pointer
bRet = SetProp(hReBar, PLUGIN_INFO_PROP, (HANDLE) plugin);
if(TRUE == bRet);
{
//subclass the rebar window
bRet = SetWindowLong(hReBar, GWL_WNDPROC, (DWORD)ToolbarParentWndProc);
if(bRet != 0)
plugin->dwInitState |= PIIF_REBARCTRL_SUBCLASSED;
}
}
}
}
return;
}
static LRESULT CALLBACK ToolbarParentWndProc(HWND hDlg,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
WNDPROC lpOldProc;
PluginInfo *plugin;
lpOldProc = (WNDPROC)GetProp( hDlg, "oldproc" );
plugin = GetPluginInfo(hDlg);
switch(msg)
{
case WM_NOTIFY:
{
LPNMHDR lpnm;
LONG lResult = 0;
lpnm = (LPNMHDR)lParam;
switch(lpnm->code)
{
case TBN_BEGINADJUST:
//if we have inserted our stuff into the toolbar already
if(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE)
DeInitMainToolbar(plugin);//de-initialize/remove stuff
break;
case TBN_ENDADJUST:
{
lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam,
lParam);
//if we have not inserted our stuff into the toolbar already
if(!(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE))
{
//insert our stuff as necessary
pgpAssert(-1 == plugin->nPGPKeysButton);
InitMainToolbar(plugin);
}
return lResult;
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -