Duilib是一个开源 好用的界面库 这是一个简单的入门学习demo

  首先编译好Duilib库,将相应的lib文件进行链接引用,dll文件放在运行目录下。编译要注意uncode码的问题和有一行注释影响hfile的声明,然后回编译通过,其中有很多demo例子,但是现在水平看不懂,先在网上找了一个教程跟着做了一次,基本可以看懂。

#pragma once
#include <Duilib\UIlib.h>

using namespace DuiLib;

#ifdef _DEBUG
#   ifdef _UNICODE
#       pragma comment(lib, "DuiLib_d.lib")
#   else
#       pragma comment(lib, "DuiLib_ud.lib")
#   endif
#else
#   ifdef _UNICODE
#       pragma comment(lib, "DuiLib_u.lib")
#   else
#       pragma comment(lib, "DuiLib.lib")
#   endif
#endif

class CDuiFrameWnd : public CWindowWnd, public INotifyUI
{
public:
    virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
    virtual void    Notify(TNotifyUI& msg) {
            if (msg.sType == _T("click"))
            {
                if (msg.pSender->GetName() == _T("btnHello"))
                {
                    ::MessageBox(NULL, _T("我是按钮"), _T("点击了按钮"), NULL);
                }
            }
    }
    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        LRESULT lRes = 0;

        if (uMsg == WM_CREATE)
        {
            //CControlUI *pWnd = new CButtonUI;
            //pWnd->SetName(_T("btnHello"));
            //pWnd->SetText(_T("Hello World"));   // 设置文字
            //pWnd->SetBkColor(0xFF00FF00);       // 设置背景色

            //m_PaintManager.Init(m_hWnd);
            //m_PaintManager.AttachDialog(pWnd);
            //m_PaintManager.AddNotifier(this);   // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理
            //return lRes;
            m_PaintManager.Init(m_hWnd);

            CDialogBuilder builder;
            CControlUI* pRoot = builder.Create(_T("duilib.xml"), (UINT)0, NULL, &m_PaintManager);   // duilib.xml需要放到exe目录下
            ASSERT(pRoot && "Failed to parse XML");

            m_PaintManager.AttachDialog(pRoot);
            m_PaintManager.AddNotifier(this);   // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理
            return lRes;

        }
        else if (uMsg == WM_NCACTIVATE)
        {
            if (!::IsIconic(m_hWnd))
            {
                return (wParam == 0) ? TRUE : FALSE;
            }
        }
        else if (uMsg == WM_NCCALCSIZE)
        {
            return 0;
        }
        else if (uMsg == WM_NCPAINT)
        {
            return 0;
        }


        if (m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes))
        {
            return lRes;
        }
        
        return __super::HandleMessage(uMsg, wParam, lParam);
        
    }

protected:
    CPaintManagerUI m_PaintManager;
};

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    CPaintManagerUI::SetInstance(hInstance);
    CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());   // 设置资源的默认路径(此处设置为和exe在同一目录)
    CDuiFrameWnd duiFrame;
    duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
    duiFrame.CenterWindow();
    duiFrame.ShowModal();
    return 0;
}

xml文件放置在运行目录下;

运行效果图如下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值