Solved

Delphi: How to change secondary display resolution

Posted on 2013-01-14
3
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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