Herein translation
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/wbcustomization.asp
Custom browser
This tutorial provides some ways to customize the behavior and appearance of your browser control. You will see advanced host interfaces, IDochostuihandler, IDochostuihandler2, IDochostshowui, and icustomDoc. This article also discusses other custom methods, such as processing DISPID_AMBIENT_DLCONTROL in the host IDispatch implementation; and uses IhostDialoghelper.
This article is divided into the following sections
Premise and Requirements Introduction Browser Custom Architecture IdochostuiHandler IdochostuiHandler2 GetOptionKeyPath and GetOverrideKeyPath comparison Control Navigation IDOCHOSTSHOWUI Control Download and Execute IHOSTDIALOGHELPER Control New Window Display Certificate dialog (New!) Conclusion
Premise and demand
To understand and use this tutorial, you need
In-depth understanding of C and COM, familiar with Active Template Library (ATL) installed Microsoft (R) Internet Explorer (IE) 6 or higher developing environment has header files and library files for IE6 or higher; especially MSHTMHST (Translator Note: You can download the latest Internet Development SDK here at http://www.microsoft.com/msdownload/platformsdk/sdkupdate/)
Many custom features can be used in IE5 or 5.5, but there are several features that require IE6. (New!) Some features require IE6's Windows XP SP2 version. Before using a feature, you should check the reference document to get version information.
Introduction
Integrated browser controls are a powerful tool for fast software development. By becoming a browser host, you can display information and develop a user interface using Dynamic HTML (DHTML), HTML, and Extensible Markup Language (XML) that is easy to use. However, the behavior of the browser control may not be in line with your needs. For example, the default status allows users to view the source code option of the displayed page through the shortcut menu, you may need to disable or simply remove this option. You may further need to replace the default shortcut menu with your own shortcut menu.
In addition to the customization characteristics just mentioned, the advanced host features allow
The buttons and other controls on the displayed page can call the built-in method of your application to effectively expand the DHTML object model (DOM). Changing the drag and drop behavior limits the navigation of the browser, for example, is limited to the specified page / domain, or the site capture user typed and processes when needed. For example, you may need to capture Ctrl O to prevent users from opening a web page in the new IE instead of using your program to open, change the default font and display settings to control the download content, and the processing of browsers after the download is completed. For example, you might disable video playback, script execution, and open a new window when you click on the link, or the Microsoft (R) ActiveX control download and execution. Limit View Source Codes Capture Search Capture Navigation Error Replace / Modify Shortcut Menu or Disable, Replace, Customize, or Add Express Necks to change the registry to change the registry to set control and modify the browser control display message box control new window Creative way
In the following sections, we will see most, but not all of these possibilities and discuss how to implement them. Browser Custom Architecture
Introduction IdochostuiHandler, IdochostuiHander2, IDochostShowui, and ICustomDoc
The following three interfaces are custom cores of the browser control user interface: IDochostuiHandler, IDochostuiHandler2 and IDochostShowui. When you modify your browser control, these are interfaces you implement in your application. There are also some service interfaces. ICUSTOMDOC is implemented by MSHTML and provides a method to customize browser controls in some cases. IHOSTDIALOGHELPER provides a method to open the trusted dialog box, which is not marked for them (the translator's note: on the title bar) like the IE dialog.
In addition to using these interfaces, you can also do other two things. First, you can control the download by intercepting the environmental characteristics in the iDispatch implementation; secondly, you can control the creation of the window by intercepting the DISPID_NewWindow2 in the iDispatch implementation.
Translator Note: DHTML classes in MFC7, such as ChtmlView and CDHTMLDialog implement these interfaces, but for programmers using other class libraries, these interfaces may be required.
how to work
When a container provides support for ActiveX control, the browser control custom mechanism is designed to be automated. When the browser control is instantiated, if possible, it tries to find IDOchostuiHandler, IDOchostuiHandler2, and IDochostShowui implementations from the host. The browser control is found by calling a QueryInterface method of the host's IoleClientSite interface.
Translator Note: IE5.5 has a bug without querying the implementation of the IDOCHOSTUIHANDLER2 interface, which makes the host program not override the default parameters. For more information, refer to Microsoft Knowledge Base Article Q272968 BUG: IDochostuiHandler2 is not called in the browser control.
This structure is automatically working for an application that implements an IoleClient interface. By calling the browser's IoleObject :: setClientSite method to the browser control an IoleClientSite interface. A typical instantiation of the browser control may look like this:
example
/ / Omitted the error check for the sake of clear
CComptr
// Create webbrowser - Save pointer in class member variable m_spwebbrowser
CoCreateInstance (CLSID_WebBrowser, Null, Clsctx_inProc, IID_IWEBBROWSER2, (Void **) & m_spwebbrowser;
/ / Query the IoleObject interface of WebBrowser
m_spwebbrowser-> queryinterface (IID_ID_IOLOBJECT, (Void **) & SPoleObj);
/ / Set the user site
Spoleobj-> setClientSite (this);
// Local activation browser control
Rect rcclient
GetClienceRect (& rcclient);
SpoLeobj-> Doverb (Oleiverb_inplaceActivate, Null, this, 0, GetTopy (), & rcclient);
/ / Container intercept browser event registration
Atladvise (M_SpWebBrowser, getunknown (), diid_dwebbrowserevents2, & m_dwcookie;
// Navigate to the startup page
M_spwebbrowser-> navigate (l "res: //webhost.exe/startpage.htm", null, null, null, null;
However, if your app does not have an IoleClientSite interface, you have not lost all the hope. IE provides an icustomed interface so you can pass your IDOCHOSTUIHANDLER interface to your browser. You can't use the IDochostuiHandler2 and IDochostShowui interface without providing a browser control host's IoleClientSite interface.
Translator Note:
The class ColeControlContainer introduced in MFC7 and a lot of DHTML classes have made me dizzy, and I have a browser integration teaching - add macro support in the browser program to implement the implementation method of the interface. )
When the browser control gets a pointer to any of these interfaces, the method of the interface is called in the life of the browser control when appropriate. For example, when the user right-click anywhere in the client area of the browser control, your IDOCHOSTUIHANDLER :: ShowContextMenu's implementation will be called before IE displaying its default shortcut menu. This gives you an opportunity to display your own shortcut menu and cancel the shortcut menu of IE.
Translator Note: Some examples of screen shortcut menu can be found at the 9CBS document center, the URL is http://www.9cbs.net/develop/Article/18/18541.shtm
When you initialize the browser control, you can remember several key points. Your application should use oleinitialize instead of COINITIALIZE to launch COM. Oleinitialize enables scrapbook support, drag and drop, object connections and embedded (OLE) and local activation. Use OleunInInitialize to close the COM library when your app is over.
The ATL COM wizard uses Coinitialize instead of oleinitialize to open the COM library. If you use this wizard to build a runable program, you need to change the Coinitialize and CounInitialize calls to Oleinitialize and OleunInInitialize. For a Microsoft Basic Class (MFC) application, make sure your application calls AFXoleinit, which calls Oleinitialize in its initializer.
If you don't need to support drag and drop in your app, you can call iWebBBrowser2 :: registerASDROPTARGET, pass the variant_true (the translator) Drag and drop operation on the control instance.
A browser control host application also requires an implementation of IoleInplaceSite, because IoleInPlaceSite is derived from IoleWindow, an application will require an implementation of IoleWindow. You need these implementations that make your application have a window, display browser control, and handling its display settings.
The implementation of these interfaces and IoleClientSite may be minimal or absent. All methods of iOleClientSite can return E_NOTIMPL. Some IoleInPlaceSite and IoleWindow methods require an implementation to override the return value. You can view the minimum implementation of IoleInPlaceSite and IoleWindow in the sample code.
Since we have completed the preparation of initialization, let's take a look at each interface that the browser control is customized.
IDOCHOSTUIHANDALER
IdochostuiHandler has been available from IE5. It provides 15 methods. In general, some of the more important of these is IDocHostUIHandler :: GetExternal, IDocHostUIHandler :: GetHostInfo, IDocHostUIHandler :: GetOptionKeyPath, IDocHostUIHandler :: ShowContextMenu, and IDocHostUIHandler :: TranslateAccelerator. Of course, the method will depend on your application. IDOCHOSTUIHANDAL :: gethostinfo
You use idochostuihandler :: gethostinfo to tell MSHTML About your application's ability and needs. Through it, you can control a lot of things, for example:
You can disable the 3D edge of the browser. You can avoid scroll bar or change their appearance. You can disable scripts. You can define the way you double-click processing. You can disable the automatic function of your browser
IdochostuiHandler :: gethostinfo has a parameter, a pointer to the DochostuiInfo structure allocated by MSHTML. Your job is to populate information you pass to MSHTML in the structure.
There are four members of the DochostuiInfo structure. The first member is CBSIZE, which is the size of the structure. You should set it like the sample code below. The second member is DWFLAGS, which is consisting of a numerical bit from the Dochostuiflag enumeration. The third member is a value from DWDouBleClick, a value from the DochostuidBlClk enumeration. The fourth member is Pchhostcss. You can set PChostCSS to a string of a string of a global style sheet (CSS) rule applying the page displayed by the browser control. The last member of DochostuiInfo is Pchhostns. You can set the semicolon-separated namespace list string that you provide. Use this member when you are using a custom label on the page displayed in the browser control. This way you can declare a global namespace list without having to declare them on each displayed page.
Determine the use of CotaskMemalloc to assign strings for PchhostCSS or PChostns. (Translator Note: It seems that the caller releases these strings with cotaskmemfree).
example
HRESULT GETHOSTINFO (DochostuiInfo * Pinfo)
{
Wchar * szcss = l "body {background-color: #ffcccc}";
Wchar * szns = l "IE; mytags; mytags2 = 'www.microsoft.com'";
#define cchmax 256
SIZE_T CCHLENGTHCSS, CCHLENGTHSZNS;
HRESULT HR = Stringcchlengthw (SZCSS, CCHMAX, & CCHLENGTHCSS)
// TODO: Handling an error here.
OLECHAR * PCSSBuffer = (OLECHAR *) CotaskMemalloc (cchlengthcss 1) * sizeof (OLECHAR));
// TODO: The error is handled here, determines that the memory is successfully assigned.
HR = StringCchlengthw (SZNS, CCHMAX, & CCHLENGTHSZNS)
// TODO: Handling an error here.
OLECHAR * PNSBuffer = (Olechar *) CotaskMemalloc (Cchlengthszns 1) * sizeof (OLECHAR));
// TODO: The error is handled here, determines that the memory is successfully assigned.
HR = stringcchcopyw (pcssbuffer, cchlengthcss 1, szcss)
// TODO: Handling an error here. HR = StringCchcopyw (Pnsbuffer, Cchlengthszns 1, SZNS)
// TODO: Handling an error here.
Pinfo-> Cbsize = Sizeof (DochostuiInfo)
Pinfo-> dwflags = dochostuiflag_no3dborder | dochostuiflag_scroll_no | dochostuiflag_enable_forms_autocomplete;
Pinfo-> dwdoubleclick = dochostuidblclk_default;
Pinfo-> pchhostcss = pcssbuffer;
Pinfo-> Pchhostns = PNSBuffer;
Return S_OK;
}
If you don't need to tell MSHTML, you can return E_NOTIMPL in this method.
IDOCHOSTUIHANDLER :: ShowContextMenu
By implementing this method, you get the control of the shortcut menu displayed by the browser control when a user is right-click. You can return the default shortcut menu from IE to the S_OK to block IE in this method. Returns some other values, like S_false or E_NOTIMPL, allowing IE to continue to perform its default shortcut menu behavior.
If you only return S_OK in this method, you can avoid the right-click behavior of any browser control. This may be all of you in many occasions, but you can do more. Typically, you use this method to generate and display your own shortcut menu before returning S_OK. If you know the resources of the browser control displayed, how do it choose them, you can also customize the default browser control shortcut menu. Let us see how it works.
The browser control is obtained by ShDoclc.dll. It is a shortcut menu resource. This knowledge and some #define give you a chance to manipulate the browser. Let us exist that you are assumed to be satisfied with the default menu, except that you want to remove the source code item. The following code loads the browser control shortcut menu resource from SHDOCLC.DLL. Select the correct menu according to the environment, remove the menu item corresponding to the IDM_VIEWSource command, and display the menu.
example
HRESULT CBROWSERHOST :: ShowContextMenu (DWORD DWID,
Point * PPT,
IUNKNOWN * PCMDTARGET,
Idispatch * pdispobject)
{
#define idr_browse_context_menu 24641
#define idr_form_context_menu 24640
#define shdvid_getmimecsetMenu 27
#define shdvid_addMenueXtensions 53
HRESULT HR;
Hinstance hinstshdoclc;
Hwnd hwnd;
Hmenu Hmenu;
CComptr
CComptr
Menuiteminfo mii = {0};
CComvariant Var, Var1, Var2;
HR = pcmdtarget-> queryinterface (IID_IOLECOMMANDTARGET, (VOID **) & SPCT);
HR = pcmdtarget-> queryinterface (IID_IOLEWINDOW, (Void **) & SPWND);
HR = SPWND-> getWindow (& hwnd);
Hinstshdoclc = loadingLibrary (Text ("shdoclc.dll");
IF (HinstshdoClc == NULL)
{
// Load Module Error - Failure Return as soon as possible;
}
HMENU = LoadMenu (HinstshdoClc,
MakeintResource (iDR_Browse_Context_Menu);
HMENU = GetSubmenu (HMENU, DWID);
// Get the language submenu
HR = SPCT-> EXEC (& CGID_SHELLDOCVIEW, SHDVID_GETMIMECSETMENU, 0, NULL, & VAR);
mii.cbsize = sizeof (mii);
mii.fmask = miim_submenu;
Mii.hsubmenu = (hmenu) var.byref;
// Add language submenu to encoding context menu
SetMenuiteminfo (HMENU, IDM_LANGUAGE, FALSE, & MII);
// Insert the shortcut menu extension from the registry
V_vt (& var1) = VT_INT_PTR;
V_byref (& var1) = HMENU;
V_vt (& var2) = vt_i4;
V_i4 (& var2) = dwid;
HR = SPCT-> EXEC (& CGID_SHELLDOCVIEW, SHDVID_ADDMENUEXTENSIS, 0, & VAR1, & VAR2);
// Delete View source code
DeleteMenu (HMENU, IDM_VIEWSOURCE, MF_BYCOMMAND);
/ / Show shortcut menu
INT ISELECTION = :: TRACKPOPUPMENU (HMENU,
TPM_LEFTALIGN | TPM_RightButton | TPM_RETURNCMD,
PPT-> X,
PPT-> Y,
0,
HWnd,
(RECT *) NULL);
// Send the selected shortcut menu project command to the housing
LRESULT LR = :: SendMessage (HWND, WM_COMMAND, ISELECTION, NULL);
Freelibrary (Hinstshdoclc);
Return S_OK;
}
Safety Warning: Incorrectly using LoadLibrary can load the wrong dynamic link library (DLL) to threate your application security. With regard to how to load DLL information on how different versions of Microsoft Windows, refer to LoadLibrary documents.
IDOCHOSTUIHANDLER :: getExternal: Extension Document Object Model
IdochostuiHandler provides a method of expanding your own objects, methods, and features that you implement in your own application. Method (DOM). Your implementation is to provide an IDispatch interface pointer to your MSHTML, pointing to your custom COM automation object, implementing your custom objects, properties, and methods. These objects, features and methods can be accessed through an external object of the document in any page displayed by the browser control.
The implementation of this method can be very simple, assuming your IDispatch interface is on the same object that implements the idochostuihandler.
HRESULT CBROWSERHOST :: getExternal (iDispatch ** ppdispatch)
{
* ppdispatch = this;
Return S_OK;
}
As long as MSHTML has a pointer to your IDispatch, MSHTML will pass the automation method of call to your application on any external object:
Function myfunc (isomedata)
{
External.MycustomMethod ("Some Text", ISOMedata;
Script>
You can also use this technology to pass the entire object to a web page. To achieve it, create a method in your IDispatch implementation, passing the objects that you can use back to your web page.
Function myfunc (isomedata)
{
Var OcustCalendarobj;
External.getCustomCalender (OcustCalenderObj);
OcustcalerDarobj.dostuffwithit ();
.
.
.
}
Script>
An example of using ATL's IDSPATCH automation can be seen in the sample code.
Translator Note: IE also extends the browser's document object model so that you can access the current window object in the script can access the current window object by the Menuarguments property of the extension object.
IDOCHOSTUIHANDAL :: GetOptionKeypath
IDOCHOSTUIHANDAL :: GetOptionKeyPath is a very powerful tool for custom browser controls. Many browser controls display and behavior settings are stored below the HKEY_CURRENT_USER key in the registry. IDOCHOSTUIHANDAL :: GetOptionKeyPath gives you a chance to overwrite these registry settings for a particular instance of your browser control. It is implemented by letting you provide an alternative registry location, the browser control will read the registry setting here.
IdochostuiHandler :: GetOptionKeyPath is passed to you let the browser control read a string of the location of the registry setting. The browser control will look for this button under the HKEY_CURRENT_USER key.
example
HRESULT CBROWSERHOST :: GetoptionKeypath (LPolestr * Pchkey,
DWORD DWRESERVED)
{
HRESULT HR;
#define cchmax 256
SIZE_T CCHLENGTH;
IF (PCHKEY)
{
Wchar * szmykey = l "Software / mycompany / myapp";
HR = StringCchlengthw (SzmyKey, Cchmax, & Cchlength);
// TODO: Handling an error here.
* pchkey = (lpolestr) CotaskMemalloc (Cchlength 1) * Sizeof (Wchar));
IF (* PChKey)
HR = stringcchcopyw (* pchkey, cchlength 1, szkey);
// TODO: Handling an error here.
HR = (* pchkey)? s_ok: e_outofmemory;
}
Else
HR = E_INVALIDARG;
Return HR;
}
Like IdochostuiHandler :: gethostinfo, make sure you use CotaskMallalloc to allocate memory for your string.
Tell the browser control to find where your registry settings are actually the first step - the program is running a second step. Your program must set a registry key in the location telling by idochostuihandler :: getOptionKeyPath, so the browser control can be read. There are a variety of ways to complete this step. A method is to execute a registry script when the application is installed. Another method is to complete it when the application is started. Here is a setting of changing the default font, size, and color.
example
HRESULT setsomeKeys ()
{
HKEY HKEY = NULL;
HKEY HKEY2 = NULL; HKY HKEY3 = NULL;
DWORD dwdisposition = null;
Long LRESULT = NULL;
#define CBMAX 256
SIZE_T CBLENGTH;
RegcreateKeyex (HKEY_CURRENT_USER, _T ("Software / Mycompany / MyApp"),
NULL, NULL, REG_OPTION_NON_VOLATILE, Key_Set_Value,
NULL, & HKEY, & DWDISPSITION
RegcreateKeyex (HKEY, _T ("Main"), NULL, NULL, REG_OPTION_NON_VOLATILE,
Key_SET_VALUE, NULL, & HKEY2, & DWDISPOSITION;
RegSetValueex (HKEY2, _T ("Uses_DLGBOX_COLORS"), NULL, REG_SZ,
(Const byte *) _ t ("no"), sizeof (_T ("no")))
Regclosekey (HKEY2);
RegcreateKeyex (HKEY, _T ("Settings"), NULL, NULL, REG_OPTION_NON_VOLATILE,
Key_SET_VALUE, NULL, & HKEY2, & DWDISPOSITION;
RegsetValueex (HKEY2, _T ("Anchor Color"), NULL, REG_SZ,
(Const byte *) _ t ("0,255,255"), sizeof (_t ("0,255,255")))))
RegSetValueex (HKEY2, _T ("Text Color"), NULL, REG_SZ,
(Const Byte *) _ T ("255, 0, 255"), SIZEOF (_T ("255, 0, 255"))))))
Regclosekey (HKEY2);
RegcreateKeyex (HKEY, _T ("International / scripts"), NULL, NULL,
REG_OPTION_NON_VOLATILE, Key_Set_Value, NULL,
& HKEY2, & DWDISPSITION);
BYTE BDEFAULTScript = 0x3;
RegsetValueex (HKEY2, _T ("default_script"), null, reg_binary,
& BDefaultscript, Sizeof (BDefaultscript));
RegcreateKeyex (HKEY2, _T ("3"), NULL, NULL, REG_OPTION_NON_VOLATILE,
Key_SET_VALUE, NULL, & HKEY3, & DWDISPOSITION;
BYTE BSIZE = 0x4; // Value from 0 - 4. 2 is Medium.
TCHAR * SZFONTNAME = _T ("COMIC SANS MS");
Tchar * szfixedfontname = _t ("coier");
HRESULT HR = Stringcblength (SZFontName, CBMax, & Cblength);
// TODO: Handling an error here.
RegSetValueex (HKEY3, _T ("IEPFontName"), NULL, REG_SZ, (Const Byte *) SZFontName, Cblength SizeOf (Tchar));
HR = Stringcblength (SZFixedFontName, CBMax, & Cblength);
// TODO: Handling an error here.
RegSetValueex (HKEY3, _T ("IEfixedFontName"), NULL, REG_SZ,
(Const byte *) SZFixedFontName, Cblength Sizeof (tchar));
RegSetValueex (HKEY3, _T ("IEFONTSIZE"), NULL, REG_BINARY, & BSIZE, SIZEOF (BSIZE));
RegcloseKey (HKEY3);
Regclosekey (HKEY2);
RegcloseKey (HKEY);
Return S_OK;
}
IDOCHOSTUIHANDLER2
IdochostuiHandler2 has only one way, IDOchostuiHandler2 :: GetoverrideKeypath. It runs very similar to the iDochostuihandler :: getOptionKeyPath. It indicates that you modify the location of the registry set by the integrated browser set by the default registry. IdochostuiHandler2 :: GetOverrideKeyPath's implementation looks similar to the implementation of idochostuihandler :: getOptionKeyPath.
Comparison of GetOptionKeyPath and GetOverrideKeyPath
You may have not seen any difference between IDOchostuiHandler :: getOptionKeyPath and IDochostuiHandler2 :: getoverrideKeyPath. The difference between them is subtle, but it is important. If you implement IDochostuiHandler :: getOptionKeyPath, your browser control instance will ignore user settings for any IE. These settings are stored under the HKEY_CURRENT_USER / SOFTWARE / Microsoft / Internet Explorer of the registry. If you implement IDochostuihandler2 :: getOverrideKeyPath, your browser control instance will merge any user settings-font settings, menu extensions, and this - to its display and behavior.
For example, in iDochostuiHandler :: getOptionKeyPath and IDochostuiHandler2 :: getOverrideKeyPath, let's re-look at the sample code of the IDOchostuiHandler :: ShowContextMenu. Remember this line:
SPCT-> EXEC (& CGID_SHECVIEW, SHDVID_ADDMENUEXTENSIS, 0, & VAR1, & VAR2);
If you have implemented IDOchostuiHandler :: GetOptionKeyPath, because menu extension information is stored in the current user's registry information, this line does not join any custom items to the shortcut menu. If you have implemented IDOchostuiHandler2 :: GetOverrideKeyPath, this row adds any current user-defined menu extensions defined in HKEY_CURRENT_USER / MENUEXT surface, unless you express a certain location in your custom registration information. Empty or alternative menuext keys.
Control navigation
You might want to know why IdochostuiHandler :: TranslateURL is not mentioned in the IDOCHOSTUIHANDAL: as the method of implementation when you want to control the page navigation. The reason is that this method is not the most common technique for controlling navigation. This method will not control the effect of navigation unless you integrate MSHTML directly. Alternatively, by implementing IDispatch :: Invoke, dealing with DISPID_BEFORENAVIGATE2, you can control navigation. For example, the following code avoids navigation to a special URL, if the user tries to do this, display "There is no allowed navigation" error page. example
Case Dispid_beforenaviGate2:
{
CCOMBSTR URL = (* pdispparams ).rgvarg) [5] .pvarval-> bstrval;
IF (URL == "http://www.adatum.com" || URL == "http://www.adatum.com/")
{
CComptr
CComptr
SPDISP-> QueryInterface (IID_IWEBBROWSER2, (Void **) & spbroWser;
spbrowser-> stopser-> stop ();
CCOMBSTR NEWURL = "l" res: //webhost.exe/nonavigate.htm ";
Spbrowser-> NaviGate (NewURL, NULL, NULL, NULL, NULL);
(* pdispparams ).rgvarg) [0] .boolval = true;
}
Break;
}
IDOCHOSTSHOWUI
This interface gives you the control of the information dialog and help of the browser control. It works like IdochostuiHandler and IdochostuiHandler2, which can call your IDochostShowui method before the browser control displays any information or help itself, you can call your IDOCHOSTSHOWUI. This gives you a chance to prevent browser controls from displaying anything, and make you can change your own custom information or help. IdochostShowui has two methods, IDochostShowui :: ShowMessage and IDochostShowui :: showhelp.
IDOCHOSTSHOWUI :: ShowMessage
Returns the S_OK to disable the information dialog of the browser control. Any other return value, like S_FALSE or E_NOTIMPL, allowing the browser control to display its information dialog.
A good thing you can do through this method is to customize the information box title for your application, replace "Microsoft Internet Explorer". You can complete it by comparing LPSTRCAPTION and String resources used in the IE stored in Shdoclc.dll. Its ID is IDS_MESSAGE_BOX_TITLE, and the value is 2213. The following sample code demonstrates that you may need to do.
example
HRESULT CBROWSERHOST :: ShowMessage (hwnd hwnd,
LpoLestr LPSTRTEXT,
LPolestr LPSTRCAPTION,
DWORD DWTYPE,
LPolestr LPStrhelpfile,
DWORD DWHELPCONTEXT,
LRESULT * PLRESULT)
{
Uses_Conversion;
TCHAR PBUFFER [50];
// Window Title "Microsoft Internet Explorer" resource ID #define ids_message_box_title 2213
// Load SHDOCLC.DLL and IE message box title string
Hinstance hinstshdoclc = loadingLibrary (Text ("shdoclc.dll");
IF (HinstshdoClc == NULL)
{
// Load module error - failure to fail safely
Return;
}
LoadString (HinstshdoClc, IDS_MESSAGE_BOX_TILE, PBUFFER, 50);
// Compare IE message box header strings and lpstrcaption
// If you do it, replace it with a custom title
IF (_TCSCMP (OLE2T (LPSTRCAPTION), PBUFFER == 0)
LPSTRCAPTION = L "Custom caption";
// Create your own message box and display
* PLRESULT = MessageBox (OLE2T (LPSTRTEXT), OLE2T (LPSTRCAPTION), DWTYPE
// Uninstall Shdoclc.dll and return
Freelibrary (Hinstshdoclc);
Return S_OK;
}
Safety Warning: Incorrectly using LoadLibrary can load the wrong dynamic link library (DLL) to threate your application security. With regard to how to load DLL information on how different versions of Microsoft Windows, refer to LoadLibrary documents.
IDOCHOSTSHOWUI :: Showhelp
This method is called when IE needs to display help. For example, when the F1 button is pressed, and how the work mode and idochostshowui: showMessage are similar. Returns the help of S_OK override the IE, or another HRESULT value makes IE to perform its own help.
Control download and execution
The browser control gives you its download, display settings, and execute control. In order to get these controls, you implement your host's IDispatch interface, making it processed by DISPID_AMBIENT_DLCONTROL. When the browser control is instantiated, it will call your idispatch :: Invoke with this ID. Set PVARRESULT to a combination of one bit and a combination of the following identity, indicating your configuration.
DLCTL_DLIMAGES, DLCTL_VIDEOS and DLCTL_BGSOUNDS: If these identities are set, the images, video, and background music will be downloaded and displayed or played from the server, otherwise it will not be downloaded and displayed. DLCTL_NO_Scripts and DLCTL_NO_JAVA: Scripts and Java makers will not be run. DLCTL_NO_DLACTIVEXCTLS and DLCTL_NO_RUNACTIVEXCTLS: ActiveX control will not be downloaded or run. DLCTL_DOWNLOADONLY: The web will only be downloaded, not displayed. DLCTL_NO_FRAMEDOWNLOAD: The browser control will download and parse the frameset page, but will not download and parse the separate frame in the frameset. DLCTL_RESYNCHRONIZE and DLCTL_PRAGMA_NO_CACHE: These markers cause the Internet buffer to refresh. By DLCTL_RESYNCHRONIZE, the server will be requested to update the status. If the server indicates that the cache information is the latest, the cache file will be used. By DLCTL_PRAGMA_NO_CACHE, files will be re-downloaded from the server regardless of the update status of the file. DLCTL_NO_BEHAVIORS: Behavior is not downloaded and disabled in the file. DLCTL_NO_METACHARSET_HTML: Ignore the character set indicated in the META element. DLCTL_URL_ENCODING_DISABLE_UTF8 and DLCTL_URL_ENCODING_ENABLE_UTF8: functions of these signs are similar IDocHostUIHandler :: DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 and DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 sign GetHostInfo used. Differently, the DOCHOSTUIFLLAG flag will only be checked when the browser control is initialized. The download logo here is now checked whenever the browser control is required to run a download. DLCTL_NO_CLIENTPULL: Do not run the client (Translator Note: For example, "default behavior). DLCTL_SILENT: No user interface is displayed during download. DLCTL_FORCEOFFLINE: The browser control is always operated in offline mode. DLCTL_OfflineIfnotConnected and DLCTL_Offline: These flags are the same. If you are not connected to your Internet, the browser control will operate in offline mode. The value of Dispid_Ambient_dlControl and flag is defined in mshtmdid.h.
Initially, the PVARRESULT parameter pointed to the Variant parameter is a VARIANT type. You must set it for any valid settings for the VT_I4 type. You can store the logo value in the LVAL member of Variant.
Most of the logo values have a negative effect, that is, they avoid behavior to occur properly. For example, if you don't customize the browser control behavior, then the script will be executed. But if you set a DLCTL_Noscripts flag, the script will not run in the instance of the control. However, the role of three markers - DLCTL_DLIMAGES, DLCTL_VIDEOS and DLCTL_BGSOUNDs are just the opposite. You must all set a flag so that the browser control performs processing about images, videos, and sounds with its default behavior.
The following example code allows a browser control instance to download and display images and videos, but do not process background music because DLCTL_BGSOUNDs are not explicitly set. The script running on the page displayed by the browser control is disabled.
example
STDMETHODIMP CATLBRCON :: Invoke (Dispid Dispidmember, Refiid RIID, LCID LCID, Word WFLAGS,
Dispparams * pdispparams,
Variant * PvarResult,
Excepinfo * pexcepinfo,
Uint * puargerr)
{
Switch (Dispidmember)
{
Case Dispid_Ambient_dlControl:
Pvarresult-> vt = vt_i4;
PvarResult-> LVAL = DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_NO_Scripts;
Break;
DEFAULT:
Return DISP_E_MEMBERNOTFOUND;
}
Return S_OK;
}
IhostDialoghelper
IhostDialoghelper is an interface that you can create dialogs based on your hobby. This interface has a method, IhostDialoghelper :: Showhtmldialog. This method provides services like a functional Showhtmldialog, but it is easier to use.
In order to use IhostDialoghelper, you generate dialog assisted objects from the header. Here is what you create it using CocreateInstance. Interfaces and IDs are defined in MSHTMHST.H.
example
IhostDialoghelper * phdh;
IMONIKER * PURLMONIKER;
BSTR BSTROPTIONS = SYSALLOCSTRING (L "DIALOGHEIGHT: 30; DialogWidth: 40");
BSTR bstrpath = sysallocstring (l "c: / dimig.htm");
Createurlmoniker (NULL, BSTRPATH, & PURLMONIKER);
// Create a dialog assisted object
CoCreateInstance (CLSID_HostDialoghelper,
NULL,
CLSCTX_INPROC,
IID_IHOSTDIALOGHELPER,
(void **) & phDh);
// Call Showhtmldialog Creative Dialog
PhDh-> showhtmldialog (NULL,
PURLMONIKER,
NULL,
BSTROPTIONS,
NULL,
NULL);
/ / Release Resources
Sysfreeestring (BSTRPATH);
Sysfreestring (BSTROPTIONS);
PURLMONIKER-> Release ();
phDh-> release ();
Translator Note: If you want to use the dialog to get user input, you may need to pass two parameters to showhtmldialog. See the Platform SDK documentation about the description of the showhtmldialog parameter. Showhtmldialog and Showhtmldialogex seem to have always been the two functions exported by mshtml.dll, and Microsoft encapsulates it as an interface, which may be prepared for future compatibility.
Control new window
An important way to control browser controls is to control navigation. You have already seen how to intercept DISPID_BEFORENAVIGATE2 in iDispatch :: Invoke to implement the navigation location of your browser control. Another important aspect of navigation is to control navigation, especially when opening new windows. Let us explain that the user right-click a link, select "Open in a new window" or a page contains a script like this:
WINDOW.OPEN ("www.msn.com")
By default, the browser control is to display the web page by opening a new instance of the IE. This may be just your application needs, but it may not be. Maybe you need to open all links in the current browser control instance, or you will be a new instance of your browser control under your control - open links with your user interface and your trademark. You can intercept an event in your IDispatch implementation - DwebBrowseRevents2 :: newWindow2 - to control it. Your control needs to connect to DwebBrowseRevents2 connection points to intercept this event.
After you connect to DwebBrowserevents2, you implement your idispatch :: invoke to process DISPID_NEWWINDOW2. In the IDispatch :: Invoke function call for Dispid_Newindow2, array PDispparams contains two parameters. The first, the serial number is zero, is a large value of a Boolean, telling the browser control to cancel the new window. Default it is a false value, and a new window will be opened. If you want to completely cancel the creation of a new window, set the flag to true value.
The parameter of the serial number is a pointer for an IDispatch interface. You can set this parameter to the IDispatch you have created by the browser control. When you pass this Idispatch, MSHTML will open the link using the control you give.
Translator Note: This event is supported by the DHTML class and class wizard in the MFC. For more information, see MSJ's article in July 1998 Keeping An Eye On Your Browser by Monitoring Internet Explorer 4.0 Events, and Microsoft Knowledge Base Articles Q184876 HOWTO: Use The WebBrowser Control NewWindow2 Event
Show a certificate dialog (New!)
In IE6 or higher, you can display the certificate dialog when you browse a legal security hypertext Transfer Protocol (HTTPS) site. This is the same as the lock icon effect of the user clicked in IE. You can display your own icon via dwebbrowserevents2 :: setsecurelockicon event.
#DEfine SHDVID_SSLSTATUS 33
IOLCOMMANDTARGET * PCT;
IF (successded (pwebbrowser2-> queryinterface (IID_IOLECOMMANDTARGET)))))
{
PCT-> EXEC (& CGID_SHELDOCVIEW, SHDVID_SSLSTATUS, 0, NULL, NULL);
PCT-> Release ();
}
Information bar (new!)
Internet Explorer 6 in Windows XP SP2 introduces a new secure user interface element called the information bar. When a particular operation is blocked, the information column displays a user interface element to the user. Special, it will be displayed when the following operation is blocked.
Pop-up window initialization (see pop-up window killer) file download (SEE file download restriction) Install ActiveX control (SEE ActiveX restriction) ActiveX control security prompt reason is that user security settings or control is not marked as script security. Document extension and multi-purpose Internet Mail Extension Type (MIME) unconformity (see MIME Processing) Network Protocol Locking Content (see Agreement)
The information bar is one of the security features introduced in Internet Explorer 6 in Windows XP SP2. Like other security characteristics, you can control: (Feature_SecurityBand) by a registry. By default IE (IExPlorer.exe) and Windows Explorer (Explorer.exe) under this security feature control. The following shows the registry key and enabled procedure:
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) SOFTWARE
Microsoft
Internet Explorer
Main
FeatureControl
Feature_securityBand
IExplorer.exe
= 0x00000001
Explorer.exe
= 0x00000001
Process Name.exe
=
0x00000001
This feature_securityband security feature control affects whether IE is displayed, and the information bar prompts users when an operation is blocked. It does not control the operation of the operation.
A program for an integrated browser control can enable the information bar by adding its process to this registry key. This can be executed at runtime by calling the CointernetSetFeatureNableD function. If an application is not under this security feature control, the behavior of the browser control is the same as the Internet Explorer 6 SP1B.
There is no way to access this feature through scripts.
Applications under Feature_SecurityBand and related security characteristics can use the information bar application programming interface (API) to customize the displayed user interface when a URL operation is disabled. Introduce a lot of new OLECMDID commands for the information bar. The third is a CGID_DOCHOSTCOMMANDHANDLER group. The host application should implement an IOLCMMANDTARGET in the same object implemented in their IDOchostuiHandler to accept the IOLCMMANDTARGET :: EXEC call from the browser control.
OLECMDID_PAGEATIONBLOCKED OLECMDID_PAGEACMDIDID_FOCUSVIEWCONTROLS
The host application can use the following two new OLECMDID commands to perform the iOleCommandTarget :: EXECMANDTARGET :: EXECMANDTARGET :: Exec call.
OLECMDID_FOCUSVIEWCONTROLSQUERY OLECMDID_SHOWPAGEAANUUNU
This example is used
IWebBrowser2 :: execwb is executed
OLECMDID_SHOWPAGEAANU command.
POINT PT = {0};
GetCursorpos (& PT);
CCOMVARIANT VARHWND ((long) hwnd;
Ccomvariant VARX (PT.X);
CComvariant Vary (Pt.y);
SafeArray * psa = SafeArrayCreateVector (VT_VARIANT, 0, 3);
Long LINDEX = 0;
SafeArrayPutelement (PSA, & Lindex, & Varhwnd);
LINDEX ;
SafearrayPuteElement (PSA, & LINDEX, & VARX);
LINDEX ;
SafeArrayPuteElement (PSA, & Lindex, & Vary);
Ccomvariant varargin;
V_vt (& varargin) = vt_ARRAY | VT_I4;
V_array (& varargin) = PSA;
PBROWSER-> EXECWB (Olecmdid_ShowPageActionMenu, (Olecmdexecopt) DWPAGEACTIONFLAGS, & VARARGIN, NULL;
In addition, applications can implement IINTERNETSECURITYMANAGER to overload the default security zone settings, see Creating a custom URL Security Manager for more information.
in conclusion