Since the end of last year a tricky interface, began to study using the Web interface to now about 1 years, this year is not confined to the implementation level, nor has been studying this problem, there are many problems is not a problem, but I did not think clearly or thought did not let go. For an interface developer, presumably pull the dialog box not less than 100, bored needless to say, just the size of the dialog box changes cause the control to change all need some effort, and the interface is beautiful, the interface style unified, flexible interface ..., headache. Load the bitmap in the dialog box, load gif, hyperlink ..., ah, can't control it! In consideration of the far point, now. NET3.0 technology has completely broken the boundaries of applications and desktops, and our interface HTML resources can be placed entirely on a Web site, so that the interface is completely dynamic.
In the meantime wrote 2 articles in this aspect, based on VC6 realization, detours is very big. In vc7.1, Vc8 inside to be a lot simpler, mainly to make a few of the previously open class public, the most important thing is to add a virtual function in CWnd Createcontrolsite so that there is a chance to change the control site to modify the control behavior. At the MFC class level, CHtmlView and CDHtmlDialog provide developers with a range of infrastructure to create WEBGUI, including event mechanisms, window behavior, and interfaces for manipulating HTML documents. It was easy for us to implement WebGui on this basis, but still puzzled me for a long time, the manager also urged me several times I have not been willing to decide the final plan. In my head I've been thinking about whether the application is completely manipulating HTML documents or HTML access to the app to get information, which is actually the mode of communication between them. It was until yesterday that I set the plan. The application manipulates HTML elements through the IWebBrowser2 interface, and HTML responds to its own events through VBScript, JavaScript scripts, and accesses the app. The main consideration is the natural flow of communication, and I used to completely control HTML elements through the application instructions, resulting in parsing the HTML document, thankless. Let's start with my thoughts:
Write a DLL, encapsulate CDHtmlDialog, and provide a dialog box that resembles an HTML container, with the ability to load HTML pages and create COM components that echo the HTML. It does not itself contain code related to app functionality, the part of the app is the HTML page and for the COM functional component. The CDHtmlDialog needs to be properly adapted to suit its goals:
First derive a class Chtmlcontainerdlg from CDHtmlDialog, by default, a Web page resource is generated, which is loaded when the dialog is created, and what we need is a container instead of a specific dialog box, so delete the page resource, To modify the dialog header file:
enum {IDD = Idd_htmlcontainerdlg, IDH = 0}; Here we change the IDH to 0 because we have deleted the Web resources. However, when the dialog box is created, the resource is loaded, and in CDHtmlDialog's OnInitDialog function we can see:
if (M_NHTMLRESID)
LoadFromResource (M_NHTMLRESID);
else if (M_SZHTMLRESID)
LoadFromResource (M_SZHTMLRESID);
else if (M_strcurrenturl)
Navigate (m_strcurrenturl); The result is that when the dialog box appears, a page loading an invalid address appears, and the page cannot be opened, in order to avoid this problem, the OnInitDialog function needs to be overloaded. In fact, it is to copy the MFC code and then remove the above code is OK, forcing the page is not loaded. So in order to load the specified page, a function is required:
void Chtmlcontainerdlg::sethtmlandcom (CString strurl, CString Strprog)
{
HRESULT hr = NOERROR;
m_strURL = strURL;
hr = M_spcomdisp.cocreateinstance (Strprog);
if (FAILED (HR))
{
TRACE (_t ("Some error when create COM object\n"));
}
Setexternaldispatch (M_SPCOMDISP);
Specify the URL of the HTML and the ProgID of the corresponding feature component, so that the COM component can be accessed through script window.external in the Web page.
This can load the HTML page, but the HTML page inside the element style is 2k style (at least in the IE7 below), this is not even a little aesthetic effect, for which I considered a half-day, asked to do the web of people whether there is a way, and eventually inspired to visit, mistakenly hit. Overloaded GetHostInfo functions:
STDMETHODIMP Chtmlcontainerdlg::gethostinfo (dochostuiinfo* pInfo)
{
Pinfo->dwflags = Dochostuiflag_theme;
return S_OK;
This is a lot to say, ^_^.
Here is a demonstration of a guide to show you in VS2005:
Chtmlcontainerdlg Dlg;
TCHAR Szpath[max_path] = {0};
CString strpath;
GetCurrentDirectory (MAX_PATH, szpath);
strpath = szpath;
strpath + = _t ("\\Default.htm");
Dlg. Sethtmlandcom (strpath, _t ("Testwebcom.webcomctrl"));
Dlg. DoModal ();
The dialog title can actually be set by parsing the HTML document for the title header, which is not currently processed. Here's a look at the components that HTML interacts with your app.
Build an ATL project, testwebcom, add a COM component Webcomctrl, add a method to handle the above band ... button (folder browse button):
STDMETHODIMP Cwebcomctrl::showfolderbrowser (void)
{
Afx_manage_state (AfxGetStaticModuleState ());
TODO: Add implementation code here
AfxMessageBox (_t ("In Com, can show folder Select Dialog"));
return S_OK;
}
There is no specific handling, just a symbolic pop-up dialog box. Well, above we have set the ProgID of the COM component in the dialog box, where the HTML and components can be associated, and the COM component method can be accessed through a script:
<button class= "Buttonclass3custom" id= "browsebtn" type= "button" title= "Browse header file. "Onclick=" Onbrowseheaderfile (); " The ></BUTTON> script is as follows:
function Onbrowseheaderfile ()
{
Window.external.ShowFolderBrowser ();
To run a try, press the Select Folder button to see a dialog box that asks if the component is safe:
This is annoying, the user can not endure each time more pop up this dialog box to ask whether the component is safe. I began to plan to implement the security interface components to solve this problem, but do not know why, did not succeed, search on the internet as if to say in the IE7 inside invalid, no way or look at the MFC source code to solve the problem.
The CDHtmlDialog class gets the external code as follows:
STDMETHODIMP Cdhtmldialog::getexternal (IDispatch **ppdispatch)
{
if (Ppdispatch = = NULL)
return e_pointer;
*ppdispatch = NULL;
if (M_SPEXTERNALDISP.P && canaccessexternal ())
{
M_spexternaldisp.p->addref ();
*ppdispatch = M_SPEXTERNALDISP.P;
return S_OK;
}
return E_NOTIMPL;
} See the Canaccessexternal function, is definitely the code to verify the security, find the function declaration, fortunately is a virtual function, the overload directly returns true:
BOOL chtmlcontainerdlg::canaccessexternal ()
{
We Trust all COM object (haha, you can make virus)
return TRUE;
Friends who are interested can look at the internal implementation.
This is good, press the page Select Folder button, Pop-up dialog box:
A complete set of procedures, the program personally feel good, their duties, communication naturally unblocked, an HTML paired with a COM functional component, functional components not only make the code good encapsulation, but also can be used in many languages.
Since this technology is not used for company development, this edition provides download posted on 2006-12-15 21:11 Wan Lianwen Read (18641) Comment (38) Edit collection reference belongs to Category: MFC
FeedBack:# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-19 22:40 | Noname
Really good. HTML interface in the development of efficiency, extensibility, etc. are very good. It happened that the two days needed to do a program. The interface requirements are more flexible. Just try the idea of Brother Wan.
Using WTL for the first time to do such an application, do not consider the code reuse. So no DLL was made. Even the externaldispatch of the page is implemented inside the program. Since Wan brothers did not give out the source code, I put a demo. Because the code is put up. sort of incompatible. :)
Http://nicoster.googlepages.com/wtlhtml.rar
Lieph $ (at) 163 $ (dot) com reply more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-20 14:10 | Cooelaf
Read the brother's blog, I am very impressed by the accomplishments of brother. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-25 10:51 | Shaolong
Wango, could you make this example code public? I just started to do embedded HTML VC project, but also cdhtmldialog derived classes, but do not know how to implement the corresponding function interface, time is very tight, depressed very, thank you! Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-25 11:04 | Wan Lianwen
Email me and I'll send you.
Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-26 23:59 | Xhl
I have done WebGui under VC6, interested in your ideas, wondering how to use the COM encapsulation feature, how to call COM components in HTML.
Can you send me a copy of your sample code?
My e-mail [email protected]
Thanks a lot! Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2006-12-27 00:01 | Xhl
I've done WebGui under VC6, interested in your ideas, wondering how to use COM encapsulation capabilities, and how to call COM components in HTML.
Can you send me a copy of your sample code?
My e-mail [email protected]
Thanks a lot! Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-01-28 14:04 | Xie
I'm a beginner, and I want a thank you. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-02-25 17:55 | Kukustream
Very interested, can you send me a copy of the sample source, thank you! [email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-03-05 17:24 | Xq
Million seniors, I have long wanted to learn this technology, suffering from data difficult to find, this is met with an expert.
Give me a copy, thank you very much. [email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-03-05 22:47 | Wan Lianwen
See so many people asking for code, the RealSense accident. Because the debugging code was messy and originally developed for the company, the code was not disclosed. Now it seems that the company will not adopt, may think differently. Recently in the graduation project, after 1 weeks I will collate the code and published on this page to download. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-03-10 13:08 | Wan Lianwen
Download file has been provided, vs2005 environment, about other environment I do not intend to transplant. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-08-15 18:44 | Lanse
I want a copy.
[Email protected]
Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-09-05 11:35 | I want one, too, please.
I want one, too, please.
[email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-09-05 14:10 | Wan Lianwen
Alas, I do not know how to say, download is below, but the word is a little bit. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-10-13 08:52 | Yefeng
I want one too, please!
[Email protected]
Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-12-03 16:12 | Ason Jia
I've been doing this lately, but I've met a problem because the middle of the HTML size (not the file size, the width and height of the HTML) is going to change, so I want to get the size dynamically from the HTML, specifically, there is a variable in the HTML to save the HTML size, when the HTML is loaded , the size is calculated by the JS dynamic, and then our dialog to get this size (using IWebBrowser2 directly to query the HTML value), and then dynamically adjust the size of the dialog to accommodate the size of the HTML, but the problem is here: HTML at the time of loading, Often for some reason this element in the DOM is not created, or this element is created, but the size is not calculated (that is, this node has, but value is "0"), Khan ~~~~~ This problem I think for a long time can not solve
I do not know if the author can provide some help, thank you again ~ ~ ~ Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-12-04 10:10 | Wan Lianwen
My thoughts are:
HTML is loaded, it is best not to use HTML, this time the DOM document has not been loaded completely. You need to invoke the script at the time of the ondocumentcompleted event and then modify the dialog box size. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-12-04 15:04 | Ason Jia
I also thought about the ondocumentcompleted when the message was triggered, but the test found that the message function was triggered, but the HTML is not exactly calculated size.
That you mentioned in this function call JS method to calculate the size, this I did not try, in fact, I do not know, sweat ~ ~ ~ Not too familiar with COM.
But it seems to be possible. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-12-04 15:14 | Wan Lianwen
I think you may have made a mistake of knowing this thing. HTML is not a way to calculate size, its layout depends on the size of the Web control. Take this method to do the interface, it is best for a class of HTML page size fixed function to use a dialog box class, so that the dialog box fixed size can be, and for a class of dialog box, the function of processing is similar. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2007-12-05 17:38 | Ason Jia
At present, I am also more inclined to this way of thinking, but the boss said, our products to do n language, because of different language, or you mention the different control, directly caused by the change of HTML size, Halo ~ ~ ~
But in C call JS method, I have to get out, helpless only in this direction first do a painstaking first
Sweat ~ ~
Not really, then I can only write dead ~
Thank the old classmates help and guidance, hehe .... Thanks again ~
Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2008-06-19 06:39 | Arthurlee
At first I thought that I needed to implement the interface of active scriping, and read this article only to know the method is so simple.
Thank you very much! Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2008-10-13 17:58 | Ali
In fact, this does not provide an interface to the active scriping, but only the additional control of the WebBrowser control, if not the MFC may need to use the interface IDocHostUIHandler, IDocHostUIHandler2 and Idochostshowui.
To implement your own active Scripting, you need to use Iactivescriptsite to reply to more comments
# Re: Implement webgui--with MFC (CDHtmlDialog) [not logged in]2008-11-06 12:01 | Yy
Hello I also want a code to see, thank you!
[email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2008-11-10 10:28 | Wan Lianwen
From the atomic age--Your email has a problem???
I'm sorry to reply to you so late, because I have been ill recently. First of all, I admire a girl engaged in C + + development expression. When it comes to interface development, it's definitely not a simple task, not even a really good technical book. CDHtmlDialog is a vs2003 after the SDK added, but this use of people are not many, but a lot simpler. I generally use a window class Atlaxwin_class provided in ATL, which is also available in VC6. According to my experience, the people who can use HTML+CSS+JS to implement interface programming are not common, at least there is some understanding of COM. For your current situation, if you use VC6 development you can consider atlaxwin_class this class for programming, depending on the ATL library, regardless of MFC. I do not have a specific example, I can refer to www.codeproject.com
Www.codeguru.com and other technical websites. If you can't get the result after you try it yourself, please contact me and I'll do a demo. Because this period of time is really sick of not light, Ben wanted to do one to you, but a look at the computer head dizzy. Excuse me.
Always can not send out, try again. Reply to more comments
# Re: Implement webgui--with MFC (CDHtmlDialog) [not logged in]2009-02-23 16:34 | Being
LZ Hello, I am Xie teacher with comrades brother, recently also with a similar interface solution.
Have time to add my MSN Chat [email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2009-10-27 18:07 | Xin
Hello, I want to learn HTML embedded into the VC use, can I send a copy of the code? [EMAIL protected] Thank you very much for replying to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2009-10-28 09:02 | Wxx
Download on the last 2 words, do not understand why so many people can not see. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2009-12-30 09:45 | Eleanor
Hello, I have only recently started to make HTML Embedded MFC dialog box, I would like to ask that I just want to get a link to some of the page's button address, call my program to ping it, return a ping time to the page. I checked the online said with IHTMLElement in the Put_onclick, but these interfaces I do not know, I found vc2005 mshtml.h in the definition of several ihtmldocument and IHTMLElement interface convenient words add me msn:[ Email protected] Guide, thank you for your comments.
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2010-04-18 14:08 | Jjqcat
Very interested, can you send me a copy of the sample source, thank you!
[email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2010-08-26 10:19 | Yyk
Very good. You have a good idea. Take a look!! Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2011-01-28 12:07 | No not
I've been thinking about this lately too, but I'm embarrassed to be under the vc6.0 and not know much about COM ... To pay attention to ... Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2011-07-25 19:14 | Tammy
How can I not open the application under the Debug folder? Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2011-07-26 10:19 | Tammy
Urgent .... Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2011-07-26 10:19 | Tammy
The program is running. But when you click the Browse button. Error saying the current page of the script is running wrong reply more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2011-07-26 10:23 | Wan Lianwen
@tammy
The COM component should not be registered. Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2012-09-22 15:25 | Reed
Senior I was just beginning to learn this aspect of the content of the novice, you have wood has this information, books recommend it, kneeling beg humbly. Contact information: [email protected] reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2013-01-30 18:02 | The year of Cloud pity show
Cannot download, can't open @noname
Reply to more comments
# Re: Implementing webgui--with MFC (CDHtmlDialog) 2013-01-30 18:03 | The year of Cloud pity show
I want a source code
O (∩_∩) o Thank you
[email protected] reply to more comments
Implementing webgui--with MFC (CDHtmlDialog)