visual C++ simple dialog boxes

Omegachi

Diamond Member
Mar 27, 2001
3,922
0
76
i am a noob at visual C++ and i want to create a very simple dialog box that has a button in the middle.... from starting up microsoft visual C++, what are the steps to creating a very simple dialog box?... i am going to leave it vague so you can make this box do whatever you want.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
To make something sort of like VB, create an MFC "dialog-based" application.

The app starts out with one main dialog that you edit with the Resource Editor. When the user clicks OK or Cancel (you can rename or hide these) the program ends.

In resource editor you add edit, static, combo etc. controls to the dialog, then use ClassWizard to add C++ functions that "fire" (are triggered) when a user clicks a button
 

juiio

Golden Member
Feb 28, 2000
1,433
4
81
Depends how simple you are talking about. Look into MessageBox and see if it is too simple for your needs.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: juiio
Depends how simple you are talking about. Look into MessageBox and see if it is too simple for your needs.
Good ppint, I was thinking "application that does something useful" not an OK box.

MessageBox is a Win32 function, you can look it up at msdn.microsoft.com if you don't have MSDN Library or VC++ online docs installed.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
AfxMessageBox
int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );

int AFXAPI AfxMessageBox( UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT) -1 );

Return Value

Zero if there is not enough memory to display the message box; otherwise one of the following values is returned:

IDABORT The Abort button was selected.


IDCANCEL The Cancel button was selected.


IDIGNORE The Ignore button was selected.


IDNO The No button was selected.


IDOK The OK button was selected.


IDRETRY The Retry button was selected.


IDYES The Yes button was selected.
If a message box has a Cancel button, the IDCANCEL value will be returned if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing the ESC key has no effect.

The functions AfxFormatString1 and AfxFormatString2 can be useful in formatting text that appears in a message box.

Parameters

lpszText

Points to a CString object or null-terminated string containing the message to be displayed in the message box.

nType

The style of the message box. Apply any of the message-box styles to the box.

nIDHelp

The Help-context ID for the message; 0 indicates the application?s default Help context will be used.

nIDPrompt

A unique ID used to reference a string in the string table.

Remarks

Displays a message box on the screen. The first form of this overloaded function displays a text string pointed to by lpszText in the message box and uses nIDHelp to describe a Help context. The Help context is used to jump to an associated Help topic when the user presses the Help key (typically F1).

The second form of the function uses the string resource with the ID nIDPrompt to display a message in the message box. The associated Help page is found through the value of nIDHelp. If the default value of nIDHelp is used (? 1), the string resource ID, nIDPrompt, is used for the Help context. For more information about defining Help contexts, see the articleHelp Topics in Visual C++ Programmer?s Guide and Technical Note 28.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
If MEssageBox is not flexible enough, the creation of a Dialog Box will require you to define a resource (rc) file that will contain the definition of the dialog box and associated controls.

As stated above, use the MFC wizard to create a simple dialog based application and go from there.