我在.h中添加了
//{{AFX_MSG(CSelDialogBar)
// NOTE: the ClassWizard will add member functions here
virtual void OnSelMsg(UINT nID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
在.cpp中添加了BEGIN_MESSAGE_MAP(CSelDialogBar, CDialog)
//{{AFX_MSG_MAP(CSelDialogBar)
// NOTE: the ClassWizard will add message map macros here
ON_COMMAND_RANGE(IDC_SEL_A, IDC_SEL_A27, OnSelMsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()为什么按钮出来都是灰的不可选呀?谢谢。
//{{AFX_MSG(CSelDialogBar)
// NOTE: the ClassWizard will add member functions here
virtual void OnSelMsg(UINT nID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
在.cpp中添加了BEGIN_MESSAGE_MAP(CSelDialogBar, CDialog)
//{{AFX_MSG_MAP(CSelDialogBar)
// NOTE: the ClassWizard will add message map macros here
ON_COMMAND_RANGE(IDC_SEL_A, IDC_SEL_A27, OnSelMsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()为什么按钮出来都是灰的不可选呀?谢谢。
ClassWizard does not support message map ranges, so you must place the macro yourself. Be sure to put it outside the message map 。
映射申明必须放到message map的外部。你放在了里面,就不可以了。
例子:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// ...
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()
问题解决了1。打开resource.h,需要Range的ID的索引必须是连续的,因为在编辑ID的时候,如果修改过,或者中间插入过其他ID,则ClassWizard可能会产生不连续的ID,此时在范围之外的ID的按钮就变成灰色了。
2。需要Rebuild项目