How to change the screen size layout programmatically?
Hi, gurus:
Does anyone know how to change the screen size layout programmatically?
This is the case:
I am changing the screen resolution programmatically for specific action from 800x600 to 1280x1024. Because the ratios are different for these resolutions the screen layouts are different. In the second case the screen layout compressed from the sides. I need to expand the layout from the sides for the size of monitor.
Any suggestions?
Thanks in advance
Re: How to change the screen size layout programmatically?
Yes, there are some APIs for it... Use two functions calls:
1. EnumDisplaySettings
2. ChangeDisplaySettings
Use the first function to get current settings (DEVMODE structure). Change the resolution in DEVMODE structure. Call the second function with the modified DEVMODE structure.
Re: How to change the screen size layout programmatically?
Quote:
Originally Posted by j0nas
Yes, there are some APIs for it... Use two functions calls:
1. EnumDisplaySettings
2. ChangeDisplaySettings
Use the first function to get current settings (DEVMODE structure). Change the resolution in DEVMODE structure. Call the second function with the modified DEVMODE structure.
I think that I could use ChangeDisplaySettings only for the resolution. If I could use it to inrease the width of the screen output it's not clear for me what the member of the DEVMODE structure is responsible for this action.
Thanks,
Sergey
Re: How to change the screen size layout programmatically?
From the docs: (MSDN)
Quote:
dmPelsWidthSpecifies the width, in pixels, of the visible device surface. Display drivers use this member, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member.
dmPelsHeightSpecifies the height, in pixels, of the visible device surface. Display drivers use this member, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member.
Re: How to change the screen size layout programmatically?
Quote:
Originally Posted by j0nas
From the docs: (MSDN)
Let's I have the screen resolution 800x600
The screen looks on the display like
---------------------
|o-----------------o|
|o|xxxxxxxxxxxxxxx|o|
|o|xxxxxxxxxxxxxxx|o|
|o|xxxxxxxxxxxxxxx|o|
|o|xxxxxxxxxxxxxxx|o|
|o|xxxxxxxxxxxxxxx|o|
|o-----------------o|
---------------------
If I will use the code:
DEVMODE dm;
ZeroMemory(&dm, sizeof(DEVMODE));
dm.dmSize = sizeof(DEVMODE);
dm.dmBitsPerPel = 32;
dm.dmPelsWidth = 1280;
dm.dmPelsHeight = 1024;
dm.dmDisplayFrequency = 60;
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
ChangeDisplaySettings(&dm, 0);
This action will change the screen resolution to 1280x1024 32-bit color 60 Herts.
And the screen layout on the display will look like:
-----------------------
|ooo--------------ooo|
|ooo|xxxxxxxxxxxx|ooo|
|ooo|xxxxxxxxxxxx|ooo|
|ooo|xxxxxxxxxxxx|ooo|
|ooo|xxxxxxxxxxxx|ooo|
|ooo|xxxxxxxxxxxx|ooo|
|ooo--------------ooo|
-----------------------
And the question is how could I increase the screen layout sides (left and right) close to display size.
Thanks again,
Sergey
Re: How to change the screen size layout programmatically?
Oh.. I guess that you have to do something with the monitor then... You'll probably get the same result when chaning the resolution manually--don't you?
On many monitors, there is a button och setting called auto-size or something. I don't know if it is possible to auto-size programmatically.
Re: How to change the screen size layout programmatically?
Quote:
Originally Posted by j0nas
Oh.. I guess that you have to do something with the monitor then... You'll probably get the same result when chaning the resolution manually--don't you?
On many monitors, there is a button och setting called auto-size or something. I don't know if it is possible to auto-size programmatically.
Thanks,
It's absolutly true. But the user does not care about this settings. He wants to see the right screen size when he is doing the specific action pressing the button on application.
I am trying to find the solution for several days and I have still no answer.
Sergey