Here's a sample to my problem...
Start a new project add 3 forms
1- unit=FMenu (name=frmMenu)
2- unit=Form1 (name=frmForm1)
3- unit=Form2 (name=frmForm2)
paste following code to each file.
---------------------------------------------------------
unit FMenu;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Form1;
type
TfrmMenu = class(TForm)
Label1: TLabel;
btnModal: TButton;
btnNonModal: TButton;
procedure btnModalClick(Sender: TObject);
procedure btnNonModalClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMenu: TfrmMenu;
implementation
{$R *.dfm}
procedure TfrmMenu.btnModalClick(Sender: TObject);
begin
if frmForm1.Visible then frmForm1.Close;
frmForm1.ShowModal;
end;
procedure TfrmMenu.btnNonModalClick(Sender: TObject);
begin
if frmForm1.Visible then frmForm1.Close;
frmForm1.Show;
end;
end.
-----------------------------------------------------------
unit Form1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TfrmForm1 = class(TForm)
Label1: TLabel;
btnform2: TButton;
ListBox1: TListBox;
procedure btnform2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmForm1: TfrmForm1;
implementation
{$R *.dfm}
uses Form2;
procedure TfrmForm1.FormShow(Sender: TObject);
begin
if (fsModal in FormState) then
Label1.Caption := Self.Caption + ' is modal.'
else
Label1.Caption := Self.Caption + ' is non-modal.';
ListBox1.ItemIndex := 0;
end;
procedure TfrmForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if frmForm2.Visible then frmForm2.Close;
end;
procedure TfrmForm1.btnform2Click(Sender: TObject);
begin
frmForm2.Show;
frmForm2.ShowSelection(ListBox1.Items[ListBox1.ItemIndex], (fsModal in FormState));
end;
procedure TfrmForm1.ListBox1Click(Sender: TObject);
begin
if frmForm2.Visible then
btnForm2.Click;
end;
end.
-----------------------------------------------------------
unit Form2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmForm2 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ShowSelection(sItem: String; bModal: Boolean);
end;
var
frmForm2: TfrmForm2;
implementation
{$R *.dfm}
uses Form1;
procedure TfrmForm2.FormShow(Sender: TObject);
begin
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE OR SWP_NOACTIVATE);
Top := frmForm1.Top;
Left := frmForm1.Left + (frmForm1.Width-Width);
end;
procedure TfrmForm2.ShowSelection(sItem: String; bModal: Boolean);
begin
Edit1.Text := sItem;
if bModal then
begin
Label3.Font.Color := clRed;
Label3.Caption := 'ONTOP OF ALL APPS.'+#13+'If you switch to another app,'+#13+'Form2 will still on top.';
end
else
begin
Label3.Font.Color := clGreen;
Label3.Caption := 'ONTOP OF MY APP ONLY.'+#13+'If you switch to another app,'+#13+'Form2 will still with my app.';
end;
end;
end.
-----------------------------------------------------------