Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MessageBox in VC++ Windows Form

Status
Not open for further replies.

jartman

Programmer
Oct 16, 2001
34
US
I'm trying to pop up a confirmation dialog box in a Windows Forms app, but I keep getting an error at compile time.

Here's the code snippet:

using namespace System::Windows::Forms;
.
.
.
int Form1::myMethod(void)
{
.
.
.
if (System::Windows::Forms::MessageBox::Show(msg,"Warning",System::Windows::Forms::MessageBoxButtons::OKCancel))
return 0;
}

The error message is:
error C2039: 'MessageBoxA' is not a member of 'System::Windows::Controls'
error C2660: System::Windows::Forms::Control::Show' : function does not take 3 arguments

Nowhere do I have a MessageBoxA, I assume this is somehow an alias of or referenced by the MessageBox definition?

Also being new to this platform, I wonder if there's just an include file or DLL that I'm missing?

This is VC++ in the visual studio 2003 environment, using a simple single-form window.
 
The first error is most likely due to the type of variable msg is. Check you arn't mixing managed and unmanaged code.
The second is a result of the first. Try...
Code:
String^ msg("The Message"); string on the managed heap

if (MessageBox::Show(msg,"Warning",MessageBoxButtons::OKCancel) == System::Windows::Forms::DialogResult::Cancel)
return 0;
or similar.
This works for me in C++VS2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top