Advertisement

How to use MFC to make a prompt box

Started by January 15, 2000 08:02 PM
3 comments, last by C++ Freak 24 years, 11 months ago
How do you use MFC to make a prompt box and then test its value when the user presses OK? Visit members.xoom.com/ivanickgames Edited by - C++ Freak on 1/15/00 8:05:17 PM
Visit http://members.xoom.com/ivanickgames
If I understand what you are asking, just use the dialog editor to design your box and then derive a class from CDialog using the new dialog template you created. Finally, override the DoDataExchange() function in which you set the validation ranges. You can find out how to do this in the docs.
Advertisement
I have the MSDN October 99 Library. Does that have how to do it in it? I didn''t get my VC++ with any manuals or anything.
Visit http://members.xoom.com/ivanickgames
Well, first go into your resource editor and draw your spiffy dialog (it should be the resource tab. You did make this an MFC project right? If not, start over). Make sure you have an "OK" and "Cancel" button, add an "Edit Control" for the user to type in, and put in some "Static Text" to tell them what they''re supposed to be typing.
Now, right click on your edit control. Run down the popup menu until you see "Class Wizard". It''s going to prompt you to make a new class for your dialog, type in something nice and create it, it will create the files that go to your dialog, and derive them for you, which is sweet. Now, click the "Member Variables" tab. Choose your edit box ID (it will be something generic unless you right clicked your edit control, scrolled down to "Properties", and changed it there). Then, click the button to add a variable. You can choose to add it as either a CString or a CEdit. Either way is fine, I usually make one of each because I tend to do things like dynamic showing on some of my projects. You might just want to stick with a CString variable. Name it something you can remember. Now go back to the "Message Maps" tab, and click on "IDOK". This is what fires when you hit the OK button on your dialog. Click BN_CLICKED, then hit "Add Function". "OnOK" will be default function name, so use it. This will create a function in your .h and .cpp. Now, go into the OnOK function and type "UpdateData(FALSE)" (anyway I think it''s the FALSE case, my computer is currently having its display drivers reinstalled and I can''t get to MSDN help right now, might want to check that) This should get you whatever they typed in the edit box when you hit the OK button.
Now, in the program you want to pop it up from, create an instance of the dialog''s class like this:

CWhateverYouNamedYourDialog myDialog;

Pop it up by:

if (myDialog.DoModal() == IDOK)
{
m_PromptThingToRetrieve = myDialog.m_EditBoxStuff;
}

myPromptThingToRetrieve should be a CString to contain whatever you prompted them for, and m_EditBoxStuff should be whatever you named the CString in your dialog that belongs to your edit control.

HTH, luck

-fel

~ and that''s why it''s called "Visual" C++ ~
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Um... If I understand what you''re asking you might just want to use the Win32 API function MessageBox...

i.e.
if (MessageBox(handle, "MessageBox Body", "Title", MB_OKCANCEL) == ID_OK) {
} else {
}

This topic is closed to new replies.

Advertisement