Solved

Graphics mode problems

Posted on 2000-02-21
16
300 Views
Last Modified: 2010-04-04
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
Comment
Question by:Signet
  • 6
  • 6
  • 2
  • +2
16 Comments
 
LVL 6

Expert Comment

by:edey
Comment Utility
try getDeviceCaps using the dc from getDC

GL
Mike
0
 

Author Comment

by:Signet
Comment Utility
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
 

Author Comment

by:Signet
Comment Utility
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
 

Author Comment

by:Signet
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
 

Author Comment

by:Signet
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:Radler
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
I stuttered a bit there! <g>
0
 

Author Comment

by:Signet
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
Comment Utility
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
 
LVL 4

Expert Comment

by:Radler
Comment Utility
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
 

Author Comment

by:Signet
Comment Utility
Thanx Madshi!!!  That hit the spot.  Sorry took so long to get back to you with your points.

Signet
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

6 Experts available now in Live!

Get 1:1 Help Now