VC(在主对话框上捕获按钮等控件上的鼠标消息)

比如。当鼠标移到按钮上时候,需要主对话框上显示出鼠标在哪一个按钮上

BOOL CTextbuttonDlg::PreTranslateMessage(MSG* pMsg) 
{

CRect rectb;
GetDlgItem(IDC_BUTTON_B)
->GetWindowRect(&rectb);
if(rectb.PtInRect(pMsg->pt))
{
//SetDlgItemText(IDC_STATIC_TEXT,"");
CString str;
str
="鼠标在按钮B上";
SetDlgItemText(IDC_STATIC_TEXT,str);
}
// TODO: Add your specialized code here and/or call the base class
CRect rect;
GetDlgItem(IDC_BUTTON_A)
->GetWindowRect(&rect);
if(rect.PtInRect(pMsg->pt))
{
CString str;
str
="鼠标在按钮A上";
SetDlgItemText(IDC_STATIC_TEXT,str);
}

return CDialog::PreTranslateMessage(pMsg);
}这里需要在PreTranslateMessage(pMsg)提前捕获鼠标消息。否则的话按钮控件捕获的鼠标消息,对话框是不知道的

你可能感兴趣的:(对话框)