Solved

Current graphics mode

Posted on 2000-02-14
6
151 Views
Last Modified: 2010-04-04
How can I return the current graphics mode?
0
Comment
Question by:Signet
6 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2520229
hi,
here a couple of ways:

function GetPixelFormat:TPixelFormat;
var
  DesktopDC: HDC;
BitsPerPixel: integer;
begin
DesktopDC := GetDC(0);
Result:= pf8Bit;
  try
    BitsPerPixel := GetDeviceCaps(DesktopDC, BITSPIXEL) *
GetDeviceCaps(DesktopDC, PLANES);
  case BitsPerPixel of
                      4: Result:= pf4Bit;
                      8: Result:= pf8Bit;
                    16: Result:= pf16Bit;
                    24: Result:= pf24Bit;
                    else
                    Result:= pf8Bit;
                    end;
  finally
    ReleaseDC(0, DesktopDC);
  end;
end;



function GetColors: Integer;
  var
    DC: HDC;
  begin
  DC := GetDC(GetDesktopWindow);
  try
    Result := GetDeviceCaps(DC, NUMPLANES) *
      GetDeviceCaps(DC, BITSPIXEL);
  finally
    ReleaseDC(GetDesktopWindow, DC) end end;


Regards Barry

0
 

Author Comment

by:Signet
ID: 2520271
Actually I need the mode #...as in a number that would be used by a funtion such as this EnumDisplaySettings(nil, modenum, dm);  I want to know the current mode # when I start a program.
0
 
LVL 6

Expert Comment

by:edey
ID: 2520421
from win32.hlp:


The GetGraphicsMode function retrieves the current graphics mode for the specified device context.

int GetGraphicsMode(

    HDC  hdc       // handle of device context
   );



GL
Mike
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Accepted Solution

by:
Radler earned 50 total points
ID: 2520680
Hi Signet;

I imagine that is this:

//###Code
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
      DevMode : TDeviceMode;
      Selected, ModeID, HRes, VRes : integer;
      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;
end;

end.


//##DFM
object Form1: TForm1
  Left = 218
  Top = 134
  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 = 152
    Top = 56
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 0
  end
  object Button1: TButton
    Left = 184
    Top = 104
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end

Good luck.

T++, Radler.
0
 
LVL 4

Expert Comment

by:Radler
ID: 2520687
A more ellegant declaration to integers types would be DWORD's.

T++, Radler.
0
 

Author Comment

by:Signet
ID: 2521424
Thanx..this should work..was hoping not to have to play 'find and match' to get it though...here are the points..but do you know of a more direct way?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange message in Delphi 10 Seattle 1 465
How to convert wav to mp3 in delphi 9 138
delphi custom sort exception 6 111
code issue 8 85
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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

13 Experts available now in Live!

Get 1:1 Help Now