Jump to content
  • Advertisement
Sign in to follow this  

User Input with Dialog / Text box

This topic is 3673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
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]

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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:

CAPTION "Region"
FONT 8, "MS Sans Serif"

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.

Share this post

Link to post
Share on other sites
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:

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?

Share this post

Link to post
Share on other sites
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){

doesn't work.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!