Mostrando tamaño de agarre en CDialog?
Pregunta
He visto un código que maneja el dibujo de esta cosa ( DFCS_SCROLLSIZEGRIP
), pero seguramente hay un estilo de ventana que puedo solicitar para obtenerlo " gratis " ;. Derecho?
Solución
En lugar de una mejor respuesta, publicaré el código que tengo que dibuja el control de tamaño y maneja la prueba de impacto. También debe invalidar el área apropiada durante el tamaño de OnSize para volver a pintarlo.
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);
}
Otros consejos
No creo que haya un estilo predeterminado para obtener esta funcionalidad de forma gratuita. Debe crear una nueva ventana secundaria con el nombre de clase Scrollbar
y el estilo de control SBS_SIZEGRIP
Además de OnEraseBkgnd y OnNcHitTest mencionados anteriormente, tendrá que invalidar el área de agarre cuando la ventana tenga el tamaño adecuado, de lo contrario dejará marcas cuando se amplíe:
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);
}