C++/VB - Custom non-client area and minimize and close buttons

Asked By BillA on 10-May-07 09:54 AM
We are making a skinned application for XP and need to implement the
minimize and close buttons.  I was under the impression that I just
had to handle WM_NCHITTEST and return HTMINBUTTON to indicate that the
mouse is in the minimize button.  After that, the system would handle
the WM_NCLBUTTONDOWN/UP messages and fire the WM_SYSCOMMAND message to
minimize/close the window, but that does not seem to be the case.

Do we need to implement WM_NCLBUTTONDOWN/UP and fire the WM_SYSCOMMAND
messages myself?

Excuse the magic numbers; i am just trying to get this to work right
now.

Here is my WTL code:

LRESULT CMainDlg::OnNCHitTest(CPoint pt)
{
// need to subtract window origin from x and y
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);

BOOL check = GetWindowPlacement(&wp);

pt.x = pt.x - wp.rcNormalPosition.left;
pt.y = pt.y - wp.rcNormalPosition.top;

CRect minBtnRect(0, 0, 16, 17);
minBtnRect.MoveToXY(1246, 5);

CRect closeBtnRect(0, 0, 16, 17);
closeBtnRect.MoveToXY(minBtnRect.right + 2, 5);
if(minBtnRect.PtInRect(pt))
{
return HTMINBUTTON;
}
else if (closeBtnRect.PtInRect(pt))
{
return HTCLOSE;
}
else if(CRect(1, 1, 1279, 27).PtInRect(pt))
{
return HTCAPTION;
}

return HTCLIENT;
}

void CMainDlg::OnNCPaint(HRGN rgn)
{
}

LRESULT CMainDlg::OnNCActivate(BOOL active)
{
return 1;
}


Christian ASTOR replied on 11-May-07 02:22 AM
e.g. WM_NCLBUTTONDOWN (PtInRect(), SetCapture()) + WM_LBUTTONUP
(ReleaseCapture(), SW_MINIMIZE)
BillA replied on 15-May-07 05:28 PM
Yeah.  I figured that out after using Spy++.  Strange that there is
not WM_NCLBUTTONUP after the WM_NCLBUTTONDOWN.

But I thought that just returning HTMINBUTTON would cause the default
window procedure/dialog procedure to close the window.