定义窗口类
继承
WindowImplBase
(示例代码使用了未考虑安全的单例)
aet.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#ifndef _AET_H #define _AET_H class CAetDlg : public DuiLib::WindowImplBase { private: CAetDlg(); public: ~CAetDlg(); static CAetDlg* GetInstance(); public: LPCTSTR GetWindowClassName() const override; void OnFinalMessage(HWND hWnd) override; DuiLib::CDuiString GetSkinFile() override; UINT GetClassStyle() const; void Notify(DuiLib::TNotifyUI& msg) override; void OnClick(DuiLib::TNotifyUI& msg) override; private: static CAetDlg* m_instance; }; #endif #ifndef _AET_H |
aet.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include "aet.h" CAetDlg* CAetDlg::m_instance = nullptr; CAetDlg::CAetDlg() {} CAetDlg::~CAetDlg() {} LPCTSTR CAetDlg::GetWindowClassName() const { return -T("aet_window"); } void CAetDlg::OnFinalMessage(HWND hWnd) { __super::OnFinalMessage(hWnd); delete this; } DuiLib::CDuiString CAetDlg::GetSkinFile() { return _T("aet.xml"); } UINT CAetDlg::GetClassStyle() const { return UI_CLASSSTYLE_FRAME|CS_DBLCLKS; } void CAetDlg::Notify(DuiLib::TNotify& msg) { //处理消息 swith(msg.sType) { case DUI_MSGTYPE_CLICK: { //aet按钮被点击 if(msg.pSender->GetName() == "aet") { //do something } } break; } } void CAetDlg::OnClick(DuiLib::TNotifyUI& msg) { } |
XML文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?xml version="1.0" encoding="utf-8"?> <Window size="220,180" roundcorner="5,5"> <Font id="0" name="微软雅黑" size="13" /> <HorizontalLayout borderround="5,5" bkcolor="#FFFFFFFF"> <Control name="control_01" mouse="false" width="15"/> <VerticalLayout width="190"> <Control name="control_03" mouse="false" height="15"/> <Label name="system_head" height="18" text="系统头像" textcolor="#FF6C6C6C"/> <Control name="control_05" mouse="false" height="9"/> <HorizontalLayout childpadding="10" height="32"> <Button name="pic_01" width="30" height="30" bkimage="main/QQ User Head.png"/> <Button name="pic_02" width="30" height="30" bkimage="main/QQ User Head.png"/> <Button name="pic_03" width="30" height="30" bkimage="main/QQ User Head.png"/> <Button name="pic_04" width="30" height="30" bkimage="main/QQ User Head.png"/> <Button name="pic_05" width="30" height="30" bkimage="main/QQ User Head.png"/> </HorizontalLayout> <Control name="control_06" mouse="false" height="10"/> <Button name="split_line" height="1" mouse="false" bkimage="file='' fade=''"/> <Control name="control_07" mouse="false" height="14"/> <Label name="self_head" height="18" text="自定义头像" textcolor="#FF6C6C6C"/> <Control name="control_08" mouse="false" height="10"/> <Button name="self_choose_btn" height="30" normalimage="main/btnLoginHot.png"/> <Control name="control_04" mouse="false" height="24"/> </VerticalLayout> <Control name="control_02" mouse="false" width="15"/> </HorizontalLayout> </Window> |
生成窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//标识 bool _flag = false; if(/*condition*/) { auto pAetDlg = CAetDlg::GetInstance(); if(pAetDlg == nullptr) return; if(!_flag) { pAetDlg->Create(NULL,_T(""),UI_WNDSTYLE_FRAME,WS_EX_TOOLWINDOW); pAetDlg->ShowWindow(true); _flag = true; } } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ Duilib用于C++项目10/30
- ♥ Linux开发相关工具08/05
- ♥ VMaware:安装MacOS 10.14.610/16
- ♥ 【Manjaro】Software installation 103/21
- ♥ Go 基础:第二篇04/18
- ♥ 【LeetCode-July】07/10