Solved

Delphi: How to change secondary display resolution

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Memory leak using records in a TVirtualStringTree 11 107
creating threads in delphi 1 80
Create a path if not exists 7 67
Convert MS Word document to a PDF file 9 59
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 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

20 Experts available now in Live!

Get 1:1 Help Now