Re: checkbox caption placement

Tech-Archive recommends: Speed Up your PC by fixing your registry



No, not really There is no support for this.

You could create a static control with the caption, set the SS_NOTIFY style, and create a
check box with no caption at all Then you could respond to WM_LBUTTONDOWN events in the
caption by doing something like

void CMyButtonCaption::OnLButtonDown(...)
{
CWnd * buddy = GetWindow(GW_HWNDNEXT);
if(buddy == NULL)
return;

if(buddy->GetCheck() == BST_CHECKED)
buddy->SetCheck(BST_UNCHECKED);
else
buddy->SetCheck(BST_CHECKED);
}

In this case, I set it up so the next window in the Z-order is assumed to be the "buddy"
of the static control, so you would lay down the static control and then the checkbox, or
adjust the Z-order afterward. This also assumes the button is auto-2-state; generalizing
it to 3-state is an Exercise For The Reader.

There are subtler issues such as showing a focus rectangle, having it respond to a tab key
properly, etc.; in this case you would not use CStatic but a control derived from CWnd and
do a fancy OnPaint to handle this.
joe
On 28 Nov 2006 15:47:10 -0800, "mitenko" <mitenko@xxxxxxxxx> wrote:

Hi everyone, hope you're all well.

newbie question: I'm wondering if there's an easy way for setting up
checkboxes so that the caption text ends up above or below the actual
checkbox.

regards,
mitenko
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.


Quantcast