?
Solved

Current graphics mode

Posted on 2000-02-14
6
Medium Priority
?
158 Views
Last Modified: 2010-04-04
How can I return the current graphics mode?
0
Comment
Question by:Signet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
Radler earned 150 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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 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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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