RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TOpenDialog.GetStaticRect Method

Returns the coordinates of the reserved area of the dialog box.

Pascal
function GetStaticRect: TRect; virtual;
C++
virtual __fastcall TRect GetStaticRect();

GetStaticRect is provided for components that descend from TOpenDialog and require the placement of new controls alongside the standard ones inherited from the parent class. For Explorer-style dialogs, GetStaticRect returns the size and location of the standard controls within the dialog. For older versions of Windows, or if ofOldStyleDialog is enabled in Options, GetStaticRect returns the client dimensions of the entire dialog box.  

C++ Examples: 

 

/*
The following example is taken from TOpenPictureDialog. It
calculates the preview rectangle based on the difference
between the client area of the dialog and the static area of
the standard controls.
*/

#include <ExtDlgs.hpp>

class MyOpenPictureDialog : public TOpenPictureDialog
{
private:    // User declarations
    TPanel *FPicturePanel;  // can't use the private versions in TOpenPictureDialog
    TLabel *FPictureLabel;
    TSpeedButton *FPreviewButton;
    TPanel *FPaintPanel;
    TImage *FImageCtrl;
    AnsiString FSavedFilename;
protected:  // User declarations
    DYNAMIC void __fastcall DoShow(void);
public:     // User declarations
    __fastcall MyOpenPictureDialog(TComponent* Owner);
    virtual bool __fastcall  Execute(HWND ParentWnd){ return TOpenDialog::Execute(ParentWnd); }
};

__fastcall MyOpenPictureDialog::MyOpenPictureDialog(TComponent* Owner)
    : TOpenPictureDialog(Owner)
{
}

void __fastcall MyOpenPictureDialog::DoShow(void)
{
  RECT *PreviewRect = new RECT();
  TRect StaticRect;
  FPicturePanel = new TPanel(this);
  FPictureLabel = new TLabel(this);
  FPreviewButton = new TSpeedButton(this);
  FPaintPanel = new TPanel(this);
  FImageCtrl = new TImage(this);
  // Set preview area to entire dialog
  GetClientRect(Handle, PreviewRect);
  StaticRect = GetStaticRect();
  // Move preview area to right of static area
  PreviewRect->left = StaticRect.Left + (StaticRect.Right - StaticRect.Left);
  PreviewRect->top += 4;
  FPicturePanel->BoundsRect.Left = PreviewRect->left;
  FPicturePanel->BoundsRect.Right = PreviewRect->right;
  FPicturePanel->BoundsRect.Top = PreviewRect->top;
  FPicturePanel->BoundsRect.Bottom = PreviewRect->bottom;

  FPreviewButton->Left = FPaintPanel->BoundsRect.Right - FPreviewButton->Width - 2;
  FImageCtrl->Picture = NULL;
  FSavedFilename = "";
  FPaintPanel->Caption = "";
  FPicturePanel->ParentWindow = Handle;
  delete PreviewRect;
  delete FPicturePanel;
  delete FPreviewButton;
  delete FPaintPanel;
  delete FImageCtrl;
//  TOpenDialog::DoShow();   // the above code is equivalent to the inherited version
}

TForm1 *Form1;
MyOpenPictureDialog *OpenPictureDialog1;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (OpenPictureDialog1->Execute(GetParentHandle()))
      Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  OpenPictureDialog1 =  new MyOpenPictureDialog(Form1);
}

 

Delphi Examples: 

{
The following example is overrides the
TOpenPictureDialog.DoShow method and implements it here.
DoShow calculates the preview rectangle based on the
difference between the client area of the dialog and the
static area of the standard controls.
}
type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  MyOpenPictureDialog = class(TOpenPictureDialog)
  private
    FPicturePanel: TPanel; // can't use the private versions in TOpenPictureDialog
    FPictureLabel: TLabel;
    FPreviewButton: TSpeedButton;
    FPaintPanel: TPanel;
    FImageCtrl: TImage;
    FSavedFilename: string;
  public
    { Public declarations }
  protected
    procedure DoShow; override;
  end;
var
  Form1: TForm1;
  OpenPictureDialog1: MyOpenPictureDialog;

implementation

{$R *.dfm}

procedure MyOpenPictureDialog.DoShow;
var
  PreviewRect, StaticRect: TRect;
begin
  FPicturePanel:= TPanel.Create(Self);
  FPictureLabel:= TLabel.Create(Self);
  FPreviewButton:= TSpeedButton.Create(Self);
  FPaintPanel:= TPanel.Create(Self);
  FImageCtrl:= TImage.Create(Self);
  // Set preview area to entire dialog
  GetClientRect(Handle, PreviewRect);
  StaticRect := GetStaticRect;
  // Move preview area to right of static area
  PreviewRect.Left := StaticRect.Left + (StaticRect.Right - StaticRect.Left);
  Inc(PreviewRect.Top, 4);
  FPicturePanel.BoundsRect := PreviewRect;
  FPreviewButton.Left := FPaintPanel.BoundsRect.Right - FPreviewButton.Width - 2;
  FImageCtrl.Picture := nil;
  FSavedFilename := '';
  FPaintPanel.Caption := '';
  FPicturePanel.ParentWindow := Handle;
//  TCommonDialog.DoShow;  // this is the one TOpenPictureDialog.DoShow calls
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute then
      Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  OpenPictureDialog1:= MyOpenPictureDialog.Create(Form1);
//  OpenPictureDialog1.Parent:= Form1;
//  OpenPictureDialog1.visible := false;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!