Getting the rect of the text in a Static
-
To get the rect of the control or of the text itself? // Control: CRect oR; CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetWindowRect(&oR); ScreenToClient(&oR); // bounding rectangle of static's text contents CString cText; GetDlgItemText(IDC_THE_STATIC_CTRL,cText); CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetClientRect(&oR); CDC *pDC = pStatic->GetDC(); pDC->DrawText(cText,&oR,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_TOP); pStatic->ReleaseDC(pDC); // oR now has the bounding rectangle needed to display the text. onwards and upwards...
-
To get the rect of the control or of the text itself? // Control: CRect oR; CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetWindowRect(&oR); ScreenToClient(&oR); // bounding rectangle of static's text contents CString cText; GetDlgItemText(IDC_THE_STATIC_CTRL,cText); CWnd *pStatic = GetDlgItem(IDC_THE_STATIC_CTRL); pStatic->GetClientRect(&oR); CDC *pDC = pStatic->GetDC(); pDC->DrawText(cText,&oR,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_TOP); pStatic->ReleaseDC(pDC); // oR now has the bounding rectangle needed to display the text. onwards and upwards...
-
Wouldn't it be better to just make a memDC so the text itself won't show up on the control (it's already there ofcourse)? Or doesn't it do this anyway?
With the DT_CALCRECT the drawtext does not go to the screen it just calculates the rect. John
-
With the DT_CALCRECT the drawtext does not go to the screen it just calculates the rect. John