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("\r\n执行结果:\r\n")); 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="#000000" hottextcolor="#FFFFFF" focusedtextcolor="#000000" pushedtextcolor="#77a8de" normalimage="file='Button/btn.png' corner='5,11,5,11' source='0,0,96,24'" hotimage="file='Button/btn.png' corner='5,11,5,11' source='0,24,96,48'" pushedimage="file='Button/btn.png' corner='5,11,5,11' source='0,48,96,72'" disabledimage="file='Button/btn.png' corner='5,11,5,11' source='0,72,96,96'"" /> <Default shared="true" name="CheckBox" value="textcolor="#000000" hottextcolor="#FF386382" selectedtextcolor="#FF386382" disabledtextcolor="#FFbac0c5" textpadding="20,2,0,0" align="left" selectedimage="file='Icon/checked.png' dest='0,2,16,18'" normalimage="file='Icon/unchecked.png' dest='0,2,16,18'"" /> <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>