Setting default button programmatically

During program execution, when a certain edit box gets the focus in a dialog, I want that to make a specific button become the default button, so that if the user presses ENTER while the edit box has focus, the button is pressed. I don't want this button to be the default button to start out with, just when this edit box is in focus.  Then the default button can get changed back to the original one, or not - doesn't really matter.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

thresher_sharkConnect With a Mentor Commented:
Answer coming...
To do what you ask, use this:

CButton your_button; // Attach this to your button using classwizard


your_button.SetButtonStyle (BS_DEFPUSHBUTTON); // This will set it as the default button.

First you want to attach a variable of type CButton to your button in the ClassWizard.  Then, place the "SetButtonStyle" code at the point you want to change it to the default button.  If you want to change the default button status back to another button, attach another variable of type CButton to the other button and do the same thing.  If you have additional questions, please feel free to ask.  Thanks!
aaronlAuthor Commented:

only thing to add is that you have to explicitly remove the previously marked default

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Oh, whoops :-)  I didn't even know anything about this function until I looked searched for it the help.  Anyway, I am glad you have it working.
aaronlAuthor Commented:
hey, all apologies for the "good" score as well... I didn't know the system, and someone told me that was worth an excellent.
Oh, that?  It doesn't matter to me as long as you have a solution.  I have enough points as it is :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.