🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14626

Re: Change resolution

#14626
From: Dumboo
Date: Tue, 05 Aug 2003 04:39
246 lines
8678 bytes
//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

int currmode, TIMEOUT=15;


//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//--------------------------------------------------------------------------
-

void __fastcall TForm1::SetModeBtnClick(TObject *Sender)
{
 DEVMODE DevMode;
DWORD Mode=0;
int SelectedRow;
LONG Result;
HDC hdc;

DevMode.dmSize=sizeof(DevMode);

EnumDisplaySettings(
    NULL, // LPCTSTR lpszDeviceName -> specifies the display device
    Mode,    // DWORD iModeNum -> specifies the graphics mode
    &DevMode // LPDEVMODE lpDevMode -> points to structure to receive
settings
    );

// We get the desired mode from the string grid
SelectedRow=StringGrid1->Row;
Mode=StrToInt(StringGrid1->Cells[0][SelectedRow]);

// Now we let EnumDisplaySettings fill the DevMode structure with
// information about the desired mode for us
EnumDisplaySettings(
    NULL, // LPCTSTR lpszDeviceName -> specifies the display device
    Mode,    // DWORD iModeNum -> specifies the graphics mode
    &DevMode // LPDEVMODE lpDevMode -> points to structure to receive
settings
    );

// See Win32.hlp
// ChangeDisplaySettings asks the graphic driver to change the display mode
Result=ChangeDisplaySettings(
    &DevMode, // LPDEVMODE lpDevMode,
    CDS_UPDATEREGISTRY // DWORD dwflags (change the mode dynamically and
                       //                update the registry)
    );

switch (Result) {
  case DISP_CHANGE_SUCCESSFUL: //The settings change was successful.
    // Let's give the user the chance to undo changes
    Timer1->Enabled=true;
    Form2->ProgressBar1->Position=0;
    if (mrOk == Form2->ShowModal()) // the user is happy
      currmode=Mode;
    else {  // either the user pressed Cancel or we had a timeout
            // Let's undo changes
      EnumDisplaySettings(NULL, currmode, &DevMode);
      ChangeDisplaySettings(&DevMode, CDS_UPDATEREGISTRY);
      }
//    Application->MessageBox("DISP_CHANGE_SUCCESSFUL", "Status", MB_OK);
    break;
  case DISP_CHANGE_RESTART: //The computer must be restarted in order for
the graphics mode to work.
    Application->MessageBox("DISP_CHANGE_RESTART", "Status", MB_OK);
    break;
  case DISP_CHANGE_BADFLAGS: //An invalid set of flags was passed in.
    Application->MessageBox("DISP_CHANGE_BADFLAGS", "Status", MB_OK);
    break;
  case DISP_CHANGE_FAILED: //The display driver failed the specified
graphics mode.
    Application->MessageBox("DISP_CHANGE_FAILED", "Status", MB_OK);
    break;
  case DISP_CHANGE_BADMODE: //The graphics mode is not supported.
    Application->MessageBox("DISP_CHANGE_BADMODE", "Status", MB_OK);
    break;
  case DISP_CHANGE_NOTUPDATED://Windows NT only: Unable to write
    Application->MessageBox("DISP_CHANGE_NOTUPDATED", "Status", MB_OK);
    break;
  }

// Let's show the current mode
hdc=GetDC(Application->Handle);
Caption ="Current: "+
    IntToStr(GetDeviceCaps(hdc, BITSPIXEL))+"x"+
    IntToStr(GetDeviceCaps(hdc, HORZRES))+"x"+
    IntToStr(GetDeviceCaps(hdc, VERTRES));
ReleaseDC(Application->Handle, hdc);


}
//--------------------------------------------------------------------------
-
#include <fstream.h>
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DEVMODE DevMode;
BOOL Status;
DWORD Mode;
HDC hdc;
DWORD bitsperpixel, x, y;
ofstream file("c:\\abc.txt");

// Let's prepare the string grid
StringGrid1->Cells[0][0]="Mode #";
StringGrid1->Cells[1][0]="Bits Per Pixel";
StringGrid1->Cells[2][0]="Width";
StringGrid1->Cells[3][0]="Heigth";

// Information about the current display mode
hdc=GetDC(Application->Handle);
bitsperpixel  = GetDeviceCaps(hdc, BITSPIXEL);
x             = GetDeviceCaps(hdc, HORZRES);
y             = GetDeviceCaps(hdc, VERTRES);
ReleaseDC(Application->Handle, hdc);

Caption ="Current Mode: "+
    IntToStr(bitsperpixel)+"x"+
    IntToStr(x)+"x"+
    IntToStr(y);

DevMode.dmSize=sizeof(DevMode);
Mode=0;
do {
  /* See Win32.hlp
  We set lpszDeviceName to NULL, because we want information about current
  display device on the computer that the calling thread is running on.
  We set iModeNum to zero so the operating system initializes and caches
  information about the display device.
  We increment iModeNum in a loop until the call to EnumDisplaySettings
fails,
  in order to retrieve all display device's graphics modes. */
  Status = EnumDisplaySettings(
      NULL,     // LPCTSTR lpszDeviceName -> specifies the display device
      Mode,     // DWORD iModeNum -> specifies the graphics mode
      &DevMode  // LPDEVMODE lpDevMode -> points to structure to receive
settings
      );
  if (Status) { // This mode is supported by the graphics card. Let's list
it.

    file<<Mode<<'\t'<<DevMode.dmBitsPerPel<<'\t'
        <<DevMode.dmPelsWidth<<'\t'<<DevMode.dmPelsHeight<<'\n';

    StringGrid1->RowCount=Mode+2;
    StringGrid1->Cells[0][Mode+1]=IntToStr(Mode);
    StringGrid1->Cells[1][Mode+1]=IntToStr(DevMode.dmBitsPerPel);
    StringGrid1->Cells[2][Mode+1]=IntToStr(DevMode.dmPelsWidth);
    StringGrid1->Cells[3][Mode+1]=IntToStr(DevMode.dmPelsHeight);
    // Select the corresponding row in the grid if this is the current mode
    if (x==DevMode.dmPelsWidth && y==DevMode.dmPelsHeight
            && bitsperpixel==DevMode.dmBitsPerPel) {
      StringGrid1->Row=Mode+1;
      currmode=Mode; // save current mode
      }
    Mode++;
    }
  } while (Status);


  file.close();
}
//--------------------------------------------------------------------------
-

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// This handler is called every 1000 ms == 1 second
// Note: Form2->ProgressBar1->Position is used as seconds counter

if (Form2->ProgressBar1->Position==TIMEOUT) {
// if we get here, either the user is to lazy to press a button or
// he is unable to see the confirmation window. Anyway let's undo changes
// by forcing Form2 to close. Note that Form2 was shown by calling
ShowModal().
// If we force it to close its Modalresult won't be mrOk !
  Timer1->Enabled=false;
  Form2->Close();
  }
else {
// the clock is ticking ...
  Form2->ProgressBar1->Position++;
  Form2->Label1->Caption = "Previous settings will be restored in " +
      IntToStr(TIMEOUT - Form2->ProgressBar1->Position) + " seconds";
  }

}
//--------------------------------------------------------------------------
-




//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
int TIMEOUT = 15;
//--------------------------------------------------------------------------
-
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}
//--------------------------------------------------------------------------
-

void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
ProgressBar1->Position=0;

}
//--------------------------------------------------------------------------
-

void __fastcall TForm2::FormCreate(TObject *Sender)
{
ProgressBar1->Max=TIMEOUT;

}
//--------------------------------------------------------------------------
-
Technical Details
Message-ID: <3f2f31c6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f2ec2ee$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,bef4d47642e60a13
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-04 21:31:46 PST
From: "Dumboo" <dumboo@nowhere.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f2ec2ee$1@newsgroups.borland.com>
Subject: Re: Change resolution
Date: Tue, 5 Aug 2003 10:09:30 +0530
Lines: 249
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 203.115.90.244
Message-ID: <3f2f31c6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1060057542 203.115.90.244 (4 Aug 2003 21:25:42 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail