11.1 消息映射
SkinUI通过消息映射宏组成一张消息映射表,并跟基类的消息映射表联合起来。
一个对话框类如果要自己处理某些消息,需要在头文件和源文件分别加上消息映射宏,如下所示:
- 头文件
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_WM_NCDESTROY()
ON_SKINUI_COMMAND(IDC_BUTTON, OnBtnClickedCommand)
ON_SKINUI_COMMAND_RANGE(IDC_BUTTON1, IDC_BUTTON2, OnBtnClickedCommand)
ON_SKINUI_UPDATE_COMMAND_UI(IDC_MENU, OnUpdateCommandUI)
ON_SKINUI_MESSAGE(WM_COMBOBOX_SEL_CHANGE, OnComboBoxSelChange)
SKINUI_END_MESSAGE_MAP()
11.2 消息处理
11.2.1 命令消息处理
11.2.1.1 单命令消息处理
一个控件Id绑定一个消息处理函数,如下所示:
- 头文件
void OnBtnClickedCommand(UINT uNotifyCode, int nID, CSkinView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_COMMAND(IDC_BUTTON, OnBtnClickedCommand)
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnBtnClickedCommand(UINT uNotifyCode, int nID, CSkinView* pView)
{
}
11.2.1.2 范围命令消息处理
一个控件Id范围绑定一个消息处理函数,如下所示:
- 头文件
void OnBtnClickedCommand(UINT uNotifyCode, int nID, CSkinView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_COMMAND_RANGE(IDC_BUTTON1, IDC_BUTTON2, OnBtnClickedCommand)
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnBtnClickedCommand(UINT uNotifyCode, int nID, CSkinView* pView)
{
}
11.2.1.3 更新UI命令消息处理
SkinUI会在需要的时候发送更新UI命令消息用来更新UI组件的状态。主要存在以下几种情况:
- 按钮的禁用;
- 菜单的禁用;
- 菜单的选中;
按钮的禁用:
- 头文件
void OnUpdateCommandUI(CSkinView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_UPDATE_COMMAND_UI(IDC_BUTTON, OnUpdateCommandUI)
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnUpdateCommandUI(CSkinView* pView)
{
pView->SetEnable(FALSE);
}
菜单的禁用:
- 头文件
void OnUpdateCommandUI(CSkinView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_UPDATE_COMMAND_UI(IDC_MENU, OnUpdateCommandUI)
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnUpdateCommandUI(CSkinView* pView)
{
pView->SetEnable(FALSE);
}
菜单的选中:
- 头文件
void OnUpdateCommandUI(CSkinView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_UPDATE_COMMAND_UI(IDC_MENU, OnUpdateCommandUI)
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnUpdateCommandUI(CSkinView* pView)
{
pView->SetSelected(TRUE);
}
11.2.2 非命令消息处理
SkinUI内置了一些消息,可以自动解析消息的参数,参考下面的消息映射宏:
- ON_SKINUI_WM_CREATE()
- ON_SKINUI_WM_PAINT()
- ON_SKINUI_WM_ERASEBKGND()
- ON_SKINUI_WM_SETCURSOR()
- ON_SKINUI_WM_DESTROY()
- ON_SKINUI_WM_SETFOCUS()
- ON_SKINUI_WM_NCDESTROY()
- ON_SKINUI_WM_NCLBUTTONDOWN()
- ON_SKINUI_WM_KILLFOCUS()
- ON_SKINUI_WM_SIZE()
- ON_SKINUI_WM_SYSKEYDOWN()
- ON_SKINUI_WM_SYSKEYUP()
- ON_SKINUI_WM_KEYDOWN()
- ON_SKINUI_WM_KEYUP()
- ON_SKINUI_WM_CHAR()
- ON_SKINUI_WM_SIZING()
- ON_SKINUI_WM_LBUTTONDOWN()
- ON_SKINUI_WM_LBUTTONUP()
- ON_SKINUI_WM_RBUTTONDOWN()
- ON_SKINUI_WM_RBUTTONUP()
- ON_SKINUI_WM_LBUTTONDBLCLK()
- ON_SKINUI_WM_MOUSEMOVE()
- ON_SKINUI_WM_MOUSEHOVER()
- ON_SKINUI_WM_MOUSELEAVE()
- ON_SKINUI_WM_MOUSEWHEEL()
- ON_SKINUI_WM_NCHITTEST()
- ON_SKINUI_WM_GETMINMAXINFO()
- ON_SKINUI_WM_TIMER()
- ON_SKINUI_WM_SYSCOMMAND()
- ON_SKINUI_WM_CLOSE()
- ON_SKINUI_WM_MOVE()
- ON_SKINUI_WM_MOVING()
- ON_SKINUI_WM_COPYDATA()
- ON_SKINUI_WM_WINDOWPOSCHANGED()
- ON_SKINUI_WM_ACTIVATE()
- ON_SKINUI_WM_HOTKEY()
- ON_SKINUI_WM_QUERYENDSESSION()
- ON_SKINUI_WM_IME_STARTCOMPOSITION()
- ON_SKINUI_WM_IME_ENDCOMPOSITION()
- ON_SKINUI_WM_IME_COMPOSITION()
- ON_SKINUI_WM_DISPLAYCHANGE()
11.2.2.1 自动解析参数的消息处理
上面的消息,可以由SkinUI自动解析参数。参考下面的示例:
- 头文件
void OnLButtonDown(UINT nFlags, CPoint point, BOOL& bHandle);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_WM_RBUTTONDOWN()
SKINUI_END_MESSAGE_MAP()
void CMainDialog::OnLButtonDown(UINT nFlags, CPoint point, BOOL& bHandle)
{
}
11.2.2.2 手动解析参数的消息处理
用户自定义消息和未提供自动解析参数的系统消息,不能自动解析参数,需要开发者手动解析。参考下面的示例:
- 头文件
LRESULT OnComboBoxSelChange(WPARAM wParam, LPARAM lParam);
SKINUI_DECLARE_MESSAGE_MAP()
- 源文件
SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog)
ON_SKINUI_MESSAGE(WM_COMBOBOX_SEL_CHANGE, OnComboBoxSelChange)
SKINUI_END_MESSAGE_MAP()
LRESULT CMainDialog::OnComboBoxSelChange(WPARAM wParam, LPARAM lParam)
{
if(wParam == CChatRecordChildLayout::IDC_BUTTON_COMBOBOX)
{
CSkinComboBox* pComboBox = reinterpret_cast<CSkinComboBox*>(lParam);
}
return 1L;
}