ZBLOG

duilib设置窗口边框

在DuiLib中,可以通过设置窗口的样式来实现自定义窗口边框。以下是一个示例:

#include "DuiLib/UIlib.h"

using namespace DuiLib;

class MyWindow : public CWindowWnd, public INotifyUI
{
public:
    virtual LPCTSTR GetWindowClassName() const { return _T("MyWindow"); }
    virtual UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; }

    virtual void Notify(TNotifyUI& msg)
    {
        if (msg.sType == _T("click"))
        {
            if (msg.pSender->GetName() == _T("btnClose"))
                Close();
            else if (msg.pSender->GetName() == _T("btnMin"))
                SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
        }
    }

    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        LRESULT lRes = 0;
        BOOL bHandled = TRUE;

        switch (uMsg)
        {
            case WM_CREATE:
                OnCreate(uMsg, wParam, lParam);
                break;
            case WM_NCACTIVATE:
                if (!::IsIconic(*this))
                    return (wParam == 0) ? TRUE : FALSE;
                break;
            case WM_NCCALCSIZE:
                if (!::IsIconic(*this))
                    return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
                break;
            default:
                bHandled = FALSE;
                break;
        }

        if (bHandled)
            return lRes;

        return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
    }

private:
    void OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        m_PaintManager.Init(m_hWnd);
        CDialogBuilder builder;
        CContainerUI* pRoot = static_cast<CContainerUI*>(builder.Create(_T("window.xml"), (UINT)0, NULL, &m_PaintManager));
        if (pRoot != NULL)
        {
            m_PaintManager.AttachDialog(pRoot);
            m_PaintManager.AddNotifier(this);

            CButtonUI* btnClose = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnClose")));
            if (btnClose != NULL)
                btnClose->SetVisible(true);

            CButtonUI* btnMin = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnMin")));
            if (btnMin != NULL)
                btnMin->SetVisible(true);
        }
    }

private:
    CPaintManagerUI m_PaintManager;
};

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int nCmdShow)
{
    CPaintManagerUI::SetInstance(hInstance);
    CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("\\resources"));

    MyWindow wnd;
    
    // 设置窗口样式,去掉默认边框
    DWORD dwStyle = WS_POPUP | WS_VISIBLE;
    ::CreateWindowEx(WS_EX_APPWINDOW, wnd.GetWindowClassName(), _T("DuiLib Custom Window Border"), dwStyle,
                     0, 0, 800, 600, NULL, NULL, hInstance, &wnd);
                     
    CPaintManagerUI::MessageLoop();

    return 0;
}

在上述示例中,我们创建了一个自定义窗口边框的窗口。通过设置 WS_POPUP 样式来实现去掉默认边框。然后,通过调用 CreateWindowEx 函数创建窗口并设置其样式。

你可以根据自己的需求修改窗口的布局和样式,以实现更加个性化的窗口边框效果。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=16767

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?