Solved

Current graphics mode

Posted on 2000-02-14
6
154 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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