Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ vector question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 codder88   Members   -  Reputation: 103

Like
0Likes
Like

Posted 06 September 2010 - 07:05 AM


DEVMODE dm;
memset((void*)&dm,0,sizeof(dm));
DWORD dw;

vector<DEVMODE> vec;


while(EnumDisplaySettings(NULL, dw, &dm))
{
vec.push_back(dm);
dw++;
}

// from DEVMODE i need only the resolution but some DEVMODE contain a repeated screen resolution



for example:
i logged the vector and the output is

VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 720 x 480
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
.....

How to remove the repeated values? there is a function to do this?

Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 4330

Like
0Likes
Like

Posted 06 September 2010 - 07:07 AM

Use std::set or std::map instead of a std::vector. You may need to create a simple structure with only the information you're looking for. (See DEVMODE structure.) Or you can keep track of the current display settings:


while there are more display settings
get next display setting
if next display setting's resolution is not equal to the previous display setting resolution then
add display setting to available settings
end
end


c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#3 codder88   Members   -  Reputation: 103

Like
0Likes
Like

Posted 06 September 2010 - 07:14 AM

Quote:
Original post by _fastcall
Use std::set or std::map instead of a std::vector. You may need to create a simple structure with only the information you're looking for. (See DEVMODE structure.) Or you can keep track of the current display settings:

*** Source Snippet Removed ***


Isn't ordered this is another piece of the log
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 720 x 480
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
....
VIDEOCARD INFO: 640 x 480 // here you can see the 640 x 480 is repeated...
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480

#4 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 06 September 2010 - 07:39 AM

I assume the same resolution is being returned multiple times for a reason (different refresh rates or color depths, maybe?), but there are various ways you can remove the duplicates if you wish. Examples include using std::set (as suggested previously), or using std::sort() along with std::unique().

Note that you may need to provide a comparator for the resolution data type that tests for either equality or 'less than', depending. (For 'less than', you can use a lexicographical comparison based on the width and height.)

#5 void main   Members   -  Reputation: 114

Like
0Likes
Like

Posted 06 September 2010 - 07:46 AM

The simplest solution is IMHO to create a little helper function, which will tell you if some DEVMODE with the same resolution is already contained in your vector. Something like this:

bool containsResolution(const std::vector<DEVMODE> &vec, const DEVMODE &dm)
{
std::vector<DEVMODE>::const_iterator iter = vec.begin();

while (iter != vec.end())
{
if ((*iter).dmPelsWidth == dm.dmPelsWidth && (*iter).dmPelsHeight == dm.dmPelsHeight)
return true;

iter++;
}

return false;
}


... then just use this in your loop for testing if newly enumerated DEVMODE is worth push_backing :-)


#6 codder88   Members   -  Reputation: 103

Like
0Likes
Like

Posted 06 September 2010 - 08:21 AM

Quote:
Original post by void main
The simplest solution is IMHO to create a little helper function, which will tell you if some DEVMODE with the same resolution is already contained in your vector. Something like this:

*** Source Snippet Removed ***

... then just use this in your loop for testing if newly enumerated DEVMODE is worth push_backing :-)


Ok i try :D

#7 iMalc   Crossbones+   -  Reputation: 2306

Like
0Likes
Like

Posted 06 September 2010 - 08:25 AM

I've personally already run into this exact issue and solved it by using a std::set I think. Just define the less-than operator to take into account the fields of your choice.

#8 ViperG   Members   -  Reputation: 206

Like
0Likes
Like

Posted 06 September 2010 - 08:51 AM

you need to also check for these values...

dm.dmDisplayFrequency
dm.dmBitsPerPel
dm.dmDefaultSource

Jyk was correct about different modes/pits/refresh rate per screen res.

I have also seen other intel chipsets reverse the x and y values because its an inverted supported resolution (no joke).

so instead of getting 1024x768 you get 768x1024.

Black Sky A Star Control 2/Elite like game

#9 codder88   Members   -  Reputation: 103

Like
0Likes
Like

Posted 06 September 2010 - 11:46 AM

Quote:
Original post by ViperG
you need to also check for these values...

dm.dmDisplayFrequency
dm.dmBitsPerPel
dm.dmDefaultSource

Jyk was correct about different modes/pits/refresh rate per screen res.

I have also seen other intel chipsets reverse the x and y values because its an inverted supported resolution (no joke).

so instead of getting 1024x768 you get 768x1024.


I logged in a txt and works :D i have intel chipset

#10 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 06 September 2010 - 12:48 PM

Quote:
Original post by void main
The simplest solution is IMHO to create a little helper function, which will tell you if some DEVMODE with the same resolution is already contained in your vector. Something like this:

*** Source Snippet Removed ***

... then just use this in your loop for testing if newly enumerated DEVMODE is worth push_backing :-)
That's definitely not the simplest solution :) You're doing a lot of unnecessary work there; the same thing can be accomplished using any number of methods (std::find(), std::find_if(), std::set, etc.) with much less effort.

#11 Dragonion   Members   -  Reputation: 131

Like
0Likes
Like

Posted 07 September 2010 - 11:42 AM

Quote:
Original post by codder88
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 720 x 480
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 800 x 600
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
VIDEOCARD INFO: 1024 x 768
....
VIDEOCARD INFO: 640 x 480 // here you can see the 640 x 480 is repeated...
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480
VIDEOCARD INFO: 640 x 480


The reason you apparently are getting duplicate values is that each of these resolutions have different update frequencies (refresh rates). Then, later on, when they seemingly appear again you get them once again, but this time with a different color depth. More specifically, what you are actually receiving is something like this:

VIDEOCARD INFO: 640 x 480, 60 Hz, 16 bpp
VIDEOCARD INFO: 640 x 480, 70 Hz, 16 bpp
VIDEOCARD INFO: 640 x 480, 75 Hz, 16 bpp
VIDEOCARD INFO: 640 x 480, 100 Hz, 16 bpp
.
.
.
VIDEOCARD INFO: 640 x 480, 60 Hz, 32 bpp // here you can see the 640 x 480 is repeated...
VIDEOCARD INFO: 640 x 480, 70 Hz, 32 bpp
VIDEOCARD INFO: 640 x 480, 75 Hz, 32 bpp
VIDEOCARD INFO: 640 x 480, 100 Hz, 32 bpp




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS