Solved

Current graphics mode

Posted on 2000-02-14
6
157 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
Industry Leaders: 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 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

Industry Leaders: 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!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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