Setting default button programmatically

Posted on 1998-12-29
Last Modified: 2013-11-20
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.
Question by:aaronl
  • 4
  • 2

Accepted Solution

thresher_shark earned 70 total points
ID: 1326938
Answer coming...

Expert Comment

ID: 1326939
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!

Author Comment

ID: 1326940

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


Expert Comment

ID: 1326941
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.

Author Comment

ID: 1326942
hey, all apologies for the "good" score as well... I didn't know the system, and someone told me that was worth an excellent.

Expert Comment

ID: 1326943
Oh, that?  It doesn't matter to me as long as you have a solution.  I have enough points as it is :-)

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question