[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Graphics mode problems

I want to determine the current graphics mode so I can save that, then change the current mode using ChangeDisplaySettings, and finially when the program exits, restore the graphics mode to the origional saved mode.  How can I get this current graphics mode when I run the program?  I have found nothing on getting the exact graphics mode anywhere (exact = current refresh etc.)
It seems windows must store that info somewhere.

0
Signet
Asked:
Signet
  • 6
  • 6
  • 2
  • +2
1 Solution
 
edeyCommented:
try getDeviceCaps using the dc from getDC

GL
Mike
0
 
SignetAuthor Commented:
Mike...Ive done that..listed all modes out..etc. but I want the current mode #...that info doesnt seem to appear in GetDeviceCaps return data..I get alot of data, just no graphic mode number.
0
 
SignetAuthor Commented:
I can get all the modes listed out that the card is capable of, I just want the current mode that the card is in.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SignetAuthor Commented:
I can get all the modes listed out that the card is capable of, I just want the current mode that the card is in.
0
 
DrDelphiCommented:
var newdevmode:Tdevmode;
begin
     Memo1.lines.CLear;
     newdevmode.dmsize:=sizeof(newdevmode);
     enumdisplaysettings(nil,0,newdevmode);
     memo1.lines.add('bits per pixel ='+inttostr(newdevmode.dmBitsPerPel));
     Memo1.lines.add('Display frequency= '+inttostr(newDevmode.dmDisplayFrequency));
     Memo1.lines.add('Pixel width ='+ inttostr(newdevmode.dmPelsWidth));
     Memo1.lines.add('Pixel height ='+inttostr(newdevmode.dmPelsHeight));
     Memo1.lines.add('');
     Memo1.lines.add('When you call the EnumDisplaySettings function, the dmDisplayFrequency member ');
     Memo1.lines.add('may return with the value 0 or 1. These values represent the display hardware''s');
     Memo1.lines.add('default refresh rate. This default rate is typically set by switches on a ');
     Memo1.lines.add('display card or computer motherboard, or by a configuration program that does ');
     Memo1.lines.add('not use Win32 display functions ');
end;
0
 
SignetAuthor Commented:
Dr. Delphi - it didnt work, the same value is returned no matter what mode your initally in, and its not the right one.  Thank for trying though.
0
 
DrDelphiCommented:
I guess my question would have to be why aren't you simply storing the current settings in a static DEVMODE, Changing the settings as needed and then passing that DEVMODE back to ChangeDisplaySettings when you are done?
When you say that the value is the same and it is wrong, it makes me wonderwhich value you are looking at, also. ChangeDisplaySettings only deals with :

dmBitsPerPel      Bits per pixel
dmPelsWidth      Pixel width
dmPelsHeight      Pixel height
dmDisplayFlags      Mode flags
dmDisplayFrequency      Mode frequency


dmDisplayFrequency, as I explaineed earlier may very well NEVER come back correct and there is nothing to be done for that. All the other parameters are covered... what EXACTLY are  you trying to do?




0
 
DrDelphiCommented:
I guess my question would have to be why aren't you simply storing the current settings in a static DEVMODE, Changing the settings as needed and then passing that DEVMODE back to ChangeDisplaySettings when you are done?
When you say that the value is the same and it is wrong, it makes me wonder which value you are looking at, also. ChangeDisplaySettings only deals with :

dmBitsPerPel      Bits per pixel
dmPelsWidth      Pixel width
dmPelsHeight      Pixel height
dmDisplayFlags      Mode flags
dmDisplayFrequency      Mode frequency


dmDisplayFrequency, as I explaineed earlier may very well NEVER come back correct and there is nothing to be done for that. All the other parameters are covered... what EXACTLY are  you trying to do?




0
 
RadlerCommented:
Hi Signet;

Is a bit scrambled, but is what you wants.

//DFM
object Form1: TForm1
  Left = 222
  Top = 139
  Width = 479
  Height = 283
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 128
    Top = 64
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 0
  end
  object Button1: TButton
    Left = 48
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Load Modes'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 152
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Set Mode'
    Enabled = False
    TabOrder = 2
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 248
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Reset Mode'
    Enabled = False
    TabOrder = 3
    OnClick = Button3Click
  end
end


//CODE
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
       procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
       { Private declarations }
       Selected : DWORD;
  public
       { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
      DevMode : TDeviceMode;
      ModeID, HRes, VRes : DWORD;
      Bits : DWORD;
      Ok : boolean;
begin
      Bits := GetDeviceCaps(Canvas.Handle, BITSPIXEL);
      HRes := GetDeviceCaps(Canvas.Handle, HORZRES);
      VRes := GetDeviceCaps(Canvas.Handle, VERTRES);
      ComboBox1.Items.Clear;
      ModeID:=0;
      EnumDisplaySettings(nil, ModeID, DevMode);
      ComboBox1.Items.Add(Format('%d bits, %d x %d', [DevMode.dmBitsPerPel, DevMode.dmPelsWidth,
                                            DevMode.dmPelsHeight]));
      Ok := True;
      while Ok do begin
            if (Bits = DevMode.dmBitsPerPel) and (HRes = DevMode.dmPelsWidth) and ( VRes = DevMode.dmPelsHeight ) then begin
                  Selected:=ModeId;
            end;
            Inc(ModeID);
            Ok := EnumDisplaySettings(nil, ModeID, DevMode);
            if Ok then begin
                  ComboBox1.Items.Add(Format('%d bits, %d x %d', [DevMode.dmBitsPerPel, DevMode.dmPelsWidth,
                                                         DevMode.dmPelsHeight]));
            end;
      end;
      ComboBox1.ItemIndex:=Selected;
      Button2.Enabled:=True;
      Button1.Enabled:=False;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
      DevMode : TDeviceMode;
begin
      EnumDisplaySettings( nil, ComboBox1.ItemIndex, DevMode );
      DevMode.dmFields:=DM_BITSPERPEL      + DM_PELSWIDTH + DM_PELSHEIGHT + DM_DISPLAYFLAGS + DM_DISPLAYFREQUENCY;
      ChangeDisplaySettings( DevMode, 0 );
      Button3.Enabled:=True;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
      DevMode : TDeviceMode;
begin
      EnumDisplaySettings( nil, Self.Selected, DevMode );
      DevMode.dmFields:=DM_BITSPERPEL      + DM_PELSWIDTH + DM_PELSHEIGHT + DM_DISPLAYFLAGS + DM_DISPLAYFREQUENCY;
      ChangeDisplaySettings( DevMode, 0 );
      ComboBox1.ItemIndex:=Self.Selected;
end;

end.


Good Luck !!

T++, Radler.
0
 
DrDelphiCommented:
I stuttered a bit there! <g>
0
 
SignetAuthor Commented:
I seem to be having trouble communicating the thought that what I need is the current mode #...NOT the attributes of any given mode.  I dont care about HRez, VRez or anything..I just want to save the current mode and restore it later....Radler..your example above tries to find the current mode through matching via the devmode table...thats ok up to a point but the problem comes in when you have a possible 5 modes for the same VRez, HRez and # of colors..the difference for those modes in that case is the refresh rates...and you will only return -1 in Win 95, 98...only will work in NT.  Someone much know something that can retreive the current graphics mode # using the Windows 95/98/NT API...if Windows knows it..so can we..somehow.
0
 
DrDelphiCommented:
Signet, you seem fixated with the concept of a single graphics mode... something like the old ScreenMode in DOS... the fact is that there is no such animal. Your "Graphics Mode" is a compilation of all the parameters that I ( and now others) are trying to convey to you. The main sticking point is the refresh rate, and again, acoording to M$'s own help files, there isn't diddly you can do about it. You CAN store each of the DEVMODES supported and revert back at any time, though. Is this not enough?


0
 
DrDelphiCommented:
Further beating the dead horse:

From the WinAPI help file under DEVMODE:

dmDisplayFrequency

Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member.
When you call the EnumDisplaySettings function, the dmDisplayFrequency member may return with the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use Win32 display functions such as ChangeDisplaySettings.
0
 
MadshiCommented:
Use this to install your mode:

ChangeDisplaySettings(yourDevMode, 0);

Don't care about reading the old mode. Just call this to restore it (Windows does that for you):

ChangeDisplaySettings(PDevMode(nil)^, 0);

Regards, Madshi.
0
 
RadlerCommented:
Hi Madshi,

I'm envolved with Detours yet. and really need you help %-(

Hi Signet,
I imagined that restore previous configuration was sufficient.
Well, You can read the default refresh rate but change it is possible only trught registry or some call to video card driver.
Before do it remember that to optmized refresh rate the monitor profile made a great diference and is better set in acordance wiht him.

T++, Radler.
0
 
SignetAuthor Commented:
Thanx Madshi!!!  That hit the spot.  Sorry took so long to get back to you with your points.

Signet
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now