Answered by:
How can i show messagebox in visual C++?

Question
-
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;
Wednesday, November 16, 2011 4:34 AM
Answers
-
>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- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Wednesday, November 16, 2011 6:14 AM -
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
- Edited by Bordon Wednesday, November 16, 2011 6:05 AM
- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Wednesday, November 16, 2011 6:05 AM -
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
- Edited by Helen Zhao Friday, November 18, 2011 1:52 AM
- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Friday, November 18, 2011 1:51 AM
All replies
-
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
- Edited by Bordon Wednesday, November 16, 2011 6:05 AM
- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Wednesday, November 16, 2011 6:05 AM -
>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- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Wednesday, November 16, 2011 6:14 AM -
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
- Edited by Helen Zhao Friday, November 18, 2011 1:52 AM
- Proposed as answer by Helen Zhao Monday, November 21, 2011 3:07 AM
- Marked as answer by Helen Zhao Wednesday, November 23, 2011 5:22 AM
Friday, November 18, 2011 1:51 AM -
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 ;)
Monday, May 5, 2014 6:11 PM -
If you still have problems
After two and a half years? I hope not. ;-)
- Wayne
Monday, May 5, 2014 9:51 PM -
Just adding the statement by itself doesn't compile anymore.
MessageBox::Show("Any text here");
In Visual Studio 2017 gives a slew of errors, starting with Name followed by :: must be a class or namespace name, must be a class or union, and "Show" identifier not found. So things have apparently changed since this question was answered.
Whats the new quick & dirty way to throw up an alert box if you're working with the dialog box system given to you in the "Build a windows ap in 5 minutes!" starter kit? The alerts and such that are pre-build with the toolbox are working fine, but that's not so useful for displaying dynamically generated text on the fly...
Friday, June 29, 2018 6:15 PM -
Just adding the statement by itself doesn't compile anymore.
MessageBox::Show("Any text here");
In Visual Studio 2017 gives a slew of errors, starting with Name followed by :: must be a class or namespace name, must be a class or union, and "Show" identifier not found. So things have apparently changed since this question was answered.
- Edited by Castorix31 Friday, June 29, 2018 7:36 PM
Friday, June 29, 2018 7:35 PM -
.
Whats the new quick & dirty way to throw up an alert box if you're working with the dialog box system given to you in the "Build a windows ap in 5 minutes!" starter kit?
a thread that is almost seven years old and long since answered.
If you start a new thread on this, provide more specifics. Don't assume
that we all know what kind of project you're building, what your code
looks like *exactly*, etc.
If you are building a program using the Win32 API, then the posts in this
thread also show how to get a MessageBox that way. Note that they assume
that the program has:
#include <windows.h>
Note that it isn't a "new" way. It is the original way to do it in a
Windows program.
- Wayne
Friday, June 29, 2018 10:19 PM