Reputation: 4830
We have a legacy code MFC VC++ one. I need to add a message box asking for 2 inputs(both are string). No need to consider security issue. Just need input.
How to do this? I am really not MFC guy. Searched several pages. Not good for me.
Best Thank you
Upvotes: 1
Views: 2709
Reputation: 490178
To get input you want a dialog, not a message box.
Assuming you're working in VS, you'll go to the resource view, expand the tree, right-click on "Dialog" and pick "Insert Dialog" from the pop-up menu. That'll let you draw your dialog, where you'll insert a couple of edit controls, probably with a static control next to each to describe what to enter there, etc. It'll start out with Ok and Cancel buttons, so you don't need to add those.
Once you've drawn what the dialog will look like, you need to add some code and such to back it up. Right click on one of the controls, and pick "Add Class" from the menu. That'll bring up a dialog that'll ask for the name of the class for the dialog. You'll enter some class name (e.g., "my_input") and it'll pick matching names for the source/header file. You'll probably want to change the base class from "CDHtmlDialog" to "CDialog". When you're happy with that, click "finish" and it'll create the class/files.
Then you'll go back to the dialog, right-click in one of the edit controls, and choose "add variable". To keep things simple toward the far right, change the "Category" from "Control" to "Value". Then pick a name for the string you'll receive from that control and click Ok. Repeat for the other control. Repeat for the other edit control (obviously choosing a different name for its variable).
The last thing you need to add is some code to invoke that dialog. To do that, you'll need to include the dialog's header in where you're going to use it. Then you'll add a bit of code something like:
my_input inp;
if (inp.DoModal() == IDOK) {
// retrieve your two strings
CString input1 = inp.field1;
Cstring input2 = inp.field2;
}
Upvotes: 2