Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi: How to change secondary display resolution

Posted on 2013-01-14
3
Medium Priority
?
870 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 1500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

782 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