📄 mainwndproc.c
字号:
default:
break;
}
}
break;
default:
break;
}
return CallWindowProc(lpOldProc, hDlg, msg, wParam, lParam);
}
void FindAndStoreMainUIElements(HWND hMainWnd, PluginInfo *lppilPlugInf)
{
HWND hSizableRebar=NULL;
HWND hReBar=NULL;
LONG lResult=0;
//check parameters - anything wrong bail out
pgpAssert(NULL != hMainWnd);
pgpAssert((NULL != lppilPlugInf) && (NULL != lppilPlugInf->hwndCurrent));//hwndCurrent should be set
if((NULL == hMainWnd) || (NULL == lppilPlugInf) || (NULL == lppilPlugInf->hwndCurrent))
return;
pgpAssert(hMainWnd == lppilPlugInf->hwndCurrent);
//if we have already found the main menu/toolbars
if(lppilPlugInf->dwInitState&PIIF_MAINUIELEMENTS_FOUND)
return;//bail out
//let's take care of the menu if we need that in this version of OE
if((!lppilPlugInf->bOE5) && (NULL == lppilPlugInf->hMainMenu))
{
lppilPlugInf->hMainMenu = GetMenu(hMainWnd);
if(NULL == lppilPlugInf->hMainMenu)
return;//could not find the main menu
}
//let's take care of the hToolbar member of plugininfo
hSizableRebar = FindWindowEx(hMainWnd, NULL, "SizableRebar", NULL);
if(NULL == hSizableRebar)
return;//perhaps called too early in OE's initialization
hReBar = FindWindowEx(hSizableRebar, NULL, "ReBarWindow32", NULL);
if(NULL == hReBar)
return;//perhaps called too early in OE's initialization
if(NULL == lppilPlugInf->hToolbar)//if we have not filled that member yet
{
lppilPlugInf->hToolbar = FindWindowEx(hReBar, NULL, "ToolbarWindow32", NULL);
if(NULL == lppilPlugInf->hToolbar)
return;//perhaps called too early in OE's initialization
if(lppilPlugInf->bOE5)
{
//now let's take care of hMenuToolbar member of plugininfo if we need
//that in this version of OE. NOTE: even if lppilPlugInf->hToolbar may
//not be the toolbar we are looking for the next child window in z-order
//happens to be always the menu bar (thank god !!)
if(lppilPlugInf->bOE5 && (NULL == lppilPlugInf->hMenuToolbar))
{
pgpAssert(NULL != lppilPlugInf->hToolbar);
lppilPlugInf->hMenuToolbar = FindWindowEx(hReBar, lppilPlugInf->hToolbar, "ToolbarWindow32", NULL);
if(NULL == lppilPlugInf->hMenuToolbar)
return;//we will have to try to find it again some other time
//TODO:we need some way of distinguishing between the toolbars and the menu bar
//pgpAssert(-1 == SendMessage(lppilPlugInf->hMenuToolbar, TB_BUTTONCOUNT, 0, 0));
}
//if there were other child windows found under our toolbar
if((0 == SendMessage(lppilPlugInf->hToolbar, TB_GETIMAGELIST, 0, 0)) ||
(NULL != FindWindowEx(lppilPlugInf->hToolbar, NULL, NULL, NULL)))
{
//probably the handle we got for toolbar is actually the view bar
//check for other windows of the toolbar class if any under the rebar.
//the first childless toolbar window different from the menutoolbar
//is our best guess for the toolbar we are looking for
//NOTE: this is only done on OE5 or higher
//find the next toolbar child
HWND hPossToolbar = FindWindowEx(hReBar, lppilPlugInf->hToolbar, "ToolbarWindow32", NULL);
//until the child is not null
while(NULL != hPossToolbar)
{
//if the toolbar is not being thought of as a menutoolbar
if(hPossToolbar != lppilPlugInf->hMenuToolbar)
{
//if the toolbar has no children
if((NULL == FindWindowEx(hPossToolbar, NULL, NULL, NULL)) &&
((0 == SendMessage(lppilPlugInf->hToolbar, TB_GETIMAGELIST, 0, 0))))//and has an imagelist
break;//we have found it !
}
//go to next child
hPossToolbar = FindWindowEx(hReBar, hPossToolbar, "ToolbarWindow32", NULL);
}
//if we got out of loop because we found a toolbar with no child
lppilPlugInf->hToolbar = hPossToolbar;//this is our best effort guess for now
if(NULL == lppilPlugInf->hToolbar)
return; //could not find a toolbar to attach UI elements to
}
}
if(NULL != lppilPlugInf->hToolbar)
PGPOeTrace("Found toolbar handle %#x \n", lppilPlugInf->hToolbar);
}
//now let's take care of hStatusBar member of plugininfo
if(NULL == lppilPlugInf->hStatusBar)
{
lppilPlugInf->hStatusBar = FindWindowEx(hMainWnd, NULL, "msctls_statusbar32", NULL);
//NOTE we do not consider this abcolutely necessary
}
//control comes here only if all the things we need are filled up in plugininfo
//so we remember that we have already reached this stage of plugin initialization
lppilPlugInf->dwInitState |= PIIF_MAINUIELEMENTS_FOUND;
}
void InitMainToolbar(PluginInfo *lppilPlugInf)
{
int nIndex = -1;
int nPGPkeysSTR = -1;
int nPGPkeysBMP = -1;
LONG lResult = 0;
TBBUTTON tbb[1]={0};
char szText[255] = {0};
HINSTANCE hInst = NULL;
int nX = -1;
//check parameters
if(NULL == lppilPlugInf)
return;
//if main UI elements have not yet been found/partially found
if(!(lppilPlugInf->dwInitState & PIIF_MAINUIELEMENTS_FOUND))
{
//find and store the main UI elements we will be playing with
FindAndStoreMainUIElements(lppilPlugInf->hwndCurrent, lppilPlugInf);
//if we have not found all the main menu/toolbars stuff
if(!(lppilPlugInf->dwInitState&PIIF_MAINUIELEMENTS_FOUND))
return;
}
//we should be having all UI elements needed from this point onwards
pgpAssert(lppilPlugInf->dwInitState & PIIF_MAINUIELEMENTS_FOUND);
//we should not have inserted ourselves already
//pgpAssert(!(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE));
if(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE)
return;//we have already inserted ourselves to the main toolbar
//we should not be there already. alternately OE could not be using
//our command id for itself
pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
IDC_PGPKEYS, 0));
//get the number of buttons in the toolbar currently
//lResult = SendMessage(lppilPlugInf->hToolbar, TB_BUTTONCOUNT, 0, 0);
//if (lResult < 2)//if less than 2
// return;//we will try again later ?
//load and add the appropriate bitmaps to the toolbar for pgp keys button
nPGPkeysBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_PGPKEYS);
pgpAssert(-1 != nPGPkeysBMP);
if(-1 == nPGPkeysBMP)
return;//some failure in loading bitmaps
pgpAssert(-1 == lppilPlugInf->nPGPKeysImage);
lppilPlugInf->nPGPKeysImage = nPGPkeysBMP;
//if we have not already added the string for pgpkeys button
if(-1 == lppilPlugInf->nPGPKeysString)
{
UIGetString(szText, 254, IDS_TOOLTIP_PGPKEYS);
nPGPkeysSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0,
(LPARAM) szText);
pgpAssert(-1 != nPGPkeysSTR);
pgpAssert(-1 == lppilPlugInf->nPGPKeysString);
lppilPlugInf->nPGPKeysString = nPGPkeysSTR;
}
//we must send TB_BUTTONSTRUCTSIZE before sending TB_ADDBITMAP
//or TB_ADDBUTTONS message NOTE: this message has side effects
SendMessage(lppilPlugInf->hToolbar, TB_BUTTONSTRUCTSIZE,
(WPARAM)sizeof(TBBUTTON), 0);
tbb[0].iBitmap = nPGPkeysBMP;
tbb[0].idCommand = IDC_PGPKEYS;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0;
tbb[0].iString = lppilPlugInf->nPGPKeysString;
lResult = SendMessage(lppilPlugInf->hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbb);
pgpAssert(TRUE == lResult);
if(TRUE == lResult)//if we successfully added the button
{
//get the command id for our button
lppilPlugInf->nPGPKeysButton = SendMessage(lppilPlugInf->hToolbar,
TB_COMMANDTOINDEX, IDC_PGPKEYS, 0);
pgpAssert(-1 != lppilPlugInf->nPGPKeysButton);
if(-1 != lppilPlugInf->nPGPKeysButton)
lppilPlugInf->dwInitState |= PIIF_TOOLSINSERTION_DONE;//all success
}
return;
}
void DeInitMainToolbar(PluginInfo *lppilPlugInf)
{
HIMAGELIST hTbImgList = NULL;
BOOL bRet = FALSE;
BOOL bForceRedetectTbar = FALSE;
INT iIndex = -1;
LONG lResult = 0;
//if we have not inserted our stuff into the toolbar already
if(!(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE))
return;
pgpAssert(-1 != lppilPlugInf->nPGPKeysButton);
pgpAssert(NULL != lppilPlugInf->hToolbar);
//REMOVE THE BUTTON
//find the button index for pgp keys button
iIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
IDC_PGPKEYS, 0);
pgpAssert(-1 != iIndex);
if(-1 != iIndex)
{
//the button index should be the same as we know already
pgpAssert(iIndex == lppilPlugInf->nPGPKeysButton);
//delete the button
lResult = SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, iIndex, 0);
pgpAssert(TRUE == lResult);
if(FALSE == lResult)//if we could not delete the button
bForceRedetectTbar = TRUE;//force a redetection of toolbar stuff
//does not matter if we could delete or not. forget the button index nevertheless
lppilPlugInf->nPGPKeysButton = -1;
}
//REMOVE BITMAP INSERTIONS FOR THE BUTTONS
pgpAssert(-1 != lppilPlugInf->nPGPKeysImage);
if( -1 != lppilPlugInf->nPGPKeysImage)
{
//remove it from the hot imagelist
hTbImgList = (HIMAGELIST) SendMessage(lppilPlugInf->hToolbar,
TB_GETHOTIMAGELIST, 0, 0);
pgpAssert(NULL != hTbImgList);
if(NULL == hTbImgList)//if we could not find an imagelist
{
bForceRedetectTbar = TRUE;//force a redetection of toolbar stuff
}
else//we found the imagelist
{
bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nPGPKeysImage);
pgpAssert(0 != bRet);
}
//remove it from the normal imagelist
hTbImgList = (HIMAGELIST) SendMessage(lppilPlugInf->hToolbar,
TB_GETIMAGELIST, 0, 0);
pgpAssert(NULL != hTbImgList);
if(NULL == hTbImgList)//if we could not find an imagelist
{
bForceRedetectTbar = TRUE;//force a redetection of toolbar stuff
}
else//we found the imagelist
{
bRet = ImageList_Remove(hTbImgList, lppilPlugInf->nPGPKeysImage);
pgpAssert(0 != bRet);
}
lppilPlugInf->nPGPKeysImage = -1;//cant do much if anything fails to delete
}
//REMOVE THE STRING ADDED TO TOOLBAR
//there is currently no way to do this. TODO: change stuff so that we
//do not need to have this side effect
//if we are supposed to redetect toolbar stuff
if(TRUE == bForceRedetectTbar)
{
PGPOeTrace("Forgetting toolbar handle %#x \n", lppilPlugInf->hToolbar);
lppilPlugInf->hToolbar = NULL; //forget current toolbar handle
lppilPlugInf->dwInitState &= (~PIIF_MAINUIELEMENTS_FOUND);//mark state appropriately
}
//state maintenance - toolbar insertion is not done anymore
lppilPlugInf->dwInitState &= (~PIIF_TOOLSINSERTION_DONE);
}
void PreparePGPMenu(PluginInfo *lppilPlugInf)
{
char szText[255]={0};
pgpAssert(NULL != lppilPlugInf);
pgpAssert(NULL == lppilPlugInf->hPGPMenu);
//if invalid params or menu already made
if((NULL == lppilPlugInf) || (NULL != lppilPlugInf->hPGPMenu))
return;//bail
lppilPlugInf->hPGPMenu = CreatePopupMenu();
if(NULL == lppilPlugInf->hPGPMenu)
return;
UIGetString(szText, 254, IDS_MENU_PREFS);
AppendMenu(lppilPlugInf->hPGPMenu, MF_STRING, IDC_PREFS, szText);
UIGetString(szText, 254, IDS_MENU_PGPKEYS);
AppendMenu(lppilPlugInf->hPGPMenu, MF_STRING, IDC_PGPKEYS, szText);
return;//all success
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -