Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Stonemonkey on September 13, 2007

Title: dialog boxes?
Post by: Stonemonkey on September 13, 2007
I've been looking for some way of making a dialog box to select windowed/fullscreen but everything I've found so far makes it look quite complicated, is it or is there any easier ways to do it?
Title: Re: dialog boxes?
Post by: benny! on September 13, 2007
Simple Dialog Boxes can be done with MessageBox command - like you see it in
the NeHe tutorials. If you want more and cooler looking starting screens to select
various settings and displaying a logo e.g. it's actually a normal window - and therefor
you have to face with the typical windows gui management.
Title: Re: dialog boxes?
Post by: Jim on September 13, 2007
You can either simply use
Code: [Select]
int res;
res = MessageBox(NULL, "Click Yes for Full Screen, No for Windowed", "Pick One!", MB_YESNO);
if (res == IDYES)
  fullscreen();
else if (res == IDNO)
  windowed();

alternatively if you want a whole box full of options you need to use the dialog editor in Visual Studio to create it, and then do all the message processing for the options in the box.  I can help you with that if you need it?

Jim
Title: Re: dialog boxes?
Post by: Stonemonkey on September 13, 2007
Thanks benny and jim, that's pretty much what I was looking for for now jim but knowing how to be able to select resolutions and choose other options would be pretty handy too.

k++
Title: Re: dialog boxes?
Post by: taj on September 15, 2007
Wait ... does this mean I can use MessageBox before opening my window?

Would this work Jim?

Code: [Select]
MessageBox(NULL, "Muzik?", "", MB_YESNO) ? sound() : nosound() ;
MessageBox(NULL, "Full Screen?", "", MB_YESNO) ? fullscreen() : windowed() ;
That might squeeze nicely into 4k.
Title: Re: dialog boxes?
Post by: Jim on September 15, 2007
Yep :)
Title: Re: dialog boxes?
Post by: va!n on September 15, 2007
@chris:
Just check only the returncode of MessageBox any you know what the user selected... like

Code: [Select]
lPlaySound = MessageBox(NULL, "Muzik?", "", MB_YESNO)
lFullScreen = MessageBox(NULL, "Fullscreen?", "", MB_YESNO)

If lPlaySound = MB_YES   ; Can be optimized to      If lPlaySound     only
    lSound = True
Else
    lSound = False
Endif

If lFullScreen = MB_YES
    lScreen = True
Else
    lScreen = False
Endif

However, you can change the look and feel of the messagebox... just try this flags you can combine...

Code: [Select]
MB_ICONSTOP
MB_ICONQUESTION    ; possible the best for you...
MB_ICONWARNING
MB_ICONEXCLAMATION

MB_OK
MB_OKCANCEL
MB_YESNO
MB_YESNOCANCEL
MB_ARORTRETRYINGNORE



Edit:
Ah sorry, haven't seen JIMs post before... ^^   Btw, if you want an messagebox with own text on the buttons, this is possible too but a little bit complicated... If you want know how it work, just tell me and i will try to find the timer very soon to post an example..
Title: Re: dialog boxes?
Post by: taj on September 15, 2007
Thanks Va!n. I was just looking fro the minimum byte use, nothing fancy.
Title: Re: dialog boxes?
Post by: Jim on September 18, 2007
Here's a sample of how to do something a bit more complicated with the option box.

If you double click the dialog.rc file you will see the dialog in the visual studio editor.  From there you can right click any gadget and get and change its properties, LOTS of properties, or drag and drop new controls.  In the menu there are options to help you with the layout alignment and spacing.

NB. This is how I do dialog boxes - it's the Win32 way.  There are lots of other ways to achieve the same thing, the dialog editor can even write most of the code for you.

Jim
Title: Re: dialog boxes?
Post by: Stonemonkey on September 19, 2007
Thanks Jim, can't get it to compile though:

.\dialog.rc(10) : fatal error RC1015: cannot open include file 'afxres.h'.

I've tried adding the mfc directory to the list of VC++ directories but that doesn't seem to help.
Title: Re: dialog boxes?
Post by: Jim on September 20, 2007
On my PC, I have this folder which contains afxres.h, it's part of MFC which should be installed with Visual Studio.
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include
If I go to
Tools->Options->Projects and Solutions->VC++ Directories->Include Files
I have an entry in there which looks like
$(VCInstallDir)atlmfc\include

Why?  For some reason even when you select not to use MFC it still adds that include file to bring in winres.h.

Potential problems:
If you're using VS Express - does that file exist in your VS Express install?

Potential fixes:
Try replacing afxres.h with winres.h in the dialog.rc file.

Jim
Title: Re: dialog boxes?
Post by: Rbz on September 20, 2007
I got the same problem with "afxres.h" file on VS2005 too, my solution is to remove it from resource file.

See attached file...
Title: Re: dialog boxes?
Post by: Jim on September 20, 2007
I don't understand why our installs differ. ???  With VS.NET I always elect to install everything, it seems not to work too well if you selectively install only some bits of it.

Thanks for the fix though!

Jim
Title: Re: dialog boxes?
Post by: Rbz on September 22, 2007
No problem :)

I do not install everything because I have a slow internet connection :( , it take ages to download all that stuff...