Internet Explorer programming brief description (7) Perfect "Code" menu

xiaoxiao2021-03-06  51

Keywords: encoding menu, Encoding menu, SHDVID_GETMIMECSETMENU

1 Overview

Internet Explorer has something that is not announced. Previous article "Internet Explorer programming brief description (6) Custom Browser Context Menu mentioned to get the" Encoding "menu method is to utilize the unpublished command ID of the browser's upper window" shell docObject view ". This article will introduce how to use this ID to put the "encoding" menu in our own menu (such as the drop-down menu of the "Encoding" button on the toolbar).

#define shdvid_getmimecsetmenu 27 ... ccomptr

SPCT;

HR = PCMDTARGET-> Queryinterface (IID_IOLCOMMANDTARGET, (Void **) & SPCT); ... // get the language submenuhr = SPCT-> EXEC (& CGID_SHELLDOCVIEW, SHDVID_GETMIMECSETMENU, 0, NULL, & VAR);

2, principle

The intelligent pointer pointing to the IoleCommandTarget interface is obtained from the parameter pcmdtarget from idochostuihandler :: showcontextMenu, which can also be obtained from the HTML document interface, which is the key to implementation.

3, realize

The following code demonstrates 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 *) PNOTIFYSTRUCT;

CMenu Menu;

CMenu * ppopup = 0;

CMYHTMLVIEW * PVIEW = NULL;

m_bisencodmenupopup = false; // logo variable to check "encoding" menu in the WM_INITMENUPOPUP message handler

Switch (pnmtoolbar-> item)

{

... Case ID_View_Encode: // Press the "Encod" button

{

m_bisencodmenupopupup = true;

Verify (Menu.loadMenu (iDR_Encode)); // idR_Encode is a preset "encoded" menu resource, including any plain-occupable menu

CMYHTMLVIEW = getActiveMyhtmlView (); // Check the current browser view window with current

IF (PView! = NULL)

{

LPDISPATCH LPDISPATCH = PVIEW-> gethtmlDocument (); // Get document pointers

IF (LPDISPATCH! = NULL)

{

// Get An Idispatch Pointer for the IolecommandTarget Interface.

IOLCOMMANDTARGET * PCMDTARGET = NULL;

HRESULT HR = lpdispatch-> queryinterface (IID_IOLECOMMANDTARGET, (void **) & pcmdtarget);

En (ac))

{

Variant VarencSubmenu;

:: Variantinit (& VarencSubmenu); HR = PCMDTARGET-> EXEC (& :: CGID_SHELLDOCVIEW, CMDID_GETMIMESUBMENU, OLECMDEXECOPT_DODEFAULT, NULL, & VARENCSUBMENU);

En (ac))

{

// Add "encoding" menu

Menuiteminfo miiencoding;

:: MEMSET (& miiencoding, 0, sizeof (menuiteminfo);

Miiencoding.cbsize = sizeof (menuiteminfo);

miiencoding.fmask = miim_submenu;

Miiencoding.hsubmenu = Reinterpret_cast (VARENCSUBMENU.BYREF);

Menu.setMenuItemInfo (0, & miiencoding, true); // Lose the menu for placement when designing, replaced with "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 = PPOP-> TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, RC.LEFT, RC.TOP, THIS);

m_bisencodmenupopup = false;

IF (pnmtoolbar-> item == id_view_encode)

{

// The rest of the incident gives the browser, refer to "Internet Explorer programming brief description (5) call IE hidden command (Chinese version)"

CFINDIEWND FINDIEWND (pView-> m_wndbrowser.m_hwnd, "Internet Explorer_server);

:: SendMessage (Findiewnd.m_hwnd, WM_Command, MakewParam (Lresh (LRESULT), 0X0), 0);

}

Else

{

SendMessage (WM_Command, MakewParam (Lresh (LRESULT), 0x0), 0);

}

}

* PRESULT = TBDDRET_DEFAULT;

}

Void CMAINFRAME :: OnNitMenupopup (cmenu * PpopupUpMenu, Uint Nindex, Bool Bsysmenu)

{

CmdiframeWndex :: OnNitMenupopup (PpopupMenu, Nindex, Bsysmenu);

IF (m_bisencodmenupopup)

{

/ / By default, all menu items are disabled, and this is modified here for enabled

For (uint i = 0; i

GetMenuItemcount (); i )

{

PpopupMenu-> EnableMenuItem (PpopupMenu-> GetMenuItemID (i), MF_ENABLED | MF_BYCOMMAND);

}

}

In this way, the "encoding" menu that only appears only in the browser context menu appears on our own toolbar button drop-down menu, there is no need for more processing, the change of the menu status, the encoded settings, etc., everything Teach the browser to do it yourself.

Reference:

"Internet Explorer programming (6) Custom browser context menu"

Quote address: Internet Explorer programming brief description (7) Perfect "encoding" menu

转载请注明原文地址:https://www.9cbs.com/read-115338.html

New Post(0)