User Input with Dialog / Text box

Started by
5 comments, last by bobby_nguyen 15 years, 4 months ago
Is it possible to display a dialog box , before the display begins, that allows the user to enter their name? Multiple fields or radio buttons would be nice. the MSDN knowledge base is confusing me, as always. I've got this much to work so far:

MessageBox(hwnd,
	"Hello",
	"Testing",
	NULL);
EndDialog(hwnd, 0);

I also need to pass this name into a .txt file. With my my old GLUT code, it was kinda easy using ofstream and cout / cin. [Edited by - bobby_nguyen on November 20, 2008 3:41:56 PM]
Advertisement
You can do this with the Win32 API, but it's pretty convoluted. The docs are here. I think you can add a dialog box as a resource to your project, which makes the process a little easier.

From memory, you create a message-pump function (the same as you do for creating a normal window), and then call CreateDialog().

You can add extra buttons to the message box you're using (Yes, No, Retry, etc) but that's about it.

Hope that's helpful.
Look into DialogBox. Build a dialog resource with the dialog editor, an according DialogProc and simply run DialogBox before creating your main window.

You can put all kind of controls on the dialog but remember to read the wanted data before closing the dialog.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Is there a dialog / resource editor with Visual Studio 2008 Express? I am having problems adding a resource file.
Quote:Original post by bobby_nguyen
Is there a dialog / resource editor with Visual Studio 2008 Express? I am having problems adding a resource file.


No. Unfortunately, Express editions don't ship with the visual editor.

However, you can edit resources as text no problem (well, apart from the problem of it being a pain to edit dialog resources as text [smile]).

Right click the Resources folder in the solution explorer and do Add New Item. Type "program_name.rc" into the name field.

Now right-click the file in the solution explorer and select Open With... Select the Text Editor option and tick the Default box. Now you can double click .rc files in future to open in the code editor.

You need to look into and learn about using dialogs in Win32, which is a bit beyond the scope of this reply. However, here's the dialog script for a little dialog that presents an edit box that I grabbed out of a project of mine:

IDD_REGION DIALOG DISCARDABLE  0, 0, 180, 50style DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "Region"FONT 8, "MS Sans Serif"BEGIN    DEFPUSHBUTTON "&OK",IDOK,126,30,50,14    EDITTEXT	  IDREGIONTAG,10,10,160,12,ES_AUTOHSCROLLEND


Unfortunately, in Win32, there is quite a lot of work involved in actually making this work. Have a look at the link beebs1 posted and see how much sense it makes before coming back with questions would be my advice.

Sorry can't explain more but it is a fairly complex topic.
I downloaded ResEdit to create a dialog resource. Following a small tutorial, I added this line of code to get started:
int dialogResult = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL, WindowProc, (LPARAM)0);


However I get a compile error:
"error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to 'DLGPROC'"

I'm pretty sure it has to do with my declaration of my dialog processor:
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);

and it's return value:
return DefWindowProc(hwnd, msg, wParam, lParam);

Changing it to BOOL CALLBACK gives me other errors as well. What's going on here?
Ok I got the dialog box to display. I am able to enter in my information. How am I to retrieve it? In my resource I have:
#define IDD_DIALOG1                             100#define initials                                1006#define number                                  1007#define block                                   1009


my dialog and three fields. Let's say 'block' can be 1 or 2. I would like to make a judgement if the user had entered 1 or 2. I find that simply stating:
if (block == 1){
//stuff
}

doesn't work.

This topic is closed to new replies.

Advertisement