Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:52:36+00:00 2026-05-23T07:52:36+00:00

Language: C++ Development Environment: Microsoft Visual C++ Libraries Used: MFC Pretty new to MFC,

  • 0

Language: C++

Development Environment: Microsoft Visual C++

Libraries Used: MFC

Pretty new to MFC, so bear with me. I have a dialog that is launched via DoModal(). I’m attempting to add buttons to this dialog that will replace the default “OK” and “Cancel” buttons. Right now, I can’t quite figure out how to do this. I deleted the OK and Cancel buttons and added new ones with new IDs, added event handlers, and just some simple code for them to execute upon being pressed, but I couldn’t get it to work.

I suspect it has something to do with the fact that DoModal() expects responses from OK or Cancel, but nothing else. I’m not really sure though. Any help would be greatly appreciated!

EDIT: Stripped down code added for reference.

void CPrefsDlg::Launch() {

[ ... ]

  CSAPrefsDialog dlg;

  INT_PTR nRet = -1;
  nRet = dlg.DoModal();

  // Handle the return value from DoModal
  switch ( nRet )
  {
  case -1: 
     AfxMessageBox("Dialog box could not be created!");
     break;
  case IDABORT:
     // Do something
     break;
  case IDOK: // This works just fine.
     exit(0);
     break;
  case IDSAVEONE: // This does not work.
     MessageBox("Save One");
     break;
  default:
     break;
  };
}

void CPrefsDlg::SaveOne()
{
// I tried adding in my own handler for 'Save One'...this does not work.
MessageBox("Save one");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:52:36+00:00Added an answer on May 23, 2026 at 7:52 am

    To wire up your dialog to terminate and return IDSAVEONE, you need to add a click handler to the Save One button and have it call EndDialog:

    void CSAPrefsDialog::OnBnClickedSaveone()
    {
        EndDialog(IDSAVEONE);
    }
    

    If you add the click handler through the dialog editor (e.g. by double-clicking on your button) then the necessary framework code will be generated for you to wire this up; otherwise you’ll need to add the following line into your BEGIN_MESSAGE_MAP section in your dialog class:

    ON_BN_CLICKED(IDSAVEONE, &CSAPrefsDialog::OnBnClickedSaveone)
    

    but (as AJG85’s just beaten me to posting) depending on what the operation is, how fast it is and whether you want to report errors in the preferences dialog or not, you may want to just carry out the extra function in your on-clicked handler instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Language : C++ Development Environment : Microsoft Visual C++ Libraries Used : MFC Problem
I heard that C# is a rapid application development (RAD) language. Even after reading
.NET Framework: 2.0 Preferred Language: C# I am new to TDD (Test Driven Development).
Which programming language is it easier to support developers in (namely developers that have
Ubuntu 10.04 64-bit looks promising as a development environment for Android. I now have
If Delphi is the primary language for my development, what is the ideal complement
I am planning to participate in development of a code written in C language
Hi I'm looking into iPhone development, and Objective-C is not be my preferred language.
I am very interested in mobile application development. But which language or framework is
What book would you recommend to learn test driven development? Preferrably language agnostic.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.