PDA

View Full Version : DLL: SetDisplaySettings


RizlaUK
06-11-2007, 05:19 PM
This dll will enable you to set the users display settings to suit your app,


function name: ChangeDisplaySettings

Arguments: width, height, Depth, Freq, Permanent (0 false, 1 = true)

Returns:

0 = The settings change was successful.
1 = The computer must be restarted in order for the graphics mode to work.
-4 = An invalid set of flags was passed in.
-1 = The display driver failed the specified graphics mode.
-2 = The graphics mode is not supported.
-3 = Windows NT only: Unable to write settings to the registry.


i have set this into a easy to use function for apms, the function will resize the screen and reposition the app so its in the center

--Global function for the screen settings, !!!DO NOT EDIT!!!
function ChangeDisplaySettings(width,height,Depth,Freq,Perm anent)
args = width..", "..height..", "..Depth..", "..Freq..", "..Permanent
result = DLL.CallFunction("AutoPlay\\Docs\\DLLDisplaySettings.dll", "ChangeDisplaySettings", args, DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);
if result == "0" then
local hWnd = Application.GetWndHandle();
local WndSize = Window.GetSize(hWnd);
local ScreenRes = System.GetDisplayInfo();
local NewPos_X = (ScreenRes.Width - WndSize.Width)/2;
local NewPos_Y = (ScreenRes.Height - WndSize.Height)/2;
Window.SetPos(hWnd, NewPos_X, NewPos_Y);
else
if result == 1 then err = "The computer must be restarted in order for the graphics mode to work"
elseif result == "-4" then err = "An invalid set of flags was passed in"
elseif result == "-1" then err = "The display driver failed the specified graphics mode"
elseif result == "-2" then err = "The graphics mode is not supported"
elseif result == "-3" then err = "Unable to write settings to the registry"
end
Dialog.Message("Error", err, MB_OK, MB_ICONNONE, MB_DEFBUTTON1);
end
end


which would be called with this
-- arguments: width, height, Depth, Freq, Permanent (0 false, 1 = true)
ChangeDisplaySettings(800,600,16,70,0)

if you set permanent to false (0) then the users original settings will be restored when your app exits

you can download the amp example file (apz) or the dll and function in text file(zip)

wasim21k
06-12-2007, 03:38 AM
thanx m8, really nice work.

SiNisTer
06-12-2007, 04:58 AM
Man you are on fire! - You are simply all over the place...It is just great to see:yes

Oh Wait, I err...kinda forgot my manners - Thanks!:D

Buffman
06-13-2007, 01:30 PM
Yeah way to go RizlaUK! This DLL is very helpful for something I'm working on!

yosik
06-13-2007, 04:11 PM
Thanks Rizla.
This type of Dll was on the forum a couple of years back and I want to repeat here what I said then.
I think changing the screen res for a user on a permanent basis is NOT something acceptable to do. I, for one, would be VERY angry at the app developer if such a thing would occur.
Yossi

Buffman
06-13-2007, 05:16 PM
Hi Yosik,

I agree, if the behavior is unexpected or unwanted. There may be instances where a user wants their resolution changed, and needs it handled programtically.

If a user needs to swap between different resolutions quickly, creating an app with a hotkey would be very beneficial. One example I'm using this for is a bug on my Macbook Pro running Vista. Whenever I come out of sleep mode initiated by a lid close, the resolution changes to its lowest setting. Its a bug in the driver, and without a fix at the moment. So I've created an app that changes the resolution whenever my system comes out of sleep.

I think your comment is a general rule of thumb for any developer. If a behavior is unexpected or may create a condition that a user does not want, then its poor practice.

Having said that, there are many benefits to being able to change a resolution with this DLL.

My 2 cents...

hady
05-14-2008, 05:30 PM
it change refresh rate to 60 allways ?

Intrigued
05-14-2008, 05:37 PM
Thanks RizlaUK, I mirrored this on amsuser.com:

http://www.amsuser.com/ams/examples/DLLDispalySettings-AMS7-RizlaUK.apz

thachsn1
05-14-2008, 10:09 PM
if a users system resolution is 800x600 and my project page resolution is
1024x768 and I use the dll to set the system resolution to 1024x768 for some reason the page only covers 800x600 of the screen when it should cover the whole screen. (note) not using title bar, using border style for project.
it only works correctly when switching from a higher res to a lower res.
example :
system res 1024x768
page res 800x600
then use dll to change system res to 800x600

rexzooly
05-15-2008, 06:15 AM
if a users system resolution is 800x600 and my project page resolution is
1024x768 and I use the dll to set the system resolution to 1024x768 for some reason the page only covers 800x600 of the screen when it should cover the whole screen. (note) not using title bar, using border style for project.
it only works correctly when switching from a higher res to a lower res.
example :
system res 1024x768
page res 800x600
then use dll to change system res to 800x600

make you app dynamic and have it mini 800X600 and have it resize to the
screens resalsion

longedge
05-15-2008, 06:38 AM
it change refresh rate to 60 allways ?

Just looking at this post in isolation - that is exactly as it should be. Driving a monitor above it's limit could cause permanent damage. As far as refresh rate is concerned, 60Hertz is the safe baseline apart from H&S considerations if it's a CRT Monitor.

Fiddling about with monitor settings is an absolute No No as far as I'm concerned. Far better to design to accomodate the existing user settings.

SteevieNiteHeat
06-20-2008, 02:04 PM
RizlaUK: thank very much for this little gem!

By using your dll & app I have a workable fix for my month long problem

2 cut a story shot, remote desktop wasnt liking my new graphics card and when trying to connect to pcs it was really slow and slugish, then i found out i had to set the colour to 16bit from 24 and then it would work,

so i have made an AmS application that when clicked will automaticlly set colour to 16bit, load up RDC and with the switch of the pc i want to connnect to it, does this automatically, and when RDC is closed, the ams application returns my screen to normal so fank you more rizla for this beauty :yes :yes :yes :)