Internet Explorer programming Overview (7) Perfect "encoding" menu

Source: Internet
Author: User

Keywords: Encoding menu,Encoding menu,Shdvid_getmimecsetmenu

 


1, Overview

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 ).

 

# Define shdvid_getmimecsetmenu 27
......
Ccomptr Spct;

HR = pcmdtarget-> QueryInterface (iid_iolecommandtarget, (void **) & spct );
......
// Get the language submenu
HR = spct-> exec (& cgid_shelldocview, shdvid_getmimecsetmenu, 0, null, & var );

2 , principle

PointIolecommandtargetIntelligent pointer of an interfaceSpctYesfromIdochostuihandler: showcontextmenuParametersPcmdtargetIt can also be obtained fromHtmlThis is the key to implementation.

 

3, 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.

 


References:

《Internet ExplorerProgramming Overview (6) custom browser context menu"

 

reference address : internet Explorer programming Overview (7) Perfect "encoding" menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.