Tuesday, April 11, 2006

prevent non-client clicks from pausing app

The following works, provided the "Show window contents while dragging" system property is unchecked. The only side effects are a) left-clicking on the menu bar moves the cursor to the center of the menu bar (strange, but not really a problem), and b) close happens on button down instead of button up.

void CPersistDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
switch (nHitTest) {
case HTCLOSE:
SendMessage(WM_SYSCOMMAND, SC_CLOSE, 0);
break;
case HTCAPTION:
SendMessage(WM_SYSCOMMAND, SC_MOVE, 0);
break;
default:
CDialog::OnNcLButtonDown(nHitTest, point);
break;
}
}

void CPersistDlg::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
switch (nHitTest) {
case HTCAPTION:
case HTSYSMENU:
SendMessage(WM_CONTEXTMENU, (LONG)m_hWnd, MAKELONG(point.x, point.y));
break;
default:
CDialog::OnNcRButtonDown(nHitTest, point);
break;
}
}

No comments: