This is because I am the only one in my department, and I am the only one in C ++ and others in C #), so I will discuss with the technical consultant how to present the client. He said that, based on previous experience in the previous system), the page is frequently upgraded. We recommend that you use embedded HTML to display the page. In this way, you only need to upgrade HTML later. After hearing this, I lost my teeth in half. After I dragged the dialog box for half a month, I gave it a question.
Then I began to look for methods for displaying HTML pages in MFC, found some custom HTML classes, and found Webbrowser Control. I haven't found the Control yet ), finally, the CDHtmlDialog class is locked.
This category has just begun to shine recently. In the vc6.0 era, it is hard to see what is made with this stuff. It is a win2k style. What kind of win7 style can be used now? Maybe the Metro style can be used in vs11 .. After a simple experiment, I found that it was still usable and I decided to use it.
Create a new MFC Application project. In this step, mark the HTML Dialog
650) this. width = 650; "src =" http://img1.51cto.com/attachment/201205/170610941.png "border =" 0 "alt =" "/> you can see that the dialog box is derived from the CDHtmlDialog class.
After the creation is complete, observe the differences between the Code and the previous one. Four points may be found ):
- class CTestHtmlDialogDlg : public CDHtmlDialog
It indicates that the dialog box class does inherit CDHtmlDialog.
- // Dialog Data
- enum { IDD = IDD_TESTHTMLDIALOG_DIALOG, IDH = IDR_HTML_TESTHTMLDIALOG_DIALOG };
The enumeration here is changed to two, that is, there is a normal dialog box and an HTML dialog box.
- CTestHtmlDialogDlg::CTestHtmlDialogDlg(CWnd* pParent /*=NULL*/)
- : CDHtmlDialog(CTestHtmlDialogDlg::IDD, CTestHtmlDialogDlg::IDH, pParent)
In the CTestHtmlDialogDlg constructor, A CTestHtmlDialogDlg: IDH is added to the member initialization list of CDHtmlDialog.
- /////////////////////////////////////////////////////////////////////////////
- //
- // HTML
- //
-
- IDR_HTML_TESTHTMLDIALOG_DIALOG HTML "TestHtmlDialog.htm"
In the resourcefile, the following line is used to define the html file resource of the html dialog box. You can modify it to a specific name, such as index.html. Of course, the html file in the project must also be changed to the corresponding name.
Let's do a test. Modify testhtmldialog.htm.
- <HTML>
- <HEAD>
- </HEAD>
- <BODY ID=CTestHtmlDialogDlg style="font-family:MS Shell Dlg;font-size:8">
-
-
-
-
- </BODY>
- </HTML>
The result is as follows:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1A4424522-1.png "border =" 0 "alt =" "/>
How is it? It is much easier to drag a dialog box, drag a control, Load a resource, modify an ID number, associate a variable, and Load various shows?
I have a problem here. It has not been solved by the time of publication. Please reply if you have any suggestions. I can only use absolute path c: \ test.jpg, but cannot use relative paths. test.jpg ,.. // test.jpg ,.. /// Debug // test.jpgand so on, and I put test.jpg in the project directory, and it cannot be loaded. It always shows a small Red Cross ..
------------------------------- I am a gorgeous split line --------------------------------------
Continue our experiment. The page cannot be displayed only. What interaction do you have to make? So I'm glad that this feature also supports Javascript.
Use the HTML editor that comes with vs2010to edit testhtmldialog.htm. Here, I would like to like VS2010's HTML editor, which is very user-friendly and can basically be comparable to Dreamweaver. Double-click the button and you can directly write The onclick event. The default is Javascript.
We drag a button above, change the name, save and double-click the button to write the onclick event
- Function Button1_onclick (){
- Alert ("Hello, what are you doing ");
- }
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1A4422019-2.png "border =" 0 "alt =" "/>
The alert information is displayed.
------------------------------- I am a gorgeous split line --------------------------------------
Next I came up with the idea: Can Javascript call functions in the local dialog box? I went to Baidu to Google for a while and found that it was okay. The method is also relatively simple.
- // 1. Enable CTestHtmlDialog to support automation
- // Add it in OnInitDialog ()
- EnableAutomation ();
-
- // 2. expose itself to Javascript
- // Add it in OnInitDialog ()
- SetExternalDispatch (GetIDispatch (TRUE); // set the extension interface of the browser control to the IDispatch of the dialog box.
-
- // 3. Declare DISPATCH_MAP
- // In TestHtmlDialog. h
- DECLARE_DISPATCH_MAP ()
-
- // 4. Define DISPATCH_MAP
- // In TestHtmlDialog. cpp
- BEGIN_DISPATCH_MAP (CMyDHtmlDialog, CDHtmlDialog)
- DISP_FUNCTION (CMyDHTMLDialog, "SayHello", func, VT_EMPTY, VTS_NONE)
- END_DISPATCH_MAP ()
We can see that it is a bit like the message ing mechanism of MFC.
Next, write a function:
- MessageBox(_T("SayHello Func"), _T("Hello~~"));
Modify the button and click the event:
- Function Button1_onclick (){
- // Alert ("Hello, what are you doing ");
- External. SayHello ();
- }
Good. Compile and run it. Click the button to bring up something:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1A4422113-3.png "border =" 0 "alt =" "/>
Because the program should be exposed internally, Windows thinks this may be insecure. Click "yes" and you will see the effect of the function you just wrote.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1A4423H5-4.png "border =" 0 "alt =" "/>
But I think it's safe. I don't want to see this thing .. What should I do? Find the solution.
In CTestHtmlDialog, The CanAccessExternal () function is reloaded.
- BOOL CWebbrowserDlg::CanAccessExternal()
- {
- return TRUE;
- }
Now, the nasty security prompt is missing ~
------------------------------- I am a gorgeous split line --------------------------------------
Can I access Javascript Functions in the dialog box? Of course, you can. In this way, you can only use Javascipt to determine the validity of data, so that C ++ can focus on logical operations.
This information is relatively small. I have found one and it is not completely understood. Think about it for a moment, there is little need for this, so there is not much information. I found something in this aspect on codeproject. If you are interested, please wait and see ~ Time-Space Shuttle Portal
This article from the "front of the tradeford reverse tairuibao blog, please be sure to keep this source http://serious.blog.51cto.com/242085/864132