Windows change system resolution c++
<p>I am trying to change system resolution programatically. What I need to achieve is set system resolution to maximum value. </p>

<p>Below is code the code which change the screen resolution to maximum available value. </p>

<pre><code>       DEVMODE devmode = { 0 };

       int i=0;
       QList&lt;int&gt;widths;
       QList&lt;int&gt;heights;
       while (1) {
           if(EnumDisplaySettings( NULL,i, &amp;devmode )!=true)
                break;

           widths.append(devmode.dmPelsWidth);
           heights.append(devmode.dmPelsHeight);

           qDebug()&lt;&lt;devmode.dmPelsWidth&lt;&lt;" X "&lt;&lt;devmode.dmPelsHeight;

           i++;

       }

       EnumDisplaySettings( NULL,ENUM_CURRENT_SETTINGS, &amp;devmode );

       devmode.dmSize = sizeof(DEVMODE);
       devmode.dmPelsWidth = widths.at(widths.size()-1); //take last item maximum value
       devmode.dmPelsHeight = heights.at(widths.size()-1); //take last item maximum value

       long result = ChangeDisplaySettings(&amp;devmode, DM_PELSWIDTH || DM_PELSHEIGHT);
</code></pre>

<p>And it works fine when,</p>

<ol>
<li>When the system resolution is maximum(1920x1080) I change to the same value.</li>
<li>When the system resolution is higher and I am changed to lower value. </li>
</ol>

<p>But it doesn't work when I am changing from lower value to higher, like current resolution is 1600X900 and when I am changing to 1920x1080 then it wont work.
And I am getting -2 as return value and which stand for <code>The graphics mode is not supported</code> on the doc.</p>