mercredi 31 janvier 2018

ChangeDisplaySettingsEx return code -2

I trying rotate the screen 360º, but the function ChangeDisplaySettingsEx return -2, if you know the reason helpme. I try too create second variable with the struct DEVMODE, but this doesn't works.

Is problem of my screen driver ? Is problem of my OS ? In my case is Windows 10 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

My code here:

#include "stdafx.h"
#include<windows.h>
#include<iostream>
#include <chrono>
#include <thread>

using namespace std;

//enum version { char nombre[] = "quesito", int version = 15 };

namespace tipos_de_campo_base {
    long int vertical = 544997536; //Default
    long int horizontal = DM_DISPLAYORIENTATION; //128
}

class abstractclass {
public:
    virtual void definir_dev(DEVMODE * dm) {
        //cout << dm << endl;
        ZeroMemory(dm, sizeof(dm));
        //cout << dm << endl;
        dm->dmSize = sizeof(dm);
    }
    //pura
    virtual int get_len() = 0;
    virtual void a_dormir(int sec) {
        this_thread::sleep_for(chrono::milliseconds(sec));
    }
};

class testing : public abstractclass{
    int array_orientation[3] = { DMDO_90,DMDO_180,DMDO_270 };
public:
    int ret_arr_val(int i) {
        return this->array_orientation[i];
    }
    int get_len() {
        return sizeof(this->array_orientation) / sizeof(this->array_orientation[0]);
    }
};

int main(){
    testing orientation;
    DEVMODE xd;
    DEVMODE horizontal; 
    orientation.definir_dev(&xd);
    if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &xd))
    {
        DWORD dwTemp = xd.dmPelsHeight;
        xd.dmPelsHeight = xd.dmPelsWidth;
        xd.dmPelsWidth = dwTemp;
        xd.dmFields = tipos_de_campo_base::vertical;
        //xd.dmFields = tipos_de_campo_base::horizontal; //Lo pone por default por lo cual sobra //en este caso es para usar DMDO_90
        for (int me = 0; me < 1;me++) {
            for (int xn = 0; orientation.get_len() > xn; xn++) {
                if (orientation.ret_arr_val(xn) == DMDO_90 || orientation.ret_arr_val(xn) == DMDO_270) {
                    cout << "Vertical: " << endl;
                    cout << orientation.ret_arr_val(xn) << endl;
                    xd.dmDisplayOrientation = orientation.ret_arr_val(xn);
                    cout << ChangeDisplaySettingsEx(NULL, &xd, NULL, CDS_RESET, NULL) << endl;
                    orientation.a_dormir(2000);
                }
                else {
                    cout << "Horizontal: " << endl;
                    cout << orientation.ret_arr_val(xn) << endl;
                    xd.dmDisplayOrientation = orientation.ret_arr_val(xn);
                    cout << ChangeDisplaySettingsEx(NULL, &xd, NULL, CDS_RESET, NULL) << endl;
                    orientation.a_dormir(2000);
                }
            }
            xd.dmFields = tipos_de_campo_base::horizontal;
            xd.dmDisplayOrientation = DMDO_DEFAULT;
            cout << ChangeDisplaySettingsEx(NULL, &xd, NULL, CDS_RESET, NULL) << endl;
        }
        system("pause");
    }
}

Aucun commentaire:

Enregistrer un commentaire