Showing size grip in CDialog?
Question
I have seen code which handles the drawing of this thing (DFCS_SCROLLSIZEGRIP
), but surely there is a window style which I can apply to get it "for free". Right?
Solution
In lieu of a better answer, I will post the code I have that draws the size grip and handles the hit-testing. You also need to invalidate the appropriate area during OnSize in order to get it repainted.
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
if (CDialog::OnEraseBkgnd(pDC))
{
// draw size grip
CRect r;
GetClientRect(&r);
int size = GetSystemMetrics(SM_CXVSCROLL);
r.left = r.right - size;
r.top = r.bottom - size;
pDC->DrawFrameControl(&r, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
return TRUE;
}
else
{
return FALSE;
}
}
-
LRESULT CMyDialog::OnNcHitTest(CPoint point)
{
// return HTBOTTOMRIGHT for sizegrip area
CRect r;
GetClientRect(&r);
int size = GetSystemMetrics(SM_CXVSCROLL);
r.left = r.right - size;
r.top = r.bottom - size;
ScreenToClient(&point);
if (r.PtInRect(point))
{
return HTBOTTOMRIGHT;
}
else
return CDialog::OnNcHitTest(point);
}
OTHER TIPS
I don't think there is a default style to get this functionality for free. You have to create a new child window with class name Scrollbar
and control style SBS_SIZEGRIP
In addition to OnEraseBkgnd and OnNcHitTest mentioned by the above you will need to invalidate the grip area when the window sized, otherwise it will leave marks when enlarged:
void CMyDialog::OnSize(UINT nType, INT cx, INT cy)
{
CRect rc;
int iSize=GetSystemMetrics(SM_CXVSCROLL);
GetClientRect(rc);
InvalidateRect(CRect(rc.left-iSize, rc.bottom-iSize, rc.right, rc.bottom), FALSE);
CDialog::OnSize(nType, cx, cy);
}