Ask a Question

How to Get and Set the System Resolution using C#

abdul_rp
Contributor

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 7
abdul_rp
Contributor

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
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");
AlexKaras
Champion Level 3

Hi Abdul,



See also http://www.automatedqa.com/support/viewarticle.aspx?aid=8962
Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
abdul_rp
Contributor


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
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?
Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
abdul_rp
Contributor

Hi Alex,



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



Regards,

Abdul
abdul_rp
Contributor

Alex,



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



Regards,

Abdul
cancel
Showing results for 
Search instead for 
Did you mean: