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

    Change resolution with ChangeDisplaySettings while desktop is extended causes black s


    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);
    lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST);
    bUpdateReg = false;
    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?


  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    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

    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