views:

36

answers:

3

I need an input box in a UI program that is already written derived from the CWinnApp class and using MFC.

I see it is using message boxes but I don't see any examples of input boxes....

How do I do this?

(Using Visual Studio 6.0 in C++)

Thank You.

+2  A: 

You have to create a dialog box and place an edit control on it. There is no automagic solution. You have to code it or find some code on the web.

sylvanaar
+3  A: 

I know it's something that's often required, but there isn't a built-in input box in MFC, so you'll have to create your own. I usually just create a simple dialog with a label and edit box (the dialog already comes with OK/Cancel buttons), then create a class, say CInputDlg, add member variables for the label and edit box, and just call it like any other dialog:

CInputDlg dialog;
dialog.m_label = TEXT("Enter a number:");
if (dialog.DoModal() == IDOK) {
  // Do something
}
casablanca
@casablanca: this doesn't look too bad, I will give it a shot, thanks.
Tommy
@casablanca: Do i need to inherit from a specific class to use DoModal? The CDialog? is there any example of such a class?
Tommy
casablanca
@casablanca: Thanks, I got it working!
Tommy
ClassWizard should generate the header automatically, so I don't know why you're getting an error. Make sure that `IDD_CUSTOM_DIALOG` is actually the name of your dialog resource and also that `Resource.h` is included in the class header.
casablanca
+1  A: 

When you created your MFC App, which type of project did you tell the wizard to generate? Usually I do mine as a Dialog app, and then it's a simple matter of placing a text box on the dialog.

Mark Ransom
I believe the OP is looking for a pop-up (modal) input box, similar to a message box.
casablanca
@casablanca, my mind-reading skills must be a little off today. I think you're right.
Mark Ransom