Archived

This topic is now archived and is closed to further replies.

Peter Svensson

Buttons with MFC?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites