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 8474695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:41:43+00:00 2026-06-10T17:41:43+00:00

my environment is C++, MFC, compact-framework for WM 6.0+ devices. In many places, I

  • 0

my environment is C++, MFC, compact-framework for WM 6.0+ devices.

In many places, I am showing pop-up messages using ‘MessageBox()’ to give a simple warning or get Yes/No repsonse from user. What I want to do is that whenever any message is closed, call some common function before I perform specific codes.

I tried WM_SHOWWINDOW in parent window but it doesn’t seem to occur.

Any suggestion will be appreciated.

[Added] my screen has many buttons and I have to make sure only one button is focused all the time. When I show message box, button seems to loose its focus so I want to focus it back when message is closed. Of course, I can do it in every place where message is used but looking for a better way to handle this situation.

  • 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-06-10T17:41:44+00:00Added an answer on June 10, 2026 at 5:41 pm

    The MessageBox function returns specific return codes when it is closed, you can wrap the MessageBox function and check the return values and run some code based on that.

    Here are the return codes from MSDN :

    IDABORT    3    The Abort button was selected.
    IDCANCEL    2    The Cancel button was selected.
    IDCONTINUE    11    The Continue button was selected.
    IDIGNORE    5    The Ignore button was selected.
    IDNO    7    The No button was selected.
    IDOK    1    The OK button was selected.
    IDRETRY    4    The Retry button was selected.
    IDTRYAGAIN    10    The Try Again button was selected.
    IDYES    6    The Yes button was selected.
    

    So the following code can be used to run different functions based on the return code.

    void MyMessageBox(wstring title,wstring message)
    {
      int msgboxID = MessageBox(
           NULL,
           (LPCWSTR)message.c_str(),
           (LPCWSTR)title.c_str(),
           MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
       );
    
     switch (msgboxID)
     {
        case IDCANCEL:
            // TODO: add code
            break;
        case IDTRYAGAIN:
            // TODO: add code
            break;
        case IDCONTINUE:
            // TODO: add code
            break;
        //so on
     }
    }
    

    More info here :
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx

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

Sidebar

Related Questions

Currently all our GUI components are written in MFC. Our build environment is: VC
Environment I am using the native document management integration between Microsoft Dynamics CRM 2011
To think ... there I have been happily programming in an MFC riddled environment
[Environment] Windows 7 Ultra VS 2010 Ultra Entity Framework 4.2 Entity Framework Power Tool
Language: Visual C++, MFC Environment: Visual Studio 2005 I have a dialog that requires
Language : C++ Development Environment : Microsoft Visual C++ Libraries Used : MFC Problem
Environment: Server : Jboss 4.2.3.GA We are using c3p0 0.9.1.2 for connection pooling. Whenever
Environment - C#, .net 4.0, VS 2010 Hello, I have written a simple shell
I am trying to setup Agile and TDD environment for MFC applications that require
Environment: Win XP, Visual C++ I'm using the pthread_win32 library in order to implement

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.