给我一个duilib的简单demo程序
时间: 2023-07-29 20:14:44 浏览: 81
好的,以下是一个使用 Duilib 的简单 demo 程序,它展示了如何创建一个窗口并显示一个按钮控件。
```cpp
#include <Windows.h>
#include "DuiLib/UIlib.h"
using namespace DuiLib;
class CMainFrame : public WindowImplBase
{
public:
CMainFrame() {}
virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
virtual CDuiString GetSkinFile() { return _T("mainframe.xml"); }
virtual CDuiString GetSkinFolder() { return _T("res"); }
virtual void InitWindow()
{
CButtonUI* pButton = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btn_test")));
if (pButton) {
pButton->OnEvent += MakeDelegate(this, &CMainFrame::OnBtnTestClick);
}
}
void OnBtnTestClick(TNotifyUI& msg)
{
MessageBox(NULL, _T("Hello, Duilib!"), _T("Message"), MB_OK);
}
};
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR lpCmdLine, int nCmdShow)
{
CPaintManagerUI::SetInstance(hInstance);
CMainFrame frame;
frame.Create(NULL, _T("Duilib Demo"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
frame.SetIcon(IDI_ICON);
frame.CenterWindow();
frame.ShowWindow();
CPaintManagerUI::MessageLoop();
return 0;
}
```
你可以将上述代码保存到一个名为 `main.cpp` 的文件中,并且需要将 `mainframe.xml` 和 `res` 文件夹放到同一目录下,其中 `mainframe.xml` 为窗口的布局文件,`res` 文件夹中存放了窗口所需的资源文件,比如图片等。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)