I'm trying to use ChangeDisplaySettingsEx in Delphi 7 to set a specific monitor as Primary. In Windows.pas, it is defined as
function ChangeDisplaySettingsEx(lpszDeviceName: PChar; var lpDevMode: TDeviceMode;
wnd: HWND; dwFlags: DWORD; lParam: Pointer): Longint; stdcall;
In MSDN, the documentation for ChangeDisplaySettingsEx has the following comment for lpDevMode: "If lpDevMode is NULL, all the values currently in the registry will be used for the display setting."
My objective is to change the Primary monitor on a system with two active monitors, without changing anything else - resolution, bit depth, etc, should all remain the same. It seems like passing lpDevMode as null (nil) is the method that is provided to accomplish this.
However, lpDevMode is defined as a packed record type (TDeviceMode), not a pointer type, in Delphi's Windows.pas. Apparently, the Delphi interface to the Windows API performs the translation to the pointers used by Windows API 'behind the scenes'.
I tried calling it like this:
var
alldevs : array[0..maxdev] of TDisplayDevice;
lpDevMode : pointer;
begin
lpDevMode := nil;
lparam := nil;
my_hwnd := nil;
{... snip....}
with alldevs[NewPri] do
ChangeDisplaySettingsEx(devicename,TDeviceMode(lpDevMode),my_hwnd,CDS_SET_PRIMARY,lparam);
That gives me an invalid typecast error on "TDeviceMode(lpDevMode)". How can I pass a null pointer to ChangeDisplaySettingsEx? Or is there a better way to do this?