// TODO: Return a different brush if the default is not desired if (TRUE == m_b) { CRect rect; GetDlgItem(IDC_EDIT1)->GetClientRect(rect); CClientDC dc(GetDlgItem(IDC_EDIT1));
CBrush brush(RGB(255,0,0)); dc.FillRect(rect,&brush); } return hbr; }BOOL CEditcolorDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message==WM_LBUTTONDOWN) { return FALSE; } return CDialog::PreTranslateMessage(pMsg); }void CEditcolorDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRect rc; GetDlgItem(IDC_EDIT1)->GetClientRect(rc); ClientToScreen(rc); InvalidateRect(rc); if (rc.PtInRect(point)) { m_b = TRUE; } CDialog::OnLButtonDown(nFlags, point); } 你看看我的代码对不对,点击edit控件进不到OnLButtonDown函数里去啊?
我的意思是你把OnLButtonDown的处理放到PreTranslateMessage中去做
BOOL CXXDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1); ASSERT(pEdit); if((pEdit->GetSafeHwnd() == pMsg->hwnd) && (WM_LBUTTONDOWN == pMsg->message)) { CRect rect; pEdit->GetWindowRect(&rect); if(rect.PtInRect(pMsg->pt)) { AfxMessageBox(_T("In Edit")); } } return CDialog::PreTranslateMessage(pMsg); }
if (pMsg->wParam==WM_LBUTTONDOWN)
{
return FALSE;
}
好像还是不行啊
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired if (TRUE == m_b)
{
CRect rect;
GetDlgItem(IDC_EDIT1)->GetClientRect(rect);
CClientDC dc(GetDlgItem(IDC_EDIT1));
CBrush brush(RGB(255,0,0));
dc.FillRect(rect,&brush); }
return hbr;
}BOOL CEditcolorDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_LBUTTONDOWN)
{
return FALSE;
}
return CDialog::PreTranslateMessage(pMsg);
}void CEditcolorDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
GetDlgItem(IDC_EDIT1)->GetClientRect(rc);
ClientToScreen(rc);
InvalidateRect(rc);
if (rc.PtInRect(point))
{
m_b = TRUE;
}
CDialog::OnLButtonDown(nFlags, point);
}
你看看我的代码对不对,点击edit控件进不到OnLButtonDown函数里去啊?
{
// TODO: Add your specialized code here and/or call the base class
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
ASSERT(pEdit);
if((pEdit->GetSafeHwnd() == pMsg->hwnd) && (WM_LBUTTONDOWN == pMsg->message))
{
CRect rect;
pEdit->GetWindowRect(&rect);
if(rect.PtInRect(pMsg->pt))
{
AfxMessageBox(_T("In Edit"));
}
}
return CDialog::PreTranslateMessage(pMsg);
}