Author Topic: Resource Menu System  (Read 26699 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #20 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #21 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #22 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #23 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!
« Last Edit: October 01, 2010 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #24 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #25 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.
« Last Edit: October 04, 2010 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #26 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
« Last Edit: October 04, 2010 by Jim »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #27 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 (  ) #
------------------
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #28 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
« Last Edit: October 04, 2010 by Jim »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Resource Menu System
« Reply #29 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.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #30 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #31 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
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Resource Menu System
« Reply #32 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++;
   }
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #33 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #34 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
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Resource Menu System
« Reply #35 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.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #36 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Resource Menu System
« Reply #37 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #38 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.
« Last Edit: October 14, 2010 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Resource Menu System
« Reply #39 on: October 14, 2010 »
Can you show the other bit where you're filling in res_list.  The code below looks OK-ish.

Jim
Challenge Trophies Won: