Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on September 23, 2010

Title: Resource Menu System
Post by: Clyde on September 23, 2010
Wonder if you could help with an example of making a menu system with radio buttons and check boxes with a resource.
I'd like to link it with the ogl textured cube routines and jims tinyptc d3d lib.

I'd be really stuck on how to make choice1=option1 or option2, etc.

here's an example I knocked up in notepad:
Code: [Select]
----------------------------------------
   [minimize][exit]
 =======================
 =        =
 = image goes in here  =
 =        =
 =======================
 -----------------------
 option 1 ( )
 option 2 (0)
 -----------------------
 fullscreen [/]
 
 =========  ========
 = start =  = exit =
 =========  ========
----------------------------------------

Cheers and hugest of thanks,
Clyde.
Title: Re: Resource Menu System
Post by: Jim on September 23, 2010
Open your cubes project.
In the Solution Explorer window, right click 'Open GL Vol 1'
Choose Add->Resource.
Pick Dialog and click New.

That will show you a blank dialog window.
From the View menu, select Toolbox.
You can drag all the options, labels, check boxes etc out of the Toolbox menu onto your blank dialog.

That's half the problem, the other half is getting the information in and out of the control.

Is this what you are after?

Jim
Title: Re: Resource Menu System
Post by: Clyde on September 24, 2010
Was hoping to do this manually to start out with, and then use an editor. will have a stab in the dark at the dialog thing in the toolbox.
 
And yup, the other half about using the data from the controls.

edit - it won't let me add a resource - perhaps that's in the full version of visual studio.
Title: Re: Resource Menu System
Post by: Jim on September 24, 2010
How about if you go
Project (menu)->Add New Item->Resource->Resource File
and then muck around from there?

I am also almost certainly not the right guy to help you with how to use the resources.  I'm a nuts-and-bolts win32 programmer and I suspect what I teach you will not help you.

I also do not know how to create these dialogs in code, though I can almost certainly find out.  Hellfire (without dumping him in it :P) knows more than me in this space, but I'll have a look if this is really what you want to do.

Jim
Title: Re: Resource Menu System
Post by: Clyde on September 24, 2010
I REALLY appreciate all the help dude.
these resource must be apart of the full version of visual studio.
Title: Re: Resource Menu System
Post by: hellfire on September 24, 2010
Maybe this piece of code from Gargaj (http://breakpoint.untergrund.net/stuff/fwzSetup.zip) already does most of the stuff you're looking for.
Title: Re: Resource Menu System
Post by: Clyde on September 25, 2010
thankyou for that Hellfire. I fiddled with some aspects, it's a bit alien and dont know how to run that into a project and add the .rc file.

this attachment is pretty crappy below, but I put together what I thought more or less near a dialog menu. it looks as if you call it more or less like when updating a window / registering a windows class.

perhaps there's a book that I can ask for Christmas about menu resources?

time for bed it's gone 3 am. o_0
Title: Re: Resource Menu System
Post by: Jim on September 25, 2010
Dialogs *are* windows.  Text boxes are windows.  Buttons are windows.  Radio buttons are windows... They all have WindowProcs which respond to messages being sent to them telling them to do things, in exactly the same way that the window *you* create for *your* application behaves.

All the dialog components works by sending messages to each others' WindowProcs, even if you just want to get the text from an edit control, under the covers it will send a 'GETTEXT' message which will ask the window which is the textbox to reply with its value.

Jim
Title: Re: Resource Menu System
Post by: Rbz on September 25, 2010
My advice for you, if you like, start from the basics (not compiler ;)), ie:

1 - Learn how to create a empty window.

2 - Add a text on this window, "hello world" text is ok.

3 - Add a button, and see how it works, ie when user click on it, how to process it's message.

For every step above you must understand what each part of the code is doing.
After all those steps done, you're ready to code your dialog/setup window.
Title: Re: Resource Menu System
Post by: Clyde on September 26, 2010
thanks for the suggestions. I can register a windows class if that's whats meant by an empty window.
I'll stick with yes or no, will have to try and look for a recent book on the subject; maybe there's a visual studio 2010 express for Dummies book.

thanks for your time all.
Title: Re: Resource Menu System
Post by: Rbz on September 26, 2010
I do believe there is some good books about it indeed, but nothing better than tutorials that you can find on the net.

You can start from here:
http://sol.gfxile.net/wintut/ch2.html
Title: Re: Resource Menu System
Post by: Clyde on September 26, 2010
looks as if i need the full version of visual studio 2010, ive got express c++. it says to use a dialog tool to create the menu, and then some sort of pascal for the resource files, which Im not able to add in express, and not sure with those values at the end.

im not after a permanent menu like in word / excel. a startup menu.

thanks for digging up the link.
Title: Re: Resource Menu System
Post by: Clyde on September 27, 2010
I've found a very small chapter in one of my Dummies books on it. It still refers to make them with the inbuilt tool.
 
it doesnt mention anything about getting settings that can be used with variables.
 
With VS 2010 C++ Express there's no way of adding .rc files that I can see, which is a shame. Unless other know otherwize?
 
Title: Re: Resource Menu System
Post by: Jim on September 27, 2010
You're right, no resource editor for C++ in VS Express.
Try using this program instead
http://www.resedit.net/ (http://www.resedit.net/)
You need to point it at your Platform SDK include folder though I was able to test it by just ignoring the messages.
Once you've done designing, add the .rc and .h files to your VS project in the normal way.

To get values from dialogs you have to send them messages.  For instance, a checkbox:
Code: [Select]
int checked = (int)SendDlgItemMessage(hwndDialog, ID_CHECKBOX, BM_GETCHECK, 0, 0);
Where hwndDialog is the window handle of the dialog box (you used CreateDialog or DialogBox to open the dialog)
ID_CHECKBOX is the name of the check box in the dialog editor.
BM_GETCHECK is the message you want to send, and the two 0s are parameters for the message (in this case there aren't any).
The value of checked will be one of
BST_CHECKED
BST_UNCHECKED
BST_INDETERMINATE (greyed out)
So you might do
Code: [Select]
switch (checked)
{
  case BST_CHECKED: fullscreen = true; break;
  default: fullscreen = false;
}

There are a lot of possible messages you can send and unfortunately the docs for them are scattered all over the win32 help.

Jim
Title: Re: Resource Menu System
Post by: Clyde on September 27, 2010
absolutely awesome and thankyou.
will have a play and report back!
 
edit - Something has just dawned on me, as I want to have the menu let the user select options, and then fire up the ptc d3d engine. Am I needing to create 1 window with the dialog on. And then registering another window with the ptc3d3 parts. What I mean is, am I creating two windows classes etc?
Title: Re: Resource Menu System
Post by: Jim on September 28, 2010
Every dialog box has its own WindowProc, so you can intercept the messages sent to it when you click buttons.  You don't need to register a new class for each one though, you just pass the WindowProc in when you CreateDialog() or DialogBox().

Jim
Title: Re: Resource Menu System
Post by: Clyde on September 28, 2010
Still stuck, main 1-2.cpp is the getting ready part of the options.
haven't seen any options at all.
not too sure what extra stuff res Edit might add.
I get redefinition errors, and a long list of lots of symbols loaded.
im hoping to have an options dialog for the tinyptc d3d lib you did Jim.
Title: Re: Resource Menu System
Post by: efecto on September 28, 2010
Here's my version of the Gargaj setup dialog.
I changed it a bit and with the help of the tool Jim posted (Thanks Jim for that) I got it working. (on my system).

It's a VS 2008 express solution, so you'll have to convert it probably.

You can see the code behind the RC file by right clicking it and selecting view code.

Any questions/remarks, just let me know, I'll try answering then.

and yes i kwow the combobox looks ugly like this
Title: Re: Resource Menu System
Post by: Jim on September 28, 2010
FTFY Clyde.
Jim
Title: Re: Resource Menu System
Post by: Clyde on September 29, 2010
Cheers to you both!!

Thanks for pointing me in the right direction Jim, those additions weren't in the book. probably as it was for a permanent menu.

I now have to get those buttons with the structure to behave. You've given me some pointers, so let's see if the brains working today again. ;)

Efecto, I only have one screen resolution option from the menu.
Title: Re: Resource Menu System
Post by: Jim on September 30, 2010
Clyde, you are mixing up what you think is a menu with what Windows calls a menu.

You think it's a window that you choose options from.

Windows is very specific that a menu is something that drops down from the menu bar, like File, Options, About etc.

You are looking in the wrong bit of the book.  You want the bit about Dialogs.

You should be able to get this working now - you just need to fill in the places in the dialog window proc where the comments are.  it should be close then.

Jim
Title: Re: Resource Menu System
Post by: Clyde on September 30, 2010
the Windows Game Programming For Dummies, has a really small page about using a menu resource. Dialogs, That's one more term to add to the hat.

I've added the following into the dlgprocess to non avail, it gives an unhandled execption break.
Code: [Select]
// execute menu messages.
case WM_COMMAND:
{
// select menu item.
switch(wparam)
{
case IDC_CHECKBOX1:
{
// fullscreen, uncheck for windowed.
int checked=(int) SendDlgItemMessage(hwnd, IDC_CHECKBOX1, BM_GETCHECK, 0, wparam );

switch (checked)
{
case BST_CHECKED:
{
demo_settings->fullscreen = true;
break;
}


default:
{
demo_settings->fullscreen = false;
}
}

}
break;

case IDC_RADIO1:
{
//select 640x480.
}
break;

case IDC_RADIO2:
{
//select 800x600.
}
break;


//if (IsDlgButtonChecked(hwnd,SINWAVE))
//{
//tempconfig.wavetype=1;
//}

//if (IsDlgButtonChecked(hwnd,SQRWAVE))
//{

//}
      //tempconfig.wavetype=2;
    //if (IsDlgButtonChecked(hDlg,SAWWAVE))
     // tempconfig.wavetype=3;
   


case ID_CANCEL:
{
end_demo=true;
EndDialog(hwnd, 1);
break;
}

case ID_OK:
{
end_demo=false;
EndDialog(hwnd, 0);
break;
}

default:
{
// twiddle fingers.
break;
}

} //end switch
}//end wm command.

break;

case WM_CLOSE:
{
EndDialog(hwnd, 0);
break;
}

}// end of message switch-a-roony.

return FALSE;
}

I also need to group the radio buttons, one of them true the others false. I haven't found too much info.
Title: Re: Resource Menu System
Post by: Jim on September 30, 2010
Radio buttons can automatically turn each other off and on.
In resedit, in the properties for each radio button, set the Behavior->Auto=True (they are false by default).
Use the Dialog->Test Dialog to see that working.

If you want two groupings, then make sure the tab order is correct (the tab order is the order you created the buttons in, but you can use the Dialog->Tab Order Wizard to change it).
Then, for the first radio button in each group, set the property Misc->Group=True

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 01, 2010
I fixed a few bugs it was the struct that made the crash above.

I presume I need to set something in WM_INIT_DIALOG so that the radio buttons show the selection gfx for eg, ID_RADIO1=true so display the selection, etc. As at the moment, I have to click one of them for the bullet to appear. it would appear ( for me ) it's not saving the states for true or false.

Not only but also, my dialog menu looks nothing like wots shown in resedit, and resedit will crash when I do something like change or add a setting. Wonder if I've got resedit for Windows7.

Thanks for helping me out Dudes!
Title: Re: Resource Menu System
Post by: Jim on October 01, 2010
resedit does seem to crash a bit...I'm on W7.  Also, VS2010 full version crashes when it tries to load .rc files from resedit!  No idea why!

Yes, do this in WM_INITDIALOG to programmatically check the first box:
SendDlgItemMessage(hwnd, IDC_CHECKBOX1, BM_SETCHECK, BST_CHECKED, 0);

by the way
int checked=(int) SendDlgItemMessage(hwnd, IDC_CHECKBOX1, BM_GETCHECK, 0, wparam );
should be
int checked=(int) SendDlgItemMessage(hwnd, IDC_CHECKBOX1, BM_GETCHECK, 0,0);
            
J!m
Title: Re: Resource Menu System
Post by: Clyde on October 04, 2010
thanks for that!

I now am trying to get the dialog to appear correctly in the style of other Windows. For me in VS they look like windows 95 / 98 / XP, in resedit they look normal - ie Windows Vista / 7. Would I need the Platform SDK service pack 1 for Windows 7, as it has a link to that when setting up the paths in resEdit?

I don't know if richtext.h is needed. Also if I need to keep adding #include <windows.h> as im putting that at the top of main 1-1.cpp
 
Thanks.
Title: Re: Resource Menu System
Post by: Jim on October 04, 2010
It's a common misconception that adding or removing .h files is like adding or removing a library.  It's not the same.  .h files are just for the compiler to help work things out.  You need both a .h file and to add a .lib reference to add new libraries.
So adding extra .h files is not going to fix your problem.  Most likely it will complicate things later on.

The reason it looks a bit different is you probably need an extra style setting that resedit doesn't set.  I'd worry less about that and more about making it actually work.  In the end the difference will just be a simple style setting.

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 04, 2010
Thanks Jim, I haven't removed any .h from the rc file.
I'm quite used to freebasic and able to use eg - #include once "tinyptc_ext.bi", I was querying if should it's neccassary to keep having #include <windows.h> etc

Good news is the dialog is working for both the check box and radio buttons! And thanks tons for the help getting there.

All I need to do is to redesign and make it look better. Im looking for how to have a border with a caption:

----Resolution----
#  640 x 480 (0) #
#  800 x 600 (  ) #
------------------
Title: Re: Resource Menu System
Post by: Jim on October 04, 2010
In freebasic including .bi files also includes the libraries.  In general with .h files in C and C++ that doesn't happen.  If you need windows.h in a file then you need it in that file.  It doesn't matter how many files into which it goes. .h files are the way different .c files agree to work with each other, and each .c file will need the .h file.

Try the Group Box from the toolbox.  It has a caption and a border.

Jim
Title: Re: Resource Menu System
Post by: hellfire on October 04, 2010
----Resolution----
#  640 x 480 (0) #
#  800 x 600 (  ) #
------------------
Please don't use a fixed set of resolutions.
We did that 10 years ago and they all look crappy on nowadays displays.
Use a listbox instead and enumerate all available resolutions.
Title: Re: Resource Menu System
Post by: Clyde on October 04, 2010
I've not got to that part yeti. Only doing it as it's the first proper dialog I've ever made in C, and it's just for testing, I've also never done a software demo or intro in 800 x 600.

If you've got any examples of a list box and I've never come across the term enumerate before.

Cheers for the info dude,
Clyde.
Title: Re: Resource Menu System
Post by: Jim on October 04, 2010
There are various calls in Windows API and DirectX that let you ask the computer which resolutions it can do.
Enumerate is like 'number'.  These APIs ask the computer to give you the type and number of display modes = enumerates the display modes.

There's a list box in the toolbox in resedit.  You can set a list of items in its properties, or you can use (i think) the message LB_ADDITEM to add items.

Jim
Title: Re: Resource Menu System
Post by: hellfire on October 04, 2010
If you're using the resource-editor, just drag a "List Box" into your dialog.
Doing it programmatically would be something like this:
Code: [Select]
HWND listbox= CreateWindowEx(
      WS_EX_CLIENTEDGE,
      WC_LISTBOX,
      title,
      WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY | WS_VSCROLL,
      xPosition,      // position inside the parent wnd
      yPosition,
      width,
      height,           
      parentWnd,    // the parent wnd (your dialog)
      (HMENU)id,    // some id for the message identification
      NULL,
      NULL
);

To add items:
Code: [Select]
char *text="bla"; // assumes you're not using unicode
SendMessage(listbox, LB_ADDSTRING, NULL, (LPARAM)text);

To catch the currently selected item do something like this in your message handler:
Code: [Select]
   case WM_COMMAND:
      {
         unsigned short lo= LOWORD(wParam);
         unsigned short hi= HIWORD(wParam);
         
         switch (lo)
         {
         case ID_OF_YOUR_LISTBOX:
            if (hi == LBN_SELCHANGE || hi == LBN_SELCANCEL)
               int selectedIndex = (int)SendMessage(listbox, LB_GETCURSEL, 0, 0);
            break;

And enumerating resolutions:
Code: [Select]
   DEVMODE dmi;
   int modeNum = 0;

   while (EnumDisplaySettings(NULL, modeNum, &dmi))
   {
      // dmi holds properties of mode:
      // width= dmi.dmPelsWidth
      // height= dmi.dmPelsHeight
      // bits per pixel= dmi.dmBitsPerPel
      // refresh in hz= dmi.dmDisplayFrequency

      modeNum++;
   }
Title: Re: Resource Menu System
Post by: Clyde on October 13, 2010
not sure where and what to do with the last part w/ Enumerating bit. INIT_DIALOG ?
And make it fill the list box.

DEVMODE is a new thing for me.

big thanks
Clyde.
Title: Re: Resource Menu System
Post by: Jim on October 13, 2010
You can do it before you create the dialog, store all the resolutions somewhere or you can do it in the init dialog itself, and then use the SendDlgItemMessage in the init dialog to add the strings.

Type DEVMODE into visual studio, highlight it, press F1.  It should bring up the help.  It's nothing to be scared of, it's just another Windows type.

Jim
Title: Re: Resource Menu System
Post by: hellfire on October 13, 2010
not sure where and what to do with the last part w/ Enumerating bit. INIT_DIALOG ?
It doesn't really matter.
Adding an entry to your listbox is done by sending a message to the its' window-handle.
So just make sure that the window already exists.
Keep in mind that the enumeration-loop fetches all available video-modes.
So you'll get several modes with eg. 640x480, one in 32bpp and 60hz, another one in 16bpp and 75hz, etc.
If you just want to list all available resolutions you'll have to check if the current mode's resolution is already in your list.
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
very nearly there though I'm only getting one item listed, and a little stuck with adding in the proper name rather than blah. Also need the bit that chooses from a selection as I tried out the sendmessage stuff, it didnt like that.
 
Thanks.
Title: Re: Resource Menu System
Post by: hellfire on October 14, 2010
a little stuck with adding in the proper name rather than blah
All you needed to do is to allocate some memory for each string:
Code: [Select]
while (EnumDisplaySettings(NULL, modeNum, &dmi))
{
res_list[ modeNum ]= new char[16];
sprintf( res_list[modeNum], "%d * %d", dmi.dmPelsWidth, dmi.dmPelsHeight);
modeNum++;
}

Quote
need the bit that chooses from a selection as I tried out the sendmessage stuff, it didnt like that.
Note that you're using a combobox ("CB_..."-messages) and I assumed a listbox ("LB_..."-messages).
I also assumed you had the window-handle of your listbox and can send messages directly (that's when you create the listbox-window manually without the help of the dialog-editor).
So instead you want to send the message to your dialog-window and specify the according sub-item ("IDC_...").

Getting the currently selected item is something like this:
Code: [Select]
int selected= SendDlgItemMessage(hwnd, IDC_RESOLUTION,  CB_GETCURSEL, 0, 0);
Selecting a certain item:
Code: [Select]
SendDlgItemMessage(hwnd, IDC_RESOLUTION,  CB_SETCURSEL, indexOfItem, 0);
You can find a list of available commands for a combobox here: http://msdn.microsoft.com/en-us/library/ff485901%28v=VS.85%29.aspx
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
Sorry to be a pain.
 
Cool added the new char[16] :)
I also could of sworn, I added a list box for the resolutions.

im still only getting one entry listed.

hwnd = window handle - sent to the dialog function
IDC_RESOLUTION -the listbox resource define.
CB_ADDSTRING - combo box add string ( char* )
NULL = nothing
(LPARAM)res_list[a] - cast / convert from string to lparam.

Code: [Select]
case WM_INITDIALOG:
      {
                 
         // populate the resolution listbox.
         for ( int a=0; a<=user_res_total; a++ )
         {
            SendDlgItemMessage( hwnd, IDC_RESOLUTION, CB_ADDSTRING, NULL, (LPARAM)res_list[a]);


            //SendDlgItemMessage( hwnd, IDC_RESOLUTION, LB_ADDSTRING, NULL, (LPARAM)res_list[a]);
            // SendMessage(hwnd, IDC_RESOLUTION, LB_ADDSTRING, NULL, (LPARAM)res_list[a]);
         }

         return TRUE;
      }


Im wondering if perhaps i am overwritting the values in the WinMain.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Can you show the other bit where you're filling in res_list.  The code below looks OK-ish.

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
sure Jim, also not sure if the message I get about sprintf not being safe is doing anything silly.

Code: [Select]
// lets fire her up.
   if ( demo_status==DEMO_INIT )
   {   
      DEVMODE dmi;
      int modeNum = 0;
     
      // scan for users pc resolutions.
      while (EnumDisplaySettings(NULL, modeNum, &dmi))
      {
         // dmi holds properties of mode:
         // width= dmi.dmPelsWidth
         // height= dmi.dmPelsHeight
         // bits per pixel= dmi.dmBitsPerPel
         // refresh in hz= dmi.dmDisplayFrequency
         
         res_list[ modeNum ]=new char[16]; // assumes you're not using unicode

         sprintf( res_list[modeNum], "%d * %d", dmi.dmPelsWidth, dmi.dmPelsHeight);

         modeNum++;
      }

      user_res_total=modeNum;//-1;

      //show the dialog
      INT_PTR result = DialogBox(hInstance, "GVY_MENU", NULL, DlgWindowProc);
   }
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Can't see anything wrong, other than you have
a<=user_res_total
instead of
a<user_res_total

Ignore the warnings about sprintf.  sprintf is a C runtime library function.  It's been there since K&R days.  Microsoft are trying to get people to see that it is a dangerous function.  It is a dangerous function, but only if you are an idiot - it is prone to cause buffer overflows.  There is an international standard for the "Safer C Library", which Microsoft now supply.  They'd like you to use that instead, but the standard hasn't really been universally accepted.

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
Thanks for taking alook Dude, I'm slightly baffled then :(

I'm wondering if it needs the other bits in WM_COMMAND and IDC_FULLSCREEN for it to update properly??
 
Please could you try running the project up a few posts, if it works for you then I know it's my machine.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Post your code again.  The two snippets you posted, on the surface, look OK.  But what else you have done our tiny minds can only guess :D

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
I posted it on page 2.
http://www.dbfinteractive.com/forum/index.php/topic,4812.msg64793.html#msg64793 (http://www.dbfinteractive.com/forum/index.php/topic,4812.msg64793.html#msg64793)

you'll just need to alter them slightly with the 2 code snippets updates.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Sorry mate, but you need to post what you are actually compiling, otherwise we just have to guess how you have pasted the snippets together.

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
here's the project from page 2 with the minor changes.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Apart from the fact that code doesn't even compile, once I fixed the obvious errors it did what it should.

Jim
Title: Re: Resource Menu System
Post by: hellfire on October 14, 2010
Quote
im still only getting one entry listed.
Clyde, you know that you are still using a combobox and that comboboxes show only a single entry until you open the dropdown?
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
Ok thanks guys!

Please bare with me, I appologize for the zipped project not compiling. Not sure which bits to include other than the code and the sub folders and headers. It's a totally different affair from most basics.

If that code eventually worked for you then there's something up with my pc.

I didn't know about the combo boxes. Will use resedit and change that. I was half and half looking at the umulat link.

Thanks for your time and assistance in getting me through this. One day, I'll conker ze world.
Title: Re: Resource Menu System
Post by: hellfire on October 14, 2010
then there's something up with my pc.
Sorry, I know, sometimes bugs are so hard to spot that you can only think of a hardware problem - but it *never* is.
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
 :D A Bugs Life :)

The combo box still only shows me one entry for some reason. even clicking etc.

next I need to somehow stop duplicate entries.
I tried the obvious presuming 32 means 32-bit colour that my video settings are:

Code: [Select]
if ( dmi.bitsPerPel ==32 )
{
  // fill out info.
 modeNum++
}
Title: Re: Resource Menu System
Post by: hellfire on October 14, 2010
The combo box still only shows me one entry for some reason.
I added a scrollbar to the window-styles of the combobox.
Does this work any better for you?
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
Much better! Thanks Dude :)
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
Success in the resolution reductions :D
Didnt realize that modeNum was exclusive to the enumerator.

Code: [Select]
   // lets fire her up.
   if ( demo_status==DEMO_INIT )
   {   
      DEVMODE dmi;
      int modeNum=0, count=0;
      int prev_wwidth=0;
      int prev_height=0;

      //EnumDisplaySettings(NULL,0,&dmi);
      // scan for users pc resolutions.
      while (EnumDisplaySettings(NULL, modeNum, &dmi))
      {
         // dmi holds properties of mode:
         // width= dmi.dmPelsWidth
         // height= dmi.dmPelsHeight
         // bits per pixel= dmi.dmBitsPerPel
         // refresh in hz= dmi.dmDisplayFrequency
         
         if ( (dmi.dmPelsWidth != prev_wwidth ) && (dmi.dmPelsHeight != prev_height) && (dmi.dmBitsPerPel==32) )
         {

            res_list[ count ]=new char[16]; // assumes you're not using unicode

            sprintf( res_list[ count ], "%d * %d", dmi.dmPelsWidth, dmi.dmPelsHeight);

            prev_wwidth=dmi.dmPelsWidth;
            prev_height=dmi.dmPelsHeight;

            count++;
         
         }
            modeNum++;
      }

      user_res_total=count;

Edit:
 
Does this look right to you?
 
Code: [Select]
// execute menu messages.
  case WM_COMMAND:
  {
   unsigned short lo=LOWORD(wparam);
   unsigned short hi=HIWORD(wparam);
   // select menu item.
   switch(wparam)
   {
   
    case IDC_RESOLUTION:
    {
   
     if (hi == CBN_SELCHANGE )//|| hi == LBN_SELCANCEL)
     {
      int selectedIndex = (int)SendMessage( hwnd, CB_GETCURSEL, 0, 0);
     }
     break;
    }
}

If yes, then how can I now use that info to give the selected width and height.
user_wwidth=wwidth_list[ selectedIndex ];
...etc ?

Oh, and I couldnt find an alternative to LB_SELCANCEL

cheers.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
Quote
Please bare with me, I appologize for the zipped project not compiling. Not sure which bits to include other than the code and the sub folders and headers. It's a totally different affair from most basics.
You sent all the right bits, but the C++ code was wrong, e.g.
         // populate the resolution listbox.
         for ( int a=0; a<user_res_total; a++ )
         {
            SendDlgItemMessage( hwnd, IDC_RESOLUTION, CB_ADDSTRING, NULL, (LPARAM)res_list[a] );
             );//, 0)

            //SendDlgItemMessage( hwnd, IDC_RESOLUTION, LB_ADDSTRING, NULL, (LPARAM)res_list[a]);
            // SendMessage(hwnd, IDC_RESOLUTION, LB_ADDSTRING, NULL, (LPARAM)res_list[a]);
         }

         // for ( int i=0; i<user_res_total; i++)
          //{
            //if (ress.w==setupcfg->scrWidth && ress.h==setupcfg->scrHeight)
         //   SendDlgItemMessage(hwnd, IDC_RESOLUTION, CB_SETCURSEL, NULL, (LPARAM)res_list[14] );//, 0);
          //}
         
         SendDlgItemMessage(hwnd, IDC_RESOLUTION, CB_SETCURSEL, NULL, (LPARAM)res_list[a]
         
         return TRUE;

First problem extra closing bracket, second problem undefined variable 'a' and no closing bracket.  I don't know how you could have compiled this code.

Quote
If yes, then how can I now use that info to give the selected width and height
Code: [Select]
int selectedIndex = (int)SendMessage( hwnd, CB_GETCURSEL, 0, 0);
char *chosen_res = res_list[selectedIndex];

That will give you the select mode as a string.  If you want it as numbers then as well as keeping a copy of res_list, do something like
Code: [Select]
//make some space to store the dimensions
int res_widths[MAX_RESOLUTIONS];
int res_heights[MAX_RESOLUTIONS];
...
//store the dimensions in the enumerator
res_widths[count] = dmi.dmPelsWidth;
res_heights[count] = dmi.dmPelsHeight;
...
//pull out the widths using the selectedIndex.
int chosen_width = res_widths[selectedIndex];
int chosen_height = res_heights[selectedIndex];

Jim
Title: Re: Resource Menu System
Post by: Clyde on October 14, 2010
I know what happened with that code, I had my Niece round and she must of done some combination of key hitting when she was smashing the keyboard, and throttling the mouse in word. I still had express open, I hadnt suspected anything and saved the code before exitting.

Cool, do you guess the aspect ratios, I mean by that fill out the arrays with values manually, or is there a command like enumarating dmi / DEVMODE.
Title: Re: Resource Menu System
Post by: Jim on October 14, 2010
float aspect = (float)width/height;
16:10 is 1.6
4:3 is 1.333
and the pixel ratios of the resolutions are similar.
So, if the aspect is > 1.4 or so, then it's going to be widescreen.

Yes, fill out the choices manually.  You want
4:3
16:9
16:10
and maybe 5:4.

Jim
Title: Re: Resource Menu System
Post by: hellfire on October 15, 2010
Does this look right to you?
Code: [Select]
  case WM_COMMAND:
  {
   unsigned short lo=LOWORD(wparam);
   unsigned short hi=HIWORD(wparam);

   switch(wparam)
   {
    case IDC_RESOLUTION:
    {
     if (hi == CBN_SELCHANGE ) ...
The dialog-item is in the low-word of wParam, so your switch only works if the parameter in the high-word is 0; which it is not with CBN_SELCHANGE.
So you want to do:
Code: [Select]
   switch(lo)
   {
      case IDC_RESOLUTION: ...
Title: Re: Resource Menu System
Post by: Clyde on October 15, 2010
Just for combo boxes and / or list boxes?

Now looks like this.

Code: [Select]
// execute menu messages.
case WM_COMMAND:
{
unsigned short lo=LOWORD(wparam);
unsigned short hi=HIWORD(wparam);

// select menu item.
switch(wparam)
{
switch(lo)
{
case IDC_RESOLUTION:
{
if (hi == CBN_SELCHANGE )//|| hi == LBN_SELCANCEL)
{
int choice = (int)SendMessage( hwnd, CB_GETCURSEL, 0, 0);

user_wwidth=wwidth_list[ choice ];
user_height=height_list[ choice ];
}

break;
}

case IDC_ASPECT_RATIO:
{
if (hi == CBN_SELCHANGE )//|| hi == LBN_SELCANCEL)
{
int choice = (int)SendMessage( hwnd, CB_GETCURSEL, 0, 0);
user_ratio=(float) user_wwidth / (float) user_height ;//ratio_value[ choice ];
//user_height=height_list[ choice ];
}

break;
}
}


case IDC_FULLSCREEN:
{
//select FULLSCREEN
if ( IsDlgButtonChecked(hwnd,IDC_FULLSCREEN))
{
demo_fullscreen=0;

break;
}

}

case IDC_WINDOWED:
{
//select windowed mode.
if ( IsDlgButtonChecked(hwnd, IDC_WINDOWED ))
{
demo_fullscreen=1;
break;
}
}

case IDC_CANCEL:
{
demo_status=DEMO_OVER;
EndDialog(hwnd, 1);
break;
}

case IDC_OK:
{
demo_status=DEMO_STARTUP;
EndDialog(hwnd, 0);
break;
}

} //end of switch

break;

}//end WM_COMMAND:
Title: Re: Resource Menu System
Post by: hellfire on October 20, 2010
Just for combo boxes and / or list boxes?
If you select an entry of a combobox, you get a "CBN_SELCHANGE" event and "CBN_" indicates a combobox notification.
The same applies to a listbox except that you get a "LBN_SELCHANGE" event, "LBN_" because it's a listbox notification.
You can find a list of possible listbox-notifications here: http://msdn.microsoft.com/en-us/library/ff485968%28v=VS.85%29.aspx
A list of combobox-notifications is here: http://msdn.microsoft.com/en-us/library/ff485902%28v=VS.85%29.aspx
All notifications work by the same principle:
You'll receive a "WM_COMMAND" message with the dialog-item in the low-word of "wparam" and the event-id in the high-word.
If you're unsure how a certain event works, just put a break-point into your message-handler and have a look.