xuejianhui

导航

duilib学习笔记02:界面布局

★:带有系统标题框和边框:

//函数原型
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if( uMsg == WM_CREATE ) {
        m_pm.Init(m_hWnd);
        CControlUI *pButton = new CButtonUI;
        pButton->SetName(_T("closebtn"));
        pButton->SetBkColor(0xFFFF0000);
        m_pm.AttachDialog(pButton);
        m_pm.AddNotifier(this);
        return 0;
    }
    else if( uMsg == WM_DESTROY ) {
        ::PostQuitMessage(0);
    }

    LRESULT lRes = 0;
    if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) {
        return lRes;
    }

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

 

--------------------------------------------------------------------------------

 

★:去掉系统标题框和边框:

//函数修改
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if( uMsg == WM_CREATE ) {
        m_pm.Init(m_hWnd);
        CControlUI *pButton = new CButtonUI;
        pButton->SetName(_T("closebtn"));
        pButton->SetBkColor(0xFFFF0000);
        m_pm.AttachDialog(pButton);
        m_pm.AddNotifier(this);
        return 0;
    }
    else if( uMsg == WM_DESTROY ) {
        ::PostQuitMessage(0);
    }
    //NewAdd...Start..For delect the title frame and the rim provide by system.
    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;
    }
    //NewAdd...End..............................................................

    LRESULT lRes = 0;
    if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) {
        return lRes;
    }

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

 

--------------------------------------------------------------------------------

 

★:使用XML进行页面布局:

//函数修改
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if( uMsg == WM_CREATE ) {
        m_pm.Init(m_hWnd);

        //New Change...Start..For get a new layout by oneself...................
        CDialogBuilder builder;
        CControlUI* pRoot = builder.Create(_T("test1.xml"), (UINT)0, NULL, &m_pm);
        ASSERT(pRoot && "Failed to parse XML");
        m_pm.AttachDialog(pRoot);
        //New Change...End......................................................

        m_pm.AddNotifier(this);

        return 0;
    }
    else if( uMsg == WM_DESTROY ) {
        ::PostQuitMessage(0);
    }
    //NewAdd...Start..For delect the title frame and the rim provide by system.
    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;
    }
    //NewAdd...End..............................................................

    LRESULT lRes = 0;
    if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) {
        return lRes;
    }

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

 

--------------------------------------------------------------------------------

test1.xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<Window mininfo="200,360" size=" 480,320 ">
        <Font name="幼圆" size="16" default="true" />
        <VerticalLayout bkcolor="#FFFF00FF">
            <Button name="changeskinbtn" height="20" text="测试按钮" maxwidth="120" />
            <RichEdit name="testrichedit" bordercolor="#FF0000" bordersize="0" borderround="18,18" inset="4,2,4,2" bkcolor="#A0F2F5FA" bkcolor2="#A0FF0000" bkcolor3="#A0F2F5FA" font="1" multiline="true" vscrollbar="true" autovscroll="true" enabled="true" rich="true" readonly="false" text="测试richedit">
            </RichEdit>
            <Edit name="testedit" text="测试编辑框" />
        </VerticalLayout>
        //添加下面一行内容,以修改按钮外观。
        //然后将button_nor.bmp、button_over.bmp、button_down.bmp(可在Duilib发行包中找到)放到exe目录下。
        <Default name="Button" value="normalimage=&quot;file='button_nor.bmp' corner='4,2,4,2' fade='200' hsl='true'&quot; hotimage=&quot;file='button_over.bmp' corner='4,2,4,2' fade='200' hsl='true'&quot; pushedimage=&quot;file='button_down.bmp' corner='4,2,4,2' fade='200' hsl='true' &quot; " />
</Window>

 

--------------------------------------------------------------------------------

posted on 2012-11-22 16:12  xuejianhui  阅读(3721)  评论(0编辑  收藏  举报