我在Dialog 中定义了十几个button,我把他们 group,由于他们的function基本相同,只是ID不同?怎样能简化? 可以把buttonID放到static UINT group[]={ID_BUTTON1....}; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1) .h文件中,添加 afx_msg void OnButton( UINT id );2) 消息映射中,添加ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON3,OnButton)IDC_BUTTON1最小值IDC_BUTTON3最大值3) 函数的实现:void CMyDlg::OnButton( UINT id ) { CString str; str.Format("id=%d", id); MessageBox(str);} 同意 dyw(旺仔) , 标准方法. 从CButton类中派生出CMyButton类,在CMyButton中重载==运算符。然后,定义一个CMyButton数组m_Button[yourbuttoncount].void CTRCPDemoDlg::OnLButtonDown(UINT nFlags, CPoint point) {// RECT Rect; for (int i=1; i<12; i++) { m_Button[i].GetWindowRect((LPRECT) &Rect);////////<<-------- if (Rect.top < point.y && Rect.left < point.x && Rect.right > point.x &&Rect.bottom > point.y) { TRACE("PanLeft On \n"); m_TRCPObject->buttonPress(i, 0);//根据ID 不同 (i) } CDialog::OnLButtonDown(nFlags, point);}这样应该可以解决问题。如果不是非要在OnLButtonDown中解决问题,更好的解决方法是使用MFC ON_CONTROL_RANGE宏。它将两个以上控件发出的同样的通知映射给共用的通知处理程序。类似的宏还有ON_COMMAND_RANGE宏,它将一组连续的命令ID映射为一个公用处理程序。 关于延迟加载DLL的总结贴,欢迎讨论。 再问HTTP协议的问题? 怎样在一个类中调用另一个类的变量 郁闷、急切中!!如何检测PPT放映时里的画画工具是否安装? vs2008 sp1 保存bar位置 显示jpg 但是闪屏 vc.net中如何把插入资源的图片在资源HTML中显示? 看下我查找对话框的调用,怎么出来一下就没了? 怎么样得到对话框句柄?送分一定.(VC) WINDOWS中让程序休眠n秒钟用哪个函数啊? VC++能使用其他的程序编的.obj文件吗? 如何将ListCtrl的某一行的颜色设置成Highlight,或...
afx_msg void OnButton( UINT id );2) 消息映射中,添加
ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON3,OnButton)
IDC_BUTTON1最小值
IDC_BUTTON3最大值3) 函数的实现:void CMyDlg::OnButton( UINT id )
{
CString str;
str.Format("id=%d", id);
MessageBox(str);
}
然后,定义一个CMyButton数组m_Button[yourbuttoncount].void CTRCPDemoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
//
RECT Rect;
for (int i=1; i<12; i++)
{
m_Button[i].GetWindowRect((LPRECT) &Rect);////////<<--------
if (Rect.top < point.y && Rect.left < point.x &&
Rect.right > point.x &&Rect.bottom > point.y)
{
TRACE("PanLeft On \n");
m_TRCPObject->buttonPress(i, 0);//根据ID 不同 (i)
} CDialog::OnLButtonDown(nFlags, point);
}
这样应该可以解决问题。
如果不是非要在OnLButtonDown中解决问题,更好的解决方法是使用MFC
ON_CONTROL_RANGE宏。它将两个以上控件发出的同样的通知映射给共用的通知
处理程序。类似的宏还有ON_COMMAND_RANGE宏,它将一组连续的命令ID映射为
一个公用处理程序。