Duilib是一款基于XML的开源DirectUi界面库。在MFC中使用Duilib可以使c++界面更具有扩展性。
源代码 http://download.csdn.net/detail/witch_soya/4881669
在MFC中嵌套使用Duilib
在MFC对话框中产生一个自定义的Duilib窗口类 CDuiLib_Dialog m_dlgDuilib;
在CDuiLib_Dialog中处理以下消息
void CDuiLib_Dialog::Notify(TNotifyUI& msg)
{
if( msg.sType == _T("click") )
{
if( msg.pSender->GetName() == _T("closebtn") )
{
Close();
}
}
}
LRESULT CDuiLib_Dialog::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); */
CPaintManagerUI::SetInstance(AfxGetInstanceHandle());
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin"));
m_pm.Init(m_hWnd);
CDialogBuilder builder;
CControlUI *pRoot = builder.Create("MainActivity.xml", (UINT)0, NULL, &m_pm);
ASSERT(pRoot && "Failed to parse XML");
m_pm.AttachDialog(pRoot);
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);
}