1,下载HTMLayoutSDK,,放在workspace。
SDK下载地址:
2,vs创建win32项目。
3,引入HTMLayoutSDK的include和lib。
include:项目右键,选属性,选C/C++,选常规,附加包含目录引入HTMLayoutSDK的include目录。
lib:项目右键,选属性,选连接器,选常规,附加库目录引入HTMLayoutSDK的lib目录。
4,将HTMLayoutSDK\bin目录下的htmlayout.dll文件放在项目目录下:D:\c_workspace\Win32Html\Win32Html
5,引入头文件。
#include <htmlayout.h> #include "behaviors/notifications.h" #include <htmlayout_behavior.hpp> #pragma comment(lib,"HTMLayout.lib")
6,改写LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)函数:
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; LRESULT lResult; BOOL bHandled; // HTMLayout + // HTMLayout could be created as separate window // using CreateWindow API. // But in this case we are attaching HTMLayout functionality // to the existing window delegating windows message handling to // HTMLayoutProcND function. lResult = HTMLayoutProcND(hWnd,message,wParam,lParam, &bHandled); if(bHandled) return lResult; switch (message) { //htmlayout------------------------------beg case WM_CREATE: HTMLayoutLoadFile(hWnd,_T("Hello.htm")); //Hello.htm需要放在和exe同一目录,记得把dll也copy过去 break; //htmlayout------------------------------end case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
7,新建一个html文件,文件名Hello.htm
里面随意写些内容:
<body> <h2>hello world !</h2> </body>
8,运行:
win32最简单的htmlayout图形界面demo