CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Posts
    5

    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

  2. #2
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    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.

  3. #3
    Join Date
    Oct 2004
    Posts
    5

    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

  4. #4
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    Re: How to change the screen size layout programmatically?

    From the docs: (MSDN)
    dmPelsWidth
    Specifies 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.
    dmPelsHeight
    Specifies 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.

  5. #5
    Join Date
    Oct 2004
    Posts
    5

    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

  6. #6
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    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.

  7. #7
    Join Date
    Oct 2004
    Posts
    5

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured