Internet Explorer There are so many things that haven't been published. Previous Article Article Internet Explorer programming overview (6) the method for obtaining the "encoding" menu mentioned in the Custom browser context menu is to use the upper-Layer window " shell docobject view " unpublished commands id . This article describes how to use id put the" encoding "menu in our own menu (for example, the" encoding "button drop-down menu on the toolbar ).
PointIolecommandtargetIntelligent pointer of an interfaceSpctYesfromIdochostuihandler: showcontextmenuParametersPcmdtargetIt can also be obtained fromHtmlThis is the key to implementation.
The followingCodeDemonstrate how to place the "encoding" menu to our own encoding menu.
Void cmainframe: ondropdown (nmhdr * pnotifystruct, lresult * presult)
{
Const uint cmdid_getmimesubmenu = 27;
// Command ID for getting the Encoding submenu
Nmtoolbar * pnmtoolbar = (nmtoolbar *) ppolicystruct;
Cmenu menu;
Cmenu * ppopup = 0;
CMyhtmlView * pview = NULL;
M_bisencodmenupopup = false;//Variable used inWm_initmenupopupCheck the "encoding" menu in the message processing function
Switch (pnmtoolbar-> iItem)
{
......
Case id_view_encode:// Press"Encoding" button
{
M_bisencodmenupopup = true;
verify (menu. loadmenu (idr_encode); /// idr_encode is a preset" encoding "menu resource, menu containing any placeholder
CMyhtmlView = getactiveMyhtmlView ();//Check whether an active browser View window exists.
If (pview! = NULL)
{
Lpdispatch = pview-> gethtmldocument ();//Get document pointer
If (lpdispatch! = NULL)
{
// Get an idispatch pointer for the iolecommandtarget interface.
Iolecommandtarget * pcmdtarget = NULL;
Hresult hR = lpdispatch-> QueryInterface (iid_iolecommandtarget, (void **) & pcmdtarget );
If (succeeded (HR ))
{
Variant varencsubmenu;
: Variantinit (& varencsubmenu );
HR = pcmdtarget-> exec (&: cgid_shelldocview, cmdid_getmimesubmenu, olecmdexecopt_dodefault, null, & varencsubmenu );
If (succeeded (HR ))
{
//Add "encoding" menu
Menuiteminfo miiencoding;
: Memset (& miiencoding, 0, sizeof (menuiteminfo ));
Miiencoding. cbsize = sizeof (menuiteminfo );
Miiencoding. fmask = miim_submenu;
Miiencoding. hsubmenu = reinterpret_cast
Menu. setmenuiteminfo (0, & miiencoding, true );//Drop the placeholder menu during design and replace it with the "encoding" menu.
}
}
}
}
Ppopup = menu. getsubmenu (0 );
Break;
}
......
}
If (ppopup! = 0)
{
Crect RC;
: Sendmessage (pnmtoolbar-> HDR. hwndfrom, tb_getrect, pnmtoolbar-> iItem, (lparam) & rc );
RC. Top = RC. bottom;
: Clienttoscreen (pnmtoolbar-> HDR. hwndfrom, & rc. topleft ());
Long lresult = ppopup-> trackpopupmenu (tpm_leftalign | tpm_leftbutton | tpm_returncmd, RC. Left, RC. Top, this );
M_bisencodmenupopup = false;
If (pnmtoolbar-> iItem = id_view_encode)
{
//Other things are taught to the browser. For details, refer to Internet Explorer programming Overview (5) Calling the hidden commands of Internet Explorer (Chinese Version)
Cfindiewnd findiewnd (pview-> m_wndbrowser.m_hwnd, "Internet assumer_server ");
: Sendmessage (findiewnd. m_hwnd, wm_command, makewparam (loword (lresult), 0x0), 0 );
}
Else
{
Sendmessage (wm_command, makewparam (loword (lresult), 0x0), 0 );
}
}
* Presult = tbddret_default;
}
Void cmainframe: oninitmenupopup (cmenu * ppopupmenu, uint nindex, bool bsysmenu)
{
Cmdiframewndex: oninitmenupopup (ppopupmenu, nindex, bsysmenu );
If (m_bisencodmenupopup)
{
//By default, all menu items of "encoding" areDisabled, Modify its status hereEnabled
For (uint I = 0; I
Getmenuitemcount (); I ++)
{
Ppopupmenu-> enablemenuitem (ppopupmenu-> getmenuitemid (I), mf_enabled | mf_bycommand );
}
}
}
In this way, the "encoding" menu that appears only in the context menu of the browser appears in the drop-down menu of our toolbar buttons. No more processing is required and the menu status changes, encoding settings, etc. Everything is taught to the browser.