Solved

Delphi: How to change secondary display resolution

Posted on 2013-01-14
3
781 Views
Last Modified: 2013-01-14
Hi i want to change the secondary display resolution, im using the following code
but it only changes the main display.

function NewRes(XRes, YRes: DWORD; devnum : cardinal): Integer;
var
DevMode: TDeviceMode;
lpDisplayDevice: TDisplayDevice;
begin

  lpdisplaydevice.cb := sizeof(lpdisplaydevice);
  EnumDisplayDevices(nil,devnum,lpDisplayDevice,0 );   

EnumDisplaySettings(lpdisplaydevice.DeviceName, 0, DevMode);
DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or
DM_DISPLAYFREQUENCY;
DevMode.dmPelsWidth := XRes;
DevMode.dmPelsHeight := YRes;
//DevMode.dmDisplayFrequency := Frequency;
Result := ChangeDisplaySettings(DevMode, 0);
end;

Open in new window

0
Comment
Question by:Slinkkkk
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 38774931
Enum Display Settings gets information about one of the graphics modes for a single display device.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162611(v=vs.85).aspx

I think you may have wanted to call EnumDisplayDevices instead.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162609(v=vs.85).aspx

That is, only if you need that information.

ChangeDisplaySettings only changes the settings for the default display.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183411(v=vs.85).aspx

If you need to change settings on other displays, use ChangeDisplaySettingsEx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183413(v=vs.85).aspx

Let me know if you need more...
0
 

Author Comment

by:Slinkkkk
ID: 38775069
Thx developmentguru,
Here goes the working code if someone else need it

function NewRes(XRes, YRes: DWORD; devnum : cardinal): Integer;
var
DevMode: TDeviceMode;
lpDisplayDevice: TDisplayDevice;
begin

  lpdisplaydevice.cb := sizeof(lpdisplaydevice);
  EnumDisplayDevices(nil,devnum,lpDisplayDevice,0 );   

EnumDisplaySettings(lpdisplaydevice.DeviceName, 0, DevMode);
DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or
DM_DISPLAYFREQUENCY;
DevMode.dmPelsWidth := XRes;
DevMode.dmPelsHeight := YRes;
//DevMode.dmDisplayFrequency := Frequency;
Result := ChangeDisplaySettingsEx (lpdisplaydevice.DeviceName,DevMode,0, (CDS_UPDATEREGISTRY), nil);
end;

Open in new window

0
 

Author Closing Comment

by:Slinkkkk
ID: 38775074
function NewRes(XRes, YRes: DWORD; devnum : cardinal): Integer;
var
DevMode: TDeviceMode;
lpDisplayDevice: TDisplayDevice;
begin

  lpdisplaydevice.cb := sizeof(lpdisplaydevice);
  EnumDisplayDevices(nil,devnum,lpDisplayDevice,0 );  

EnumDisplaySettings(lpdisplaydevice.DeviceName, 0, DevMode);
DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or
DM_DISPLAYFREQUENCY;
DevMode.dmPelsWidth := XRes;
DevMode.dmPelsHeight := YRes;
//DevMode.dmDisplayFrequency := Frequency;
Result := ChangeDisplaySettingsEx (lpdisplaydevice.DeviceName,DevMode,0, (CDS_UPDATEREGISTRY), nil);
end;
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now