Internet Explorer programming brief description (5) Call the IE hidden command (Chinese version)

xiaoxiao2021-03-06  54

Keywords: Add to favorite, IMPORT / EXPORT WIZARD, Shell DocObject View, Internet Explorer_server

1. Overview In addition to the "Solving Favorites" and "Add to Favorites" dialog, there are other dialogs that we hope to call directly through WebBrowser, such as the Import / Export dialog, is difficult to use the general method. transfer. IshelluiHelper Although the ImportExportFavorites method is provided, the result is just a dialog box for selecting files, and can only be imported / export favorites and cannot operate with the cookies.

2, an articles called "WebBrowser Customization" in MSDN, which introduces a method of customizing the WebBrowser context menu through the IDOchostuiHandler.ShowContextMenu method. The principle is to create a menu from the "shdoclc.dll" resource. After some modifications, use the TrackPopUpMenu function (note that tpm_returncmd in the flag) pop up the menu, and then send the returned Command ID to the Internet Explorer_server window to process. ... // Display Menu INT ISELECTION = :: TrackPopupment | TPM_RightButton | TPM_RETURNCMD, PPT-> X, PPT-> Y, 0, HWND, (Rect *) NULL); // Send Command ID to the shell window LRESULT LR = :: SendMessage (hwnd, wm_command, ity); ......

Ok, if you find a Command ID of all context menu, you can call it at any time? It is indeed the case.

3. Implementing the Exescope Application Resource Explorer opens "shdoclc.dll" to find the design of the context menu under the menu resources, as shown below:

What we have to do is to send these IDs to the Internet Explorer_Server window for processing. The problem is that the webbrowser is actually an OLE container. The ChtmlView we use is a more outer package. Their M_HWND member variable is not the handle of the IE window, how do you find the handle we need? Please see the picture below:

According to the subordinate relationship shown in the figure, the handle of the inner window "Internet Explorer_server" is what we need. For the sake of simplification, I used the CFINDWND class from the MSDN Magazine Senior Column Writers Paul Dilascia, which is very easy to use.

// msdn magazine - August 2003 // if this code works, IT Was Written by Paul Dilascia./////////////////////////////////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 T RUE; // 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);}}; write a function invokeieserverCommand, the call is convenient, "Internet Explorer programming (4) Add to Favorites" dialog "The last way to give in this is from here.

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

Void cmyhtmlview :: onfavaddtofav () {invokeieserverCommand (ID_IE_CONTEXTMENU_ADDFAV); // Call "Add to Favorites" dialog box} 4, Command IDs After all Command IDs, we found: 1) Not all Command IDs The above method call; 2) Not all Command IDs are processed by the "Internet Explorer_server" window; 3) Some Command IDs are processed by the previous window "shell docobject view". So we also 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 in the beginning of the article can do this: void cdemoview :: onimportExport () {invokeshellDocobjcommand (ID_IE_FILE_IMPORTEXPORT); // Call the Import / Export dialog box}

Command ID processing by "Internet Explorer_server" window: #define id_ie_contextMenu_addfav 2261 # define id_ie_contextMenu_Viewsource 2139 # define id_ie_contextMenu_refresh 6042

From the Command ID "Shell DocObject View" window processing: #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 3755, Refresh familiar TEmbeddedWB readers may have noticed ID_IE_CO NTEXTMENU_REFRESH (6042) This ID gives an onRefresh event triggered when the web page is refreshed in the TEMBedDedWB, where the key code is as follows: ... if assigned (fonRefresh) and ((ncmdid = 6041 {f5}) OR (ncmdid = 6042 {contextMenu}) or (ncmdid = 2300)) Thenbegin Fcancel: = false; fonRefresh (Self, ncmdid, fcancel); if Fcancel Then Result: = S_OK; END; ... where 6402 Is our ID_IE_CONTEXTMENU_REFRESH, 2300 is built-in refresh command, that 6041. See the figure below, or "shdoclc.dll", 6041 It turned out to be the "Refresh" menu command ID under the IE "View" menu. In actual development, we find that the refresh command directly calling WebBrowser will sometimes lead to some errors, and can be replaced with the method here.

6, Item Need to Note 1) When you call the Add to Favorites dialog with InvokeieserCommand (ID_IE_CONTEXTMENU_ADDFAV), it should be noted that the IE is received when I receive the ID_IE_CONTEXTMENU_ADDFAV command to perform the currently selected link in the web page "Add to Favorites "Operation, if there is no selected link, you add the current web page to your favorites. 2) New IE window. This is one of the browser programming, that is, from the current window to create an Internet Explorer window, completely copy the contents of the current page (including "advancement", "back" state), which can be implemented by invokeshellDocobjcommand (ID_IE_FILE_NEWWINDOW). 3) Display the version information of IE. Call InvokeShellDocobjcommand (ID_IE_HELP_ABOUTIE), as follows: 4) InvokeShellDocobjcommand (ID_IE_FILE_PRINT) The "Print" dialog box is not modal (we don't know how Microsoft's design intention, I think "Print" dialog should be modal), Method to display a modal window, please participate in my article "Use the wh_CBT Hook to display the Non-Modular Dialog box as a modal dialog."

Reference: MSDN: Webbrowser Customization

Quote Address: Internet Explorer Programming Brief (5) Call the IE Hide Command (Chinese Version)

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

New Post(0)