Click here to Skip to main content
Email Password   helpLost your password?

IE Window Class Names

Demo

Introduction

Generally, when hosting the WebBrowser Control in our MFC application, we call ExecWB method of m_pBrowserApp (IWebBrowser2 interface) to invoke common web browser commands (zoom the browser, select all text in the browser, etc.).

We also invoke queryInterface to get an IDispatch pointer for the IOleCommandTarget interface and call its Exec method to invoke the "Find in This Page" dialog or "View Source" command. But there still exists some dialogs we can't invoke, i.e. the "Add To Favorite" dialog, the "Import/Export Wizard" dialog. Though we can invoke "AddFavorite" command and "ImportExportFavorites" command through IShellUIHelper interface, the former command results in a modeless "Add To Favorite" dialog independent from the application mainframe while the latter command results in a quite simple consequence.

This article will introduce an innovative but simple way to invoke the MODAL "Add To Favorite" dialog and MODAL "Import/Export Wizard" dialog in your own web browser.

Background

The idea comes from the IDocHostUIHandler::ShowContextMenu demo of "WebBrowser Customization" in the MSDN. The IDocHostUIHandler::ShowContextMenu demo presents us the way to manually build IE's context menu from the correlative resource file "SHDOCLC.DLL" and remove "View Source" from it. The key point of the code is after popping up the context menu, it calls SendMessage() API to send the MenuItem ID returned by TrackPopupMenu() to the "Internet Explorer_Server" window through WM_COMMAND message. So, if we get the MenuItem ID of the "Add To Favorite" command or the "Import/Export Wizard" command, we may probably solve the problems stated above.

......
// Show shortcut menu

int iSelection = ::TrackPopupMenu(hMenu,
                                  TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
                                  ppt->x,
                                  ppt->y,
                                  0,
                                  hwnd,
                                  (RECT*)NULL);
// Send selected shortcut menu item command to shell

LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL);
......

Using the code

Some command messages are handled by the "Internet Explorer_Server" window while some others are handled by its parent "Shell DocObject View" window. Therefore, the first thing is to get the Window Handle of the two windows from your CHtmlView. To simplify the resolution, I borrow the cute class CFindWnd below from Paul DiLascia.

////////////////////////////////////////////////////////////////

// MSDN Magazine -- August 2003

// If this code works, it was written by Paul DiLascia.

// If not, I don't know who wrote it.

// Compiles with Visual Studio .NET on Windows XP. Tab size=3.

//

// ---

// This class encapsulates the process of finding a window with a given class name

// as a descendant of a given window. To use it, instantiate like so:

//

//        CFindWnd fw(hwndParent,classname);

//

// fw.m_hWnd will be the HWND of the desired window, if found.

//

class CFindWnd {
private:
    //////////////////

    // This private function is used with EnumChildWindows to find the child

    // with a given class name. Returns FALSE if found (to stop enumerating).

    //

    static BOOL CALLBACK FindChildClassHwnd(HWND hwndParent, LPARAM lParam) {
        CFindWnd *pfw = (CFindWnd*)lParam;
        HWND hwnd = FindWindowEx(hwndParent, NULL, pfw->m_classname, NULL);
        if (hwnd) {
            pfw->m_hWnd = hwnd;    // found: save it

            return FALSE;            // stop enumerating

        }
        EnumChildWindows(hwndParent, FindChildClassHwnd, lParam); // recurse

        return TRUE;                // keep looking

    }

public:
    LPCSTR m_classname;            // class name to look for

    HWND m_hWnd;                    // HWND if found


    // ctor does the work--just instantiate and go

    CFindWnd(HWND hwndParent, LPCSTR classname)
        : m_hWnd(NULL), m_classname(classname)
    {
        FindChildClassHwnd(hwndParent, (LPARAM)this);
    }
};

void CDemoView::InvokeShellDocObjCommand(int nID)
{
    CFindWnd FindIEWnd( m_wndBrowser.m_hWnd, "Shell DocObject View");
    ::SendMessage( FindIEWnd.m_hWnd, WM_COMMAND, 
                        MAKEWPARAM(LOWORD(nID), 0x0), 0 );
}

void CDemoView::InvokeIEServerCommand(int nID)
{
    CFindWnd FindIEWnd( m_wndBrowser.m_hWnd, "Internet Explorer_Server");
    ::SendMessage( FindIEWnd.m_hWnd, WM_COMMAND, 
                        MAKEWPARAM(LOWORD(nID), 0x0), 0 );
}

Command IDs handled by the "Internet Explorer_Server" window:

#define ID_IE_CONTEXTMENU_ADDFAV        2261
#define ID_IE_CONTEXTMENU_VIEWSOURCE    2139
#define ID_IE_CONTEXTMENU_REFRESH       6042

Command IDs handled by the "Shell DocObject View" window:

#define ID_IE_FILE_SAVEAS               258
#define ID_IE_FILE_PAGESETUP            259
#define ID_IE_FILE_PRINT                260
#define ID_IE_FILE_NEWWINDOW            275
#define ID_IE_FILE_PRINTPREVIEW         277
#define ID_IE_FILE_NEWMAIL              279
#define ID_IE_FILE_SENDDESKTOPSHORTCUT  284
#define ID_IE_HELP_ABOUTIE              336
#define ID_IE_HELP_HELPINDEX            337
#define ID_IE_HELP_WEBTUTORIAL          338
#define ID_IE_HELP_FREESTUFF            341
#define ID_IE_HELP_PRODUCTUPDATE        342
#define ID_IE_HELP_FAQ                  343
#define ID_IE_HELP_ONLINESUPPORT        344
#define ID_IE_HELP_FEEDBACK             345
#define ID_IE_HELP_BESTPAGE             346
#define ID_IE_HELP_SEARCHWEB            347
#define ID_IE_HELP_MSHOME               348
#define ID_IE_HELP_VISITINTERNET        349
#define ID_IE_HELP_STARTPAGE            350
#define ID_IE_FILE_IMPORTEXPORT         374
#define ID_IE_FILE_ADDTRUST             376
#define ID_IE_FILE_ADDLOCAL             377
#define ID_IE_FILE_NEWPUBLISHINFO       387
#define ID_IE_FILE_NEWCORRESPONDENT     390
#define ID_IE_FILE_NEWCALL              395
#define ID_IE_HELP_NETSCAPEUSER         351
#define ID_IE_HELP_ENHANCEDSECURITY     375

The following code demonstrates how to invoke the MODAL "Add To Favorite" dialog.

void CDemoView::OnFavAddtofav()
{
    InvokeIEServerCommand(ID_IE_CONTEXTMENU_ADDFAV);
}

Points of Interest

You know, to keep working all the night, and finally you find the answer. I call this happiness!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalhow to prevent webbrowser flicker
Member 3102836
19:53 2 Sep '08  
when i navigate a url, the first time webbrowser will flicker.
i google the question somebody give the tip through the
"Internet Explorer_Server",
GeneralCannot send WM_KEYDOWN and WM_KEYUP message in "Internet Explorer_Server" window using SendMessage(...)
bk_pasa
18:53 4 Jul '07  
Hi, I am trying to input some message in AIM Triton chat window and simulate Return key to send it. The input window class is "Internet Explorer_Server". I am having trouble sending WM_KEYDOWN and WM_KEYUP message in the control using api SendMessage() while PostMessage() works well. I need to use SendMessage() instead of PostMessage() because i am trying to send the message just before the window gets closed. so i cannot let it process other window message before sending my message. Please help.

chatangel
GeneralFlicker while sizing
Euegene
4:34 27 Mar '07  
Is there some way to awoid flicker on resize, i.e. on sizing window gets drawed with white color than IE draws itself.

Thanks!

--
Eugene

GeneralApplet
colin-123
0:38 13 Sep '06  
How to view Applet in WebBrowser?

colin

GeneralWindows exlorer's command ids
kdsasi
1:51 23 Aug '06  
hi,

Excelent work!can any body tell me the command ids of Windows explorer's menus specially View & Context menus of Windows explorer or where they are defined(resource file)

Thanks

Sasi
GeneralRe: Windows exlorer's command ids
Zhang Shuo
5:06 28 Aug '06  
Open "shell32.dll" using some PE explorers like exescope, you can find the menu resources under resource ID 215, 216 and 217.
GeneralRe: Windows exlorer's command ids
kdsasi
20:55 4 Sep '06  
Hi

Thanks,I have seen this already but any way thanks for help

But I can't find ThumbNails menu item there in 215.I think it is added at runtime.I've to send command messages to all items in that menu.
Is there any way finding command id of ThumbNails menuitem??

Once again thanks a lot!!!!
GeneralMore COMMAND IDs
JaeWook Choi
9:55 16 Jun '05  
First of all, thank you for the article.

I have just found your article and surprised since I did very similar thing during last year. I wrote IE mouse gesture BHO add-in and I wanted to be able to assign and execute all those IE's menu commands from a specifc mouse gesture. From the very same article in MSDN I knew that I could send WM_COMMAND message to execute those menu command as well and figured out that all the IE menu command IDs can be found in "browselc.dll" (located in windows system folder). Open browselc.dll as resource in VC then Menu ID 267 is the IE's default menu. Most of menu command ID from the resource worked well when it was sent to either "IEFrame" or "Shell DocObject View" as WPARAM of WM_COMMAND message but some of those commands only worked for "IEFrame" (those were found to be mostly IE specific commands).

Addition to this, I also found that context menu command ID are located in "shdoclc.dll" (windows system folder as well). Menu ID 24641 is the IE's default context menu (right-click menu). Executing context menu is somewhat different from doing for regular menu item as it only worked under certain context (i.e. clicked on image). Menu 24641 has several submenus (Default, Image, Control, Anchor and so on). The most of the command ID from "Default" submenu seemed to work well for "Internet Explorer_Server" just by sending menu command ID through WM_COMMAND message. But menu IDs from the other submenu didn't work in the same manner. After quite digging into news group, I found solution. As you addressed in your article, menu command can be executed in two methods. The first is sending WM_COMMAND message to target window with specific menu command ID and the second is using IOleCommandTarget::Exec(). I was able to execute context menu directly for the image and anchor tags using IOleCommandTarget::Exec() but it was very important to focus the target html element before I invoked Exec().

So here is a portion of code I used to execute context menu command directly (and programmatically) on the specific HTMLelement(image or anchor).

CComQIPtr spCmd( spElementTarget );
if( !spCmd )
spCmd = spHTMLDoc;

if( !spCmd )
return E_FAIL;

spElementTarget->focus();

spCmd->Exec( &CGID_MSHTML, wMenuID, OLECMDEXECOPT_DODEFAULT, NULL, NULL );

spElementTarget->blur();

I hope this help someone!

Jae
General"Find in This Page"
voncris
16:08 3 Feb '05  
How exactly do you do this one? I mean, I wasn't able to find an OLECMDID for that function. I ghave the interface to the document, but I'm stuck there. Thanks!

Cristian
GeneralRe: "Find in This Page"
voncris
14:42 6 Feb '05  
OK, problem solved. For others that want to do this, the code you need is something like:

LPDISPATCH lpDisp = NULL;
lpDisp = m_browser.GetDocument();   //m_browser is your control
if (lpDisp) {
    
     LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
     lpDisp->QueryInterface(IID_IOleCommandTarget, (void** &lpOleCommandTarget);
     ASSERT(lpOleCommandTarget);

     lpDisp->Release();

     int nCmdID=1; //ID for "find"
     lpOleCommandTarget->Exec(&CGID_IWebBrowser, nCmdID, 0, NULL, NULL);

     // Release the command target
     lpOleCommandTarget->Release();


}

You should include "initguid.h" and then define:
DEFINE_GUID(CGID_IWebBrowser,0xED016940L,
            0xBD5B,0x11cf,0xBA, 0x4E,0x00,
            0xC0,0x4F,0xD7,0x08,0x16);

That's all.

Cristian
Generalexit command?
dapeng lin
2:05 6 Dec '04  
Is there a command like ID_IE_FILE_EXIT to close the
windows? thanks.
GeneralRe: exit command?
eagleboost
16:52 7 Dec '04  
All commandIDs listed in this article can be found in shdoclc.dll.
As far as I know, there's no command IDs like ID_IE_FILE_EXIT.
GeneralRe: exit command?
kwon9857
2:39 30 Oct '07  
exit = 0xA021
GeneralHi
Mr.Prakash
6:25 19 Sep '04  
Wont the command ids could possible change withnew version of IE?


I'll write a suicide note on a hundred dollar bill - Dire Straits
GeneralRe: Hi
eagleboost
7:28 19 Sep '04  
All of the IDs are the same in IE 4.x/5.x/6.x according to my tesing.
I don't think Microsoft would change them.
GeneralRe: Hi
Mr.Prakash
9:11 19 Sep '04  
humm, cool, i guess somewhere i have read that it could be very different in LongHorn, just to mention it.


I'll write a suicide note on a hundred dollar bill - Dire Straits
GeneralThanks for posting
Zuoliu Ding
19:51 17 Sep '04  
Thanks for posting. Good job, keep going! -zd
GeneralModal Print & Find dlgs
Ionut FIlip
19:31 13 Sep '04  
Hi,

Is there any way to show IE's 'Print' & 'Find' dialogs modal instead of modeless ?

Ionut
GeneralRe: Modal Print & Find dlgs
eagleboost
22:58 13 Sep '04  
It's quite simple, try this:

void CMyHtmlView::OnFilePrint()
{
AfxGetMainWnd()->EnableWindow(FALSE); //disable the main frame
InvokeShellDocObjCommand(ID_IE_FILE_PRINT);//then we get the modal dialog
}

GeneralRe: Modal Print & Find dlgs
Ionut FIlip
23:35 13 Sep '04  
That's correct, but after the Print dialog is closed the main window remains disabled ...

Any idea how to catch the 'Print dialog closed' event without ::EnumWindows(...) calls from a timer or other ulgy solutions ?
GeneralRe: Modal Print & Find dlgs
eagleboost
5:10 14 Sep '04  
On my computer, the main window becomes ENABLED after the Pring Dialog is closed. So I simply give you the code above.

The better way is to use the WH_CBT hook, like this:

static HHOOK g_hHook = NULL;
static HWND g_hWndDialog = NULL;

void CMIEView::OnFilePrint()
{
AfxGetMainWnd()->EnableWindow(FALSE);
g_hWndDialog = 0; //reset the variable
g_hHook = SetWindowsHookEx(WH_CBT, CbtProc, NULL, GetCurrentThreadId());
if (!g_hHook)
{
AfxGetMainWnd()->EnableWindow(TRUE);
return;
}
InvokeShellDocObjCommand(ID_IE_FILE_PRINT);
}

LRESULT CALLBACK CMIEView::CbtProc(int nCode, WPARAM wParam, LPARAM lParam)
{
switch (nCode)
{
case HCBT_CREATEWND:
{
HWND hWnd = (HWND)wParam;
LPCBT_CREATEWND pcbt = (LPCBT_CREATEWND)lParam;
LPCREATESTRUCT pcs = pcbt->lpcs;
if ((DWORD)pcs->lpszClass == 0x00008002)//#32770,dialog
{
if ( g_hWndDialog == 0 )
g_hWndDialog = hWnd; // Save hwnd of Print dialog
}
break;
}
case HCBT_DESTROYWND:
{
HWND hwnd = (HWND)wParam;
if (hwnd == g_hWndDialog)
{
AfxGetMainWnd()->EnableWindow(TRUE);
UnhookWindowsHookEx(g_hHook); //remove the hook
}
break;
}
}
return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}

Note: CbtProc is a static CALLBACK method of CMyHtmlView
GeneralRe: Modal Print & Find dlgs
Ionut FIlip
7:06 14 Sep '04  
eagleboost wrote: On my computer, the main window becomes ENABLED after the Pring Dialog is closed.
Interesting, I have Win2K Pro / IE 6 (for the record).

However your code from above work just fine. Thx _a lot_ !
Generalexcellent
.dan.g.
14:59 12 Sep '04  
excellent investigative work!

.dan.g.

AbstractSpoon Software
GeneralRe: excellent
eagleboost
17:27 12 Sep '04  
Thank U!Smile

eagleboost


Last Updated 12 Sep 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010