Public Group

# can you put a message box through C++ ?

This topic is 3968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i was wonder if any one knew if its possible to add a input message box and code it through C++??? i know how to do it in VB , but i didnt know if you could use it in C++.

##### Share on other sites
Not sure if I completely understand your question, but C++ doesn't have that functionality, so you'll have to use an external library.

##### Share on other sites
A quick guess, but I reckon you'd have to design the box yourself in the IDE (or code it by hand) and have it return the contents of the text box.

##### Share on other sites
You can do it with the Win32 API. How you do it depends on what exactly you're trying to do - what exactly "input message box" means.

##### Share on other sites
Assuming you mean something like this, it might be possible in MFC, but MFC generally gives people headaches. C++ and MFC allow multiple inheritance, which can be a pain in the ass, according some programmers. It is something to look into, however, and you might enjoy it. Good luck :)

##### Share on other sites
Not even Visual Basic has this capability when stripped to its bare language without libraries. If you're talking about something like "MessageBox.Show" using the .NET platform, you're going to have to look into Win32 API or Managed C++.

##### Share on other sites
OK... here is my code

it already has a menu but i would prefer if it had a messagebox . is there somewhere i may add it to the code?

what i want is exactly anothrguitarist showed in his link he showed

#include <iostream>using namespace std;const int A_QUANTITY = 10;    //amount of #s entered for choice Aconst int B_SENTINAL = -99;   //sentinal used to end choice Bint main(){	bool again = true;        //used to control main choice loop	int choice;              //stores the choice made	int bigger;               //stores current biggest #	int smaller;              //stores current smallest #	int temp;                 //stores next number for comparison	int i;                    //controls the For loop	while (again)	{		//displays instructions for main options		cout << "What would you like to do?" << endl;		cout << "(enter the letter of your choice)" << endl;		cout << "1 - For loop" << endl;		cout << "2 - Do loop"<< endl;		cout << "3 - Quit this program." << endl;				//obtains choice and ignores the remaining input		cin >> choice;		if (choice == 1)		{			for( i = 0; i < 10; i++)				cout << "i = " << i << endl;			cout << "now we will do it backwards" << endl;					for (i = 10; i>=0; i--)			{// when a for loop has more than 1 line, you must have {} around it				cout <<" i = ";				cout << i << endl;			}// end of 2nd for loop		}// end of if		else if (choice == 2)		{			i = 0;						do 				{						cout << "i = " << i << endl;						i++;				} while (i < 10);		}//end of else		else // not 1 or 2 		return 0;	}// end of while loop	}// end of main

##### Share on other sites
Quote:
 Original post by shadowfire36is there somewhere i may add it to the code?
Simple answer: If you're learning C++, no. Adding a dialog like that involves a huge amount of Win32 code (about 2 or 3 hundred lines), and I doubt you'd understand any of it.

We can give you code to give a box like that, but you probably won't understand how it works, and it involves using Win32 (as I said), which means your code won't run on non-Windows machines (If that's a problem). It also requires that you have the platform SDK installed (And setting that up depends on your compiler).

##### Share on other sites
#include <Windows.h>

int MessageBox(HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);

hehe is that what you want?

##### Share on other sites
opps... sorry

HWND CreateDialog( HINSTANCE hInstance,
LPCTSTR lpTemplate,
HWND hWndParent,
DLGPROC lpDialogFunc
);

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013711
×