Author Topic: Resource Menu System  (Read 26695 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #40 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);
   }
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 #41 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #42 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.
« 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 #43 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #44 on: October 14, 2010 »
I posted it on page 2.
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.
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 #45 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
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #46 on: October 14, 2010 »
here's the project from page 2 with the minor changes.
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 #47 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
Challenge Trophies Won:

Offline hellfire

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

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #49 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.
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 #50 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.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #51 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++
}
« 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 hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Resource Menu System
« Reply #52 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?
« Last Edit: October 14, 2010 by hellfire »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #53 on: October 14, 2010 »
Much better! Thanks Dude :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Resource Menu System
« Reply #54 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.
« 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 #55 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
« Last Edit: October 14, 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 #56 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.
« 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 #57 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
Challenge Trophies Won:

Offline hellfire

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

Offline Clyde

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

Challenge Trophies Won: