Solved

Delphi: How to change secondary display resolution

Posted on 2013-01-14
3
799 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

816 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

8 Experts available now in Live!

Get 1:1 Help Now