Forum Discussion

abdul_rp's avatar
abdul_rp
Contributor
14 years ago

How to Get and Set the System Resolution using C#

Hi,



Can any one guide me how to Get and Set the Screen Resolution using C# in Runtime .



Regards,

AR

7 Replies

  • I found the solution for getting the screen resolution, But how to set in Runtime?



    var
    d = Sys["Desktop"];


    ShowMessage(d["Height"]);


    ShowMessage(d["Width"]);

  • karkadil's avatar
    karkadil
    Valued Contributor
    Hi,



    AFAIK, there is no simple way to do this in TestComplete.



    As a workaround, you can download a simple command line utility here and then run it from TestComplete like this



    Sys.OleObject("WScript.Shell").Run("C:\\chscrres.exe 800 600");

  • Hi,


    Following code is not changing the system Resolution , can you let me what could be the problem with the code.


    function SetDisplay(x,y,d)



    {


    var dm, dwLastError;


    res = -1;


    dm = Win32API["DEVMODE"]();


    if(Win32API["EnumDisplaySettings"](VarToInteger(0), -1, dm) != 0)


     


    {


    dm["dmPelsWidth"] = x;


    dm["dmPelsHeight"] = y;


    dm["dmBitsPerPel"] = d;


    res = Win32API["ChangeDisplaySettings"](dm, 0);


     


    }


    else


    {


    dwLastError = Win32API["GetLastError"]();


    Log["Error"]("Error code: " + VarToStr(dwLastError));


    }


    return res


    }



     



    function TestSetDisplay()





    // SetDisplay(1024, 768, 32);


    //


    // Log["Message"]("New resolution: " + VarToStr(Sys["Desktop"]["Width"]) +


    //


    // "x"+VarToStr(Sys["Desktop"]["Height"]));



    //Delay(2000);


    SetDisplay(1280, 1024, 64);


    Log["Message"]("New resolution: " + VarToStr(Sys["Desktop"]["Width"]) +


    "x"+VarToStr(Sys["Desktop"]["Height"]));


    }

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Abdul,



    Just a quick guess: are you sure that 64 bits/pixel is a correct value for the color depth?

    (This is in the SetDisplay(1280, 1024, 64); line.)

    Shouldn't it be 32 instead of 64? Or you are using 64-bit OS?
  • Hi Alex,



    Even i have tried with 32 Bit , Here also it is not working.



    Regards,

    Abdul
  • Alex,



    Thanks . I got the solution. It should be  32 Bit as I am working 32 Bit OS.



    Regards,

    Abdul