Monday, April 11, 2011

Showing size grip in CDialog?

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?

From stackoverflow
  • 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);
    }
    

    Source: http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.ui/2006-01/msg00103.html

  • 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

0 comments:

Post a Comment