In my application, I am using a custom control that is a GroupBox and a CheckBox instead of a common caption. I got the control here: http://www.codeguru.com/cpp/cpp/cpp_...icle.php/c4149
I had to change the code to allow the checkbox to have multiline text:
Code:
CRect rc;
GetWindowRect(rc); // Get the rect of the GroupBox
this->ScreenToClient(rc);
// Change rc to be used for the checkbox
rc.left += 5;
rc.right = min(rc.left + czText.cx, rc.right - 5);
int iGroupBoxWidth = rc.right - rc.left;
double iLinesCount = ceil((double)czText.cx / iGroupBoxWidth);
rc.top -= (long)((iLinesCount - 1) * czText.cy / 2);
rc.bottom = (long)(rc.top + czText.cy * iLinesCount);
if(style == BS_AUTOCHECKBOX)
{
m_TitleBox.Create(strText, BS_AUTOCHECKBOX | BS_MULTILINE | WS_CHILD | WS_TABSTOP, rc, this, ID_TITLE);
}
As you can see, I change rc.top to have the middle of the checkbox neatly on the same level as the top edge of the groupbox, as in case of single-line caption. The multiline caption should be spread equally over and under that level. I can see that the checkbox is in the right place, so the top of the caption is calculated correctly, but the upper part of the caption text is cut off. I can see the caption not higher than the upper edge of the checkbox. Could you please tell me why this happens?
I have attached an image to show how it looks.
Thanks.
Last edited by dpreznik; February 9th, 2011 at 04:22 PM.
you're changing the top of where you are painting the text, but that just makes you write outside of the window rectangle. That isn't going to work properly since it's getting clipped.
Even if you "fix" the clipping in the DC before the paint may make it "sometimes" work, but repainting won't work properly if the area outside of your control gets invalidated for some reason. In that case the top will still be sliced off as it is now.
don't write outside of your window.
If you need more room "at the top", then you can't change just the top. Instead, you need to move everything inside the window downwards and adjust accordingly.
Thank you very much for your answer. I am not sure I understand whether it would help to change the GroupBox window's rectangle. If yes, could you please give me an example how I could do it? I tried myself, but didn't succeed. And I am not concerned now with overlapping the GroupBox content.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.