Internet Explorer programming Overview (5) Calling the hidden commands of Internet Explorer (Chinese Version)

Source: Internet
Author: User
Internet Explorer programming Overview (5) Calling the hidden commands of Internet Explorer (Chinese Version)

Keywords: Add to favorite, import/export wizard, shell docobject view, Internet assumer_server

1. Overview
In addition to the "Sort favorites" and "add to Favorites" dialog boxes, there are other dialog boxes that we want to call directly through webbrowser, such as the "Import/Export" dialog box, it is difficult to call a common method. Although the importexportfavorites method is provided by ishelluihelper, the result is only a dialog box for selecting files, and only the favorites can be imported/exported, rather than cookies.


2. Opportunities
In msdn, an article titled "webbrowser mizmization" describes how to customize the webbrowser context menu through the idochostuihandler. showcontextmenu method. The principle is from "shdoclc. create a menu in the DLL resource and use the trackpopupmenu function (note that tpm_returncmd is included in the flag) to bring up the menu, then, send the returned command ID to the Internet assumer_server window for processing.
......
// Display menu
Int iselection =: trackpopupmenu (hmenu,
Tpm_leftalign | tpm_rightbutton | tpm_returncmd,
PPT-> X,
PPT-> y,
0,
Hwnd,
(Rect *) null );
// Send the command ID to the shell window
Lresult LR =: sendmessage (hwnd, wm_command, iselection, null );
......

Well, if you find the command ID of all context menus, can you call it at any time? This is indeed the case.

3. Implementation
Open "shdoclc. dll" with the application resource explorer such as exclusive to find the context menu design under the menu resource, such:

All we need to do is send these IDs to the "Internet assumer_server" window for processing. The problem is that webbrowser is actually an OLE container, and the chtmlview we use is an outer encapsulation. Their m_hwnd member variables are not the handle of the IE window. How can we find the handle we need? See the following figure:

According to the subordination shown in the figure, the handle of the "Internet assumer_server" in the innermost window is what we need. To simplify the problem, I used the cfindwnd class from Paul dilascia, senior columnist of msdn magazine, which is very useful.

//////////////////////////////////////// ////////////////////////
// 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 ){
Cfindwnd * pfw = (cfindwnd *) lparam;
Hwnd = find1_wex (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
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 );
}
};

Write another function invokeieservercommand to make it easy to call. The last method provided in Internet Explorer programming Overview (4) "add to Favorites" dialog box is from here.

Void cmyhtmlview: invokeieservercommand (int nid)
{
Cfindwnd findiewnd (m_wndbrowser.m_hwnd, "Internet assumer_server ");
: Sendmessage (findiewnd. m_hwnd, wm_command, makewparam (loword (NID), 0x0), 0 );
}

Void cmyhtmlview: onfavaddtofav ()
{
Invokeieservercommand (id_ie_contextmenu_addfav); // call the "add to Favorites" dialog box
}

4. Command IDS
After trying all command IDs one by one, we found that:
1)Not all command IDS can be called using the above method;
2)Not all command IDs are processed by the "Internet assumer_server" window;
3)Some command IDs are processed by Shell docobject view in the upper-level window.
So we need to write a function.

Void cmyhtmlview: invokeshelldocobjcommand (int nid)
{
Cfindwnd findiewnd (m_wndbrowser.m_hwnd, "shell docobject View ");
: Sendmessage (findiewnd. m_hwnd, wm_command, makewparam (loword (NID), 0x0), 0 );
}

The "Import/Export" dialog box mentioned at the beginning of the article can be called as follows:

Void cdemoview: onimportexport ()
{
Invokeshelldocobjcommand (id_ie_file_importexport); // call the "Import/Export" dialog box
}

Command ID processed by the "Internet assumer_server" window:
# Define id_ie_contextmenu_addfav 2261
# Define id_ie_contextmenu_viewsource 2139
# Define id_ie_contextmenu_refresh 6042

Command ID processed 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_send?top=cut 284
# Define id_ie_help_abutie 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_net scapeuser 351
# Define id_ie_help_enhancedsecurity 375

5. Refresh
Readers familiar with tembeddedwb may have noticed the id_ie_contextmenu_refresh (6042) ID. In tembeddedwb, an onrefresh event triggered when a page is refreshed is provided. The key code is as follows:
......
If assigned (fonrefresh) and (n1_id =6041 {F5}) or (n1_id =6042{Contextmenu}) or (n1_id =2300) Then
Begin
Fcancel: = false;
Fonrefresh (self, n1_id, fcancel );
If fcancel then result: = s_ OK;
End;
......
Among them, 6402 is our id_ie_contextmenu_refresh, and 2300 is the built-in refresh command. What about 6041. See, or "shdoclc. dll". 6041 is the command ID of the "refresh" menu under the "View" menu of IE. In actual development, we found that calling the refresh command of webbrowser may sometimes cause some errors. you can replace it with the method here.

6. Notes
1)When using invokeieservercommand (id_ie_contextmenu_addfav) to call the "add to Favorites" dialog box, note that, when ie receives the id_ie_contextmenu_addfav command, it executes the "add to Favorites" Operation on the selected link on the webpage. If no link is selected, it adds the current webpage to the favorites folder.
2)Create an IE window. This is one of the difficulties in browser programming, that is, to create an Internet Explorer window from the current window and completely copy the content of the current page (including the status of "Forward" and "backward ), this can be achieved through invokeshelldocobjcommand (id_ie_file_newwindow.
3)Displays the version information of IE. Call invokeshelldocobjcommand (id_ie_help_aboutie) as follows:

4) The "print" dialog box called out by invokeshelldocobjcommand (id_ie_file_print) is non-modal (we are not quite clear about Microsoft's design intent. I think the "print" dialog box should be modal ), for more information about how to display the modal window, see "use wh_cbt hook to display the non-modal dialog box as the modal dialog box".

References:
Msdn: webbrowser Customization

Reference address: Internet Explorer programming Overview (5) Calling the hidden commands of Internet Explorer (Chinese Version)

Related Article

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.