Creating a Button in a Button 
Author Message
 Creating a Button in a Button

Is it possible to create a button in another button? More
specifically, I need to display a checkbox in an ActiveX Control
subclassing class "Button".

A first and blunt attempt at this resulted in my checkbox not
displaying (I explicitly called ShowWindow).

I haven't done much GDI/MFC, but the way I understand it, controls
like buttons, comboboxes, etc are drawn by the parent window.

I can see two possibilities why this could or couldn't work:

- my ActiveX control, being a control, does not expect to have to draw
any childs, so it never checks for any childs to draw.

- It could work because an ActiveX control is also a Window, and as
such can possess childs.

Thank you,



Sat, 03 Dec 2005 15:15:10 GMT  
 Creating a Button in a Button
Yes, you can do this. It is weird, but you can do it. I wouldn't guarantee the results if
the parent button is not owner-draw.

Controls are not drawn by the parent; they are drawn by the control itself. The
"owner-draw" designation would suggest the control is drawn by the parent; this can be
done, but it is colossally stupid, and the design of this was exceptionally poor.
Fortunately, in MFC, you can mark a class as "owner-draw", but add a DrawItem method, and
MFC will "reflect" the WM_DRAWITEM message from the parent to the child (which is how
Windows should have been designed!), and so you now have what is the correct approach, a
"self-draw" button.

But adding something like this retrospecifively is asking for trouble, particularly if you
can't control the parent window's drawing. You will have fewer problems if you create the
button in your ActiveX control with the WS_CLIPCHILDREN style. After that, it is pure
conjecture as to how successful this might be. I've put buttons, check boxes,
radiobuttons, edit controls, and combo boxes in as child controls of a CListBox, and it
required I handle a lot of odd redraw cases "properly".

As you point out, any window can have a child window. The real issue is how well the
window cooperates with you in dealing with the child window (for example, clicking the
child button sends the message to the parent button; if you want it to go higher, you have
to do that yourself).
                                joe


Quote:
>Is it possible to create a button in another button? More
>specifically, I need to display a checkbox in an ActiveX Control
>subclassing class "Button".

>A first and blunt attempt at this resulted in my checkbox not
>displaying (I explicitly called ShowWindow).

>I haven't done much GDI/MFC, but the way I understand it, controls
>like buttons, comboboxes, etc are drawn by the parent window.

>I can see two possibilities why this could or couldn't work:

>- my ActiveX control, being a control, does not expect to have to draw
>any childs, so it never checks for any childs to draw.

>- It could work because an ActiveX control is also a Window, and as
>such can possess childs.

>Thank you,

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Sat, 03 Dec 2005 16:58:43 GMT  
 Creating a Button in a Button

Quote:

>Is it possible to create a button in another button? More
>specifically, I need to display a checkbox in an ActiveX Control
>subclassing class "Button".

>A first and blunt attempt at this resulted in my checkbox not
>displaying (I explicitly called ShowWindow).

>I haven't done much GDI/MFC, but the way I understand it, controls
>like buttons, comboboxes, etc are drawn by the parent window.

It's true that the parent of an ownerdraw control receives WM_DRAWITEM
messages, but it's common in MFC apps for that message to be reflected to
the child, which then draws itself.

Quote:
>I can see two possibilities why this could or couldn't work:

>- my ActiveX control, being a control, does not expect to have to draw
>any childs, so it never checks for any childs to draw.

>- It could work because an ActiveX control is also a Window, and as
>such can possess childs.

If the button can have child windows, your best bet is to make your checkbox
a child. You might have to give it the WS_EX_TRANSPARENT style, so clicks on
it pass through to the button, and you might have to give the parent the
WS_CLIPCHILDREN style. If you still run into owerdraw issues, you can derive
your checkbox from CWnd and handle everything yourself. Why do you want to
do this anyway? It seems a little odd to show a checkbox in a button. Of
course, if the button is a BS_GROUPBOX, you may just have a Z-order problem,
which you can solve with SetWindowPos.

--
Doug Harrison
Microsoft MVP - Visual C++



Sat, 03 Dec 2005 17:09:03 GMT  
 Creating a Button in a Button
Thanks to both for clarifying the draw event reflection regarding the
parent-child control relationship.

My control was being clipped because I positionned too far.

WS_EX_TRANSPARENT is a good call!

Quote:
> WS_CLIPCHILDREN style. If you still run into owerdraw issues, you can derive
> your checkbox from CWnd and handle everything yourself. Why do you want to
> do this anyway? It seems a little odd to show a checkbox in a button.

Yes, it is weird. To answer your question, it's for an embedded device
that has keys around its LCD (like bank tellers), and people want to
be able to place a button on the edge of the screen and have that
button pointing towards the physical key. So the button is like so:

(if you're in monotype)
  ___
 /   |
/    |
\    |
 \_ _|

And in the case of a checkbox, such a button would contain a checkbox
indicating that the "pointed to" physical key will toggle the checkbox
on and off.

Thanks for your help.



Sun, 04 Dec 2005 16:21:43 GMT  
 Creating a Button in a Button

Quote:

>Yes, it is weird. To answer your question, it's for an embedded device
>that has keys around its LCD (like bank tellers), and people want to
>be able to place a button on the edge of the screen and have that
>button pointing towards the physical key. So the button is like so:

>(if you're in monotype)
>  ___
> /   |
>/    |
>\    |
> \_ _|

>And in the case of a checkbox, such a button would contain a checkbox
>indicating that the "pointed to" physical key will toggle the checkbox
>on and off.

>Thanks for your help.

Thanks for the explanation. Glad you got it working.

--
Doug Harrison
Microsoft MVP - Visual C++



Sun, 04 Dec 2005 17:05:58 GMT  
 Creating a Button in a Button
In that case, I'd suggest that the checkbox is inappropriate. Since you already have an
owner-draw button, just display an image of a check box on it! No need to introduce a
child control. You can either use one of the built-in bitmaps already supplied for this,
or create your own pair of bitmaps and display one or the other depending on the style you
want. What you appear to have done here is add unnecessary complexity to a simple problem.
                                joe

Quote:
>Thanks to both for clarifying the draw event reflection regarding the
>parent-child control relationship.

>My control was being clipped because I positionned too far.

>WS_EX_TRANSPARENT is a good call!

>> WS_CLIPCHILDREN style. If you still run into owerdraw issues, you can derive
>> your checkbox from CWnd and handle everything yourself. Why do you want to
>> do this anyway? It seems a little odd to show a checkbox in a button.

>Yes, it is weird. To answer your question, it's for an embedded device
>that has keys around its LCD (like bank tellers), and people want to
>be able to place a button on the edge of the screen and have that
>button pointing towards the physical key. So the button is like so:

>(if you're in monotype)
>  ___
> /   |
>/    |
>\    |
> \_ _|

>And in the case of a checkbox, such a button would contain a checkbox
>indicating that the "pointed to" physical key will toggle the checkbox
>on and off.

>Thanks for your help.

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Sun, 04 Dec 2005 18:26:26 GMT  
 Creating a Button in a Button

Quote:
> In that case, I'd suggest that the checkbox is inappropriate. Since you already have an
> owner-draw button, just display an image of a check box on it! No need to introduce a
> child control. You can either use one of the built-in bitmaps already supplied for this,
> or create your own pair of bitmaps and display one or the other depending on the style you
> want. What you appear to have done here is add unnecessary complexity to a simple problem.

That's what I initially wanted to do, but I didn't know where to find
the checkbox on/off bitmaps. As for providing my own bitmaps, the only
problem with that is that if the microsoft common controls are updated
with a new look (as is often the case), since I will be using my own
bitmaps, the look of my control will be out of sync.

This way at least, I won't need an update if anything changes.

Also, the other advantage is that if new skins are installed (this is
an ActiveX control for windows CE by the way) I don't need to update
my control to keep the "look" on sync with the rest.

Also, having a child control isn't that complicated, it's just that
I'm not too much of an MFC programmer, so I'm sure I would have run in
other problems should I have chosen the bitmap approach.



Mon, 05 Dec 2005 08:11:47 GMT  
 Creating a Button in a Button
stingelf,

You might want to check the Marlett font (included in Windows), which is
made for drawing scalable checkboxes etc.

Johan Rosengren
Abstrakt Mekanik AB


Quote:
> > In that case, I'd suggest that the checkbox is inappropriate. Since you
already have an
> > owner-draw button, just display an image of a check box on it! No need
to introduce a
> > child control. You can either use one of the built-in bitmaps already
supplied for this,
> > or create your own pair of bitmaps and display one or the other

depending on the style you
Quote:
> > want. What you appear to have done here is add unnecessary complexity to
a simple problem.

> That's what I initially wanted to do, but I didn't know where to find
> the checkbox on/off bitmaps. As for providing my own bitmaps, the only
> problem with that is that if the microsoft common controls are updated
> with a new look (as is often the case), since I will be using my own
> bitmaps, the look of my control will be out of sync.

> This way at least, I won't need an update if anything changes.

> Also, the other advantage is that if new skins are installed (this is
> an ActiveX control for windows CE by the way) I don't need to update
> my control to keep the "look" on sync with the rest.

> Also, having a child control isn't that complicated, it's just that
> I'm not too much of an MFC programmer, so I'm sure I would have run in
> other problems should I have chosen the bitmap approach.



Mon, 05 Dec 2005 19:20:05 GMT  
 Creating a Button in a Button
You don't actually need them, of course; you could simply draw the bitmaps yourself. Also,
"zoomin" can capture any screen image, and you can edit that to your heart's content.

Given this is a dedicated application, keeping consistency with the latest version, or
with skins, seems a bit pointless.

Skins are one of those really bad ideas that contributes "coolness" without any content at
all.

I actually show all this in our book, "Win32 Programming", OBM_CHECKBOXES is the complete
set of checkbox bitmaps. For NT4, it is arranged as a 4-wide, 3-high array, arranged as
follows

ABCD
EFGH
JKLM

where
A is an unchecked checkbox
B is a checked checkbox
C is an unchecked disabled checkbox
D is a checked disabled checkbox
E is an unchecked radio button
F is a checked radio button
G is an unchecked disabled radio button
H is a checked disabled radio button
J is a checked radio button in a checkbox square
K is appears to be the same as C
L is a light gray check in a disabled-checkbox
M is a dark gray check in a disabled-checkbox

To use these, you do LoadBitmap specifying OBM_CHECKBOXES, and you must do
#define OEMRESOURCE
in your stdafx.h before the #include of any file, otherwise the symbol is undefined.

Also, you could use characters from the WingDings font, which I believe is standard in all
Windows installations.
                                        joe


Quote:
>> In that case, I'd suggest that the checkbox is inappropriate. Since you already have an
>> owner-draw button, just display an image of a check box on it! No need to introduce a
>> child control. You can either use one of the built-in bitmaps already supplied for this,
>> or create your own pair of bitmaps and display one or the other depending on the style you
>> want. What you appear to have done here is add unnecessary complexity to a simple problem.

>That's what I initially wanted to do, but I didn't know where to find
>the checkbox on/off bitmaps. As for providing my own bitmaps, the only
>problem with that is that if the microsoft common controls are updated
>with a new look (as is often the case), since I will be using my own
>bitmaps, the look of my control will be out of sync.

>This way at least, I won't need an update if anything changes.

>Also, the other advantage is that if new skins are installed (this is
>an ActiveX control for windows CE by the way) I don't need to update
>my control to keep the "look" on sync with the rest.

>Also, having a child control isn't that complicated, it's just that
>I'm not too much of an MFC programmer, so I'm sure I would have run in
>other problems should I have chosen the bitmap approach.

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Mon, 05 Dec 2005 23:36:13 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. how to create a window without any close button (include OK button and X button)

2. buttons, check buttons, radio buttons, and such...

3. Dialog Box two OK buttons, two Cancel buttons and TODO still on it

4. MSVC 1.52 button disable with owner draw buttons

5. Drawing a button, that's not really a button

6. toolbar buttons with combo buttons not getting ON_UPDATE_COMMAND_UI messages

7. Button colour & Detecting mouse over button

8. check a single radio button in a radio-button-group

9. Accessing all other buttons with Context-help button in an SDI

10. Click 1 button = click 2 button?

11. How to make Cancel button not default button on Wizard Page

12. Ownerdrawn button or scratch button?

 

 
Powered by phpBB® Forum Software