This tutorial will show how to:
Minimum Origin Version Required: Origin 2017
Note: You can download the sample files here. |
When you create an HTML dialog, the first step is creating an HTML page.
<!DOCTYPE html> <html> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <head> <title> A Small Hello </title> </head> <body> <h1>Hello World</h1> <p>This is very minimal "hello world" HTML document.</p> </body> </html>
Note: When editing is complete, you can check the content of this page by opening it with any web browser. |
In this section, you will make the generated HTML page display in the dialog.
#include <Origin.h> #include <..\OriginLab\DialogEx.h> #include <..\OriginLab\HTMLDlg.h>
HTMLDlg
, and point to the HTML page inside the method GetInitURL()
.
class HelloWorldDlg: public HTMLDlg { public: string GetInitURL() //get the path of html file { string strFile = __FILE__; //the path of the current file return GetFilePath(strFile) + "index.html"; } };
void hello() { HelloWorldDlg dlg; dlg.DoModalEx(GetWindow()); }
An HTML dialog with "Hello World" will pop up:
If you want to learn more, try to improve the program by modifying the dialog and adding event handlers.
Note: The complete code of the following features is available in HelloWorldDlg1.cpp. |
To do this, use ModifyStyle
to disable WS_THICKFRAME in the method OnInitDialog
inside your dialog class:
BOOL OnInitDialog() { ModifyStyle(WS_THICKFRAME, 0);//prevent resizing return HTMLDlg::OnInitDialog(); }
You need to call a parent class method GetDlgInitSize
from you dialog class, and specify the width and height of the dialog in it:
BOOL GetDlgInitSize(int& width, int& height)//get dialog size { width = 500; height = 200; return true; }
Similar to Dialog Builder, a message map is used to specify which events will be handled and which function will be called to handle them.
As an example, an event handler methods are added inside the user defined class HelloWorldDlg to pop up a message when the dialog is closed.
HelloWorldDlg
.
//Message Map public: EVENTS_BEGIN_DERIV(HTMLDlg) ON_DESTROY(OnDestroy) EVENTS_END_DERIV
HelloWorldDlg
to pop up a message box when the dialog is closed.
BOOL OnDestroy() { MessageBox(GetSafeHwnd(), _L("Thank you and have a good day!") ,_L("Message")); return true; }