Niestety, pod tym Delphi, przy którym siedzę (2007 :-( ), niezbyt dobrze to działa. Przy pierwszy tworzeniu formy pokazywana jest ona w lewym, górnym rogu ekranu. Pewnie poza wymuszeniem pokazania trzeba by jeszcze wymusić pozycjonowanie. Ja zaś myślałem o czymś takim:
ShowMessage.dpr:
program ShowMessage;
uses
Forms,
uMain in 'uMain.pas' {fMain},
uSecond in 'uSecond.pas' {fSecond};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TfMain, fMain);
Application.Run;
end.
uMain.dfm:
object fMain: TfMain
Left = 0
Top = 0
Caption = 'Forma g'#322#243'wna'
ClientHeight = 43
ClientWidth = 211
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object btnShowNormal: TButton
Left = 16
Top = 8
Width = 75
Height = 25
Caption = 'Show Normal'
TabOrder = 0
OnClick = btnShowNormalClick
end
object btnShowModal: TButton
Left = 120
Top = 8
Width = 75
Height = 25
Caption = 'Show Modal'
TabOrder = 1
OnClick = btnShowModalClick
end
end
uMain.pas:
unit uMain;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TfMain = class(TForm)
btnShowNormal: TButton;
btnShowModal: TButton;
procedure FormDestroy(Sender: TObject);
procedure btnShowNormalClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnShowModalClick(Sender: TObject);
private
FSecondForm: TForm;
end;
var fMain: TfMain;
implementation
uses uSecond;
{$R *.dfm}
procedure TfMain.btnShowModalClick(Sender: TObject);
begin
FSecondForm.ShowModal;
end;
procedure TfMain.btnShowNormalClick(Sender: TObject);
begin
FSecondForm.Show;
end;
procedure TfMain.FormCreate(Sender: TObject);
begin
FSecondForm := TfSecond.Create(self);
end;
procedure TfMain.FormDestroy(Sender: TObject);
begin
FSecondForm.Free;
end;
end.
uSecond.dfm:
object fSecond: TfSecond
Left = 0
Top = 0
Caption = 'fSecond'
ClientHeight = 191
ClientWidth = 408
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
end
uSecond.pas:
unit uSecond;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
const WM_MYMESS = WM_USER + 1;
type
TfSecond = class(TForm)
procedure FormShow(Sender: TObject);
private
procedure WMMYMESS(var Message: TMessage); message WM_MYMESS;
end;
implementation
{$R *.dfm}
procedure TfSecond.FormShow(Sender: TObject);
begin
ShowMessage('Przed pokazaniem');
PostMessage(Handle, WM_MYMESS, 0, 0);
end;
procedure TfSecond.WMMYMESS(var Message: TMessage);
begin
ShowMessage('Po pokazaniu');
end;
end.