Solved

Current graphics mode

Posted on 2000-02-14
6
153 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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