CCustomUI.h
#pragma once
class CCustomUI : public CContainerUI, public INotifyUI
{
public:
CCustomUI(CPaintManagerUI* pm);
virtual ~CCustomUI();
public:
virtual void Notify(TNotifyUI& msg);
};
CCustomUI.cpp
#include "pch.h"
#include "CCustomUI.h"
CCustomUI::CCustomUI(CPaintManagerUI* pm)
{
CDialogBuilder builder;
CContainerUI* pSub = static_cast<CContainerUI*>(builder.Create(_T("custom.xml"), (UINT)0, NULL, pm));
if (pSub)
{
Add(pSub);
pm->AddNotifier(this);
}
}
CCustomUI::~CCustomUI()
{
}
void CCustomUI::Notify(TNotifyUI& msg)
{
if (msg.sType == _T("click"))
{
XDebug() << "CCustomUI::Notify";
}
}
dlg.h
class CDialogUI : public WindowImplBase
{
...
virtual CControlUI* CreateControl(LPCTSTR pstrClass);
...
};
dlg.cpp
CControlUI* CDialogUI::CreateControl(LPCTSTR pstrClass)
{
if (_stricmp(pstrClass, "XCustom") == 0)
return new CCustomUI(&m_PaintManager);
return nullptr;
}
通过这个代码可以实现DUILIB消息处理模块化,但是存在一个问题,就是窗体所有消息都经过模块类里。目前我暂时想了一个办法,我定义一个基类的模块实现类,伪代码如下
class CustomUI
{
public:
CustomUI(CPaintManagerUI* pm, 模块名称,xml文件)
void Notify(TNotifyUI& msg)//此类设置为不可继承
{
if (msg.sType == _T("click"))//只处理特定事件
{
msg.pSender->GetName() 取出控件名称,然后只处理名称为:模块名称.控件名称 格式的,其它的不作任何处理
}
}
virtual void OnClick(TNotifyUI& msg);
};