Duilib 带xml的1

//#include <afxdlgs.h> 
#include "../DuiLib/UIlib.h"
#include <wchar.h>
#include <tchar.h>
#pragma comment(lib,"../lib/DuiLib_d.lib")
using namespace DuiLib;




class CFrameWindowWnd : public CWindowWnd, public INotifyUI//, public CDwm, public CDPI
{
public:
    CFrameWindowWnd()  { };
    LPCTSTR GetWindowClassName() const { return _T("UIMainFrame"); };
    UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; };
    void OnFinalMessage(HWND /*hWnd*/) { delete this; };

    void Init() { }

    void OnPrepare(){
        CCheckBoxUI* pcheck = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("uid46CheckBox")));
        //pcheck->SetEnabled(false);
    }


    void Notify(TNotifyUI& msg)
    {
        if (msg.sType == _T("windowinit")) OnPrepare();
        else if (msg.sType == _T("click")) {
            if (msg.pSender->GetName() == _T("startCheckBtn")) {


                TCHAR tsCmd[1024] = { 0 };

                wcscat_s(tsCmd, _T("mulu\node.exe test.js"));

                CRichEditUI* pRich = static_cast<CRichEditUI*>(m_pm.FindControl(_T("testrichedit1")));
                if (pRich) {
                    //pRich->SetText(str);

                    pRich->RemoveAll();
                    pRich->SetText(_T(""));
                    pRich->AppendText(tsCmd);
                    pRich->AppendText(_T("
执行结果:
"));
            
                    pRich->SetEnabled(false);
                }
            
            }else if (msg.pSender->GetName() == _T("uid46CheckBox")) {
                
                CCheckBoxUI* pcheck = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("uid46CheckBox")));
                bool bCheck = pcheck->GetCheck(); 
                //if (bCheck){}
                pcheck->SetCheck(true);
                MessageBox(NULL, TEXT("暂时不支持检测UID4-6位."), TEXT("提示"), 0);
            }
        }
    }

    LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        if (uMsg == WM_CREATE) {
            m_pm.Init(m_hWnd);
            CDialogBuilder builder;
            CControlUI* pRoot = builder.Create(_T("checkparawindow.xml"), (UINT)0, NULL, &m_pm);
            ASSERT(pRoot && "Failed to parse XML");
            m_pm.AttachDialog(pRoot);
            m_pm.AddNotifier(this);

            Init();
            return 0;
        }
        else if (uMsg == WM_DESTROY) {
            ::PostQuitMessage(0L);
        }
        else if (uMsg == WM_NCACTIVATE) {
            if (!::IsIconic(*this)) return (wParam == 0) ? TRUE : FALSE;
        }
        LRESULT lRes = 0;
        if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
        return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
    }

public:
    CPaintManagerUI m_pm;

};


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow)
{
    CPaintManagerUI::SetInstance(hInstance);
    CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
    /*
    HRESULT Hr = ::CoInitialize(NULL);
    if( FAILED(Hr) ) return 0;
    */
    CWndShadow::Initialize(hInstance);

    CFrameWindowWnd* pFrame = new CFrameWindowWnd();
    if (pFrame == NULL) return 0;
    pFrame->Create(NULL, _T("工具V1.0"), UI_WNDSTYLE_FRAME | WS_CLIPCHILDREN, WS_EX_WINDOWEDGE);
    pFrame->CenterWindow();
    pFrame->ShowWindow(true);
    CPaintManagerUI::MessageLoop();

    //::CoUninitialize();
    return 0;
}

如果要再创建一个可再定义一个窗口类

CFrameWindowWnd1* pFrame = new CFrameWindowWnd1();
if (pFrame == NULL) return 0;
pFrame->Create(NULL, _T("工具V1.0"), UI_WNDSTYLE_FRAME | WS_CLIPCHILDREN, WS_EX_WINDOWEDGE);
pFrame->CenterWindow();
pFrame->ShowWindow(true);
CPaintManagerUI::MessageLoop();

<?xml version="1.0" encoding="UTF-8"?>
<Window mininfo="200,360" size="360,600">
    <Font shared="true" id="0" name="幼圆" size="12" default="true" />
    <Font shared="true" id="1" name="微软雅黑" size="18" />
    <Include source="scrollbar.xml" />
    <Default shared="true" name="Button"   value="textcolor=&quot;#000000&quot; hottextcolor=&quot;#FFFFFF&quot; focusedtextcolor=&quot;#000000&quot; pushedtextcolor=&quot;#77a8de&quot; normalimage=&quot;file='Button/btn.png' corner='5,11,5,11' source='0,0,96,24'&quot; hotimage=&quot;file='Button/btn.png' corner='5,11,5,11' source='0,24,96,48'&quot; pushedimage=&quot;file='Button/btn.png' corner='5,11,5,11' source='0,48,96,72'&quot; disabledimage=&quot;file='Button/btn.png' corner='5,11,5,11' source='0,72,96,96'&quot;" />
    <Default shared="true" name="CheckBox" value="textcolor=&quot;#000000&quot; hottextcolor=&quot;#FF386382&quot; selectedtextcolor=&quot;#FF386382&quot; disabledtextcolor=&quot;#FFbac0c5&quot; textpadding=&quot;20,2,0,0&quot; align=&quot;left&quot; selectedimage=&quot;file='Icon/checked.png' dest='0,2,16,18'&quot; normalimage=&quot;file='Icon/unchecked.png' dest='0,2,16,18'&quot;" />

    <VerticalLayout inset="10,6,10,6" bkcolor="#AAAAAAAA" >

        <Button   name="startCheckBtn"  padding="0,4,0,0" height="20" text="文件已放好,开始检查"  />
        <CheckBox name="uid46CheckBox"  padding="0,4,0,0" height="20" text="是否检查UID的4-6位" />
        <RichEdit name="testrichedit1" padding="0,4,0,0" bordercolor="#888888" bordersize="1" borderround="8,8" inset="4,2,4,2" bkcolor="#FFE2E5EA" bkcolor2="#FF00F5DA" bkcolor3="#FFF2F5FA" font="2" multiline="true" rich="true" hscrollbar="true" autohscroll="true"/>
        <DetectInfoList />
    </VerticalLayout>
</Window>
原文地址:https://www.cnblogs.com/cnchengv/p/14633005.html