CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2014
    Posts
    10

    Change resolution with ChangeDisplaySettings while desktop is extended causes black s

    Hi.

    I use this function to change resolution:

    ChangeResolution(NULL,1440, 900);

    bool ChangeResolution(WCHAR *sDeviceName, int iNewW, int iNewH)
    {
    DEVMODE oDEVMODE = { 0 };
    oDEVMODE.dmSize = sizeof(DEVMODE);
    EnumDisplaySettings(sDeviceName, ENUM_CURRENT_SETTINGS, &oDEVMODE);

    oDEVMODE.dmPelsWidth = iNewW;
    oDEVMODE.dmPelsHeight = iNewH;
    bool bUpdateReg = true;
    LONG lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST | CDS_UPDATEREGISTRY);
    if (lRet != DISP_CHANGE_SUCCESSFUL)
    {
    lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST);
    bUpdateReg = false;
    }
    if (lRet == DISP_CHANGE_SUCCESSFUL)
    lRet = ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

    return lRet == DISP_CHANGE_SUCCESSFUL;
    }

    This works well.

    Problem happens when I desktop is extended (pressing the Windows key + P and choosing "extend"). Then while desktop is extended (to non psychical display), after using my ChangeResolution the screen become black as soon as my function calls ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

    The way to get the screen back is to press Windows Key+P again and then press Enter.

    (Since screen is black you do not really see what you do).

    It becomes black no matter which new resolution i set.

    If I try to change resolution while in extended mode but from Control Panel that is works great so the problem is with my function.

    I think this happens since when i change resolution for the default screen (NULL), i also need to change something for the virtual screen - but i am not sure.

    If that helps, seems that the screen goes black since for some reason after calling the changeresolution function, display1 is removed and display2 (the virtual screen) is on, but since there is not really physical display2 then i see black screen.

    Question is why Display1 is removed when changing resolution?

    Any help?

    Thanks!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Change resolution with ChangeDisplaySettings while desktop is extended causes bla

    You may try the ChangeDisplaySettingsEx function instead.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2014
    Posts
    10

    Re: Change resolution with ChangeDisplaySettings while desktop is extended causes bla

    Already tried ChangeDisplaySettingsEx with \\\\.\\DISPLAY1
    Same results.

Tags for this Thread

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