none
How can i show messagebox in visual C++?

    Frage

  • how can i show any text with message box in Visual Studio Team system C++? I can this in C#; like this : MessageBox.Show("Any text here"); but i couldn't this one in C++? Please help me...!!!

    Thanks;

    Mittwoch, 16. November 2011 04:34

Antworten

  • MessageBox(0, "And text here", "MessageBox caption", MB_OK);

    The example I gave is plain Win32 API. See here:

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



    • Bearbeitet Bordon Mittwoch, 16. November 2011 06:05
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Mittwoch, 16. November 2011 06:05
  • >I can this in C#; like this :
    >MessageBox.Show("Any text here");
    >but i couldn't this one in C++?

    In C++/CLI (including WinForms) you can do this:

    MessageBox::Show("Any text here");

    or this:

    MessageBox::Show("CLR MessageBox", "MessageBox Test",
      MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

    - Wayne
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Mittwoch, 16. November 2011 06:14
  • Hi Tanruberdi,

    Welcome to the MSDN Forum.

    Here are some samples in C++ applications of MessageBox for you, please refer to them for help:
    1->In win32 Windows Application:

    MessageBox(NULL, _T("Open the message box "),_T("message"),MB_OK|MB_SYSTEMMODAL);
    
    

    2->In C++/CLI windows application:

    MessageBox::Show("The operation has been completed ","Notification", MessageBoxButtons::OKCancel,MessageBoxIcon::Asterisk);
    if (MessageBox::Show("Do you want to exit?","My Application", MessageBoxButtons::YesNo,MessageBoxIcon::Question)==::DialogResult::Yes)
    {
    Application::Exit();
    }
    

    3->In MFC application:

    AfxMessageBox(_T("first message box"));
    AfxMessageBox(_T("do you want to leave?", MB_YESNO|MB_ICONSTOP);
    
    

    Best regards,
    Helen


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    • Bearbeitet Helen Zhao Freitag, 18. November 2011 01:52
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Freitag, 18. November 2011 01:51

Alle Antworten

  • MessageBox(0, "And text here", "MessageBox caption", MB_OK);

    The example I gave is plain Win32 API. See here:

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



    • Bearbeitet Bordon Mittwoch, 16. November 2011 06:05
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Mittwoch, 16. November 2011 06:05
  • >I can this in C#; like this :
    >MessageBox.Show("Any text here");
    >but i couldn't this one in C++?

    In C++/CLI (including WinForms) you can do this:

    MessageBox::Show("Any text here");

    or this:

    MessageBox::Show("CLR MessageBox", "MessageBox Test",
      MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

    - Wayne
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Mittwoch, 16. November 2011 06:14
  • Hi Tanruberdi,

    Welcome to the MSDN Forum.

    Here are some samples in C++ applications of MessageBox for you, please refer to them for help:
    1->In win32 Windows Application:

    MessageBox(NULL, _T("Open the message box "),_T("message"),MB_OK|MB_SYSTEMMODAL);
    
    

    2->In C++/CLI windows application:

    MessageBox::Show("The operation has been completed ","Notification", MessageBoxButtons::OKCancel,MessageBoxIcon::Asterisk);
    if (MessageBox::Show("Do you want to exit?","My Application", MessageBoxButtons::YesNo,MessageBoxIcon::Question)==::DialogResult::Yes)
    {
    Application::Exit();
    }
    

    3->In MFC application:

    AfxMessageBox(_T("first message box"));
    AfxMessageBox(_T("do you want to leave?", MB_YESNO|MB_ICONSTOP);
    
    

    Best regards,
    Helen


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    • Bearbeitet Helen Zhao Freitag, 18. November 2011 01:52
    • Als Antwort vorgeschlagen Helen Zhao Montag, 21. November 2011 03:07
    • Als Antwort markiert Helen Zhao Mittwoch, 23. November 2011 05:22
    Freitag, 18. November 2011 01:51
  • If you still have problems it's because within the form and button you have to completely call the full path for the result. 

    ->>  System::Windows::Forms::DialogResult::Yes

    EXAMPLE:

    if (MessageBox::Show("Do you want to exit?","My Application", MessageBoxButtons::YesNo,MessageBoxIcon::Question)==System::Windows::Forms::DialogResult::Yes)
             {
    MessageBox::Show("You pressed YES!", "STATUS INDICATION");
             }
    else
    {
     MessageBox::Show("You pressed NO!", "STATUS INDICATION");
    }

    I'm sure there is a way to convert the full path in another way and use it. But at least it's working and solving your initial problems.

    Any hints or way's for converting are welcome ;)

    Montag, 5. Mai 2014 18:11
  • If you still have problems

    After two and a half years? I hope not. ;-)

    - Wayne

    Montag, 5. Mai 2014 21:51