Advertisement

Buttons with MFC?

Started by June 20, 2000 09:38 AM
5 comments, last by Peter Svensson 24 years, 6 months ago
Hello! I have a problem (don''t we all)... I''m currently trying to make a program in MFC where I need buttons that stay down when they have been clicked. Like a toggle button. If anyone has a pice of code, an idee or somthing else that might help me... please post a message! // Peter - Thanx!
This site has instructions on doing buttons of all shapes, sizes, colors, etc. I'm sure you can use one of the techniques found here, even if it involves using bitmap buttons to get the desired effect.

-fel

Edited by - felisandria on June 20, 2000 11:11:17 AM
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement

yep, codeguru is a nice site. i visit their message board about half of the times that i do this one though... i only go there to ask questions, while here i answer them ...

david
--david@neonstar.netneonstar entertainment
If you are using the resource editor (visually drawing you dialog with the mouse) then you want to use a "check box".
Right click on the check box. Select properties. Then set the "Push-Like" property. Now you have a Push Button that acts like a check box (or toggle). You can do the same for a set of radio buttons.

If you are dynamically creating your GUI at runtime, create a button (using CButton::Create ) and give it the BS_CHECKBOX button style. Of course MSDN has the complete (and accurate) details of how to do this.

The third way is hack up the event handlers for an ordinary button. Decalre BOOL m_bButtonDown; in your dialog class and set it to FALSE in your constructor. Durring the OnButtwhenclickedon event, use this code

if( m_bButtonDown )
{
m_btnYourButton.SetCheck(1); // May cause button to flicker
}
else
{
m_btnYouButton.SetCheck(0);
}
What the hell?
that should read:

"Durring the OnButtwhenclickedon() event"
Ok dumb forum software, you suck
(or maybe I suck at Java script).

Here, I''ll space it out.

O n B u t t o n C l i c k
Advertisement
Hello again!

Thank you for your suggestions!

For others who also wonder about this, here is how i solved the problem. I derived a CButton class and created it with the OWNERDRAW style. I put a status variable in the class to keep track if it has been pressed or not (for what bitmap to be drawn). It works fine, but i''m sure i will try the neat stuff Marsupial Rodentia mentioned above.

// Peter - Thanx!

This topic is closed to new replies.

Advertisement