关闭

同一类消息或命令映射到同一个函数

237人阅读 评论(0) 收藏 举报
共有三类:
ON_COMMAND_RANGE
ON_UPDATE_COMMAND_UI_RANGE
ON_CONTROL_RANGE // takes an additional first parameter: a control-notification message, such as EN_CHANGE.


第一步:
In the .CPP file, add your message-map entry, as shown in the following example:


ON_COMMAND_RANGE(ID_MYCMD_ONE, ID_MYCMD_TEN, &OnDoSomething) //The range of command IDs must be contiguous.
ON_COMMAND_RANGE(ID_COMMAND_RANGECMD1, ID_COMMAND_RANGECMD3, &CChildFrame::OnRangeCmds)
 
ON_UPDATE_COMMAND_UI_RANGE(id1, id2, memberFxn )


ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON1, IDC_BUTTON10, OnButtonClicked) //control-notification messages


第二步:
Add your handler function declaration in the .H file. The following code shows how this might look, as shown below:


public:


afx_msg void OnDoSomething(UINT nID);(== OnButtonClicked)
   
void CRangesView::OnButtonClicked( UINT nID )
{
    int nButton = nID - IDC_BUTTON1;
    ASSERT( nButton >= 0 && nButton < 10 );
    // ...
}
   


afx_msg void OnZoomUpdateUI(CCmdUI *pCmdUI); //图像放缩 更新


void CVCStyleView::OnZoomUpdateUI( CCmdUI *pCmdUI )
{
if (pCmdUI->m_nID == ID_Z00M_25)
{
if (m_zoom == -4)
{
pCmdUI->SetCheck(1);
}else
{
pCmdUI->SetCheck(0);
}

}
if (pCmdUI->m_nID == ID_ZOOM_50)
{
if (m_zoom == -2)
{
pCmdUI->SetCheck(1);
}else
{
pCmdUI->SetCheck(0);
}
}
if (pCmdUI->m_nID == ID_ZOOM_100)
{
if (m_zoom == 1)
{
pCmdUI->SetCheck(1);
}else
{
pCmdUI->SetCheck(0);
}
}
if (pCmdUI->m_nID == ID_ZOOM_200)
{
if (m_zoom == 2)
{
pCmdUI->SetCheck(1);
}else
{
pCmdUI->SetCheck(0);
}
}
if (pCmdUI->m_nID == ID_ZOOM_400)
{
if (m_zoom == 4)
{
pCmdUI->SetCheck(1);
}else
{
pCmdUI->SetCheck(0);
}
}
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:202533次
    • 积分:3468
    • 等级:
    • 排名:第9621名
    • 原创:93篇
    • 转载:348篇
    • 译文:0篇
    • 评论:12条
    最新评论