应该抛弃Delphi的TApplication,直接创建任务栏窗体
1.主窗体覆盖CreateParams方法,实现任务栏图标及隐藏Application对象在任务栏上的按钮
2.子窗体覆盖CreateParams,把父设置为主窗体
3.修改Dialogs单元源码,把所有
hWndOwner := Application.Handle;
替换成
if Owner is TWinControl then
hWndOwner := TWinControl(Owner).Handle
else
hWndOwner := Application.Handle;
1,2解决窗体的顺序问题,3解决对话框的问题
参考:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1929737
贴一个基类吧,主窗体及子窗体都从这个类继承,子窗体Create要用类似这样的方法
FormChild := TFormChild.Create(FormMain);//主窗体为父,而不是Application对象
//==============================================================================
// Unit Name: BaseFrm
// Author : ysai
// Date : 2003-11-28
// Purpose :
// History :
//==============================================================================
unit BaseFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TFrmBase = class(TForm)
private
procedure WMSysCommand(var Message:TWMSysCommand);message WM_SYSCOMMAND;
protected
procedure CreateParams(var Params:TCreateParams); override;
public
constructor Create(AOwner: TComponent);reintroduce;override;
end;
implementation
{$R *.dfm}
constructor TFrmBase.Create(AOwner: TComponent);
begin
//让Application对象不出现在任务栏
with Application do
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
inherited;
end;
procedure TFrmBase.CreateParams(var Params: TCreateParams);
begin
inherited;
if Owner is TForm then
Params.WndParent := TForm(Owner).Handle //子窗体
else
Params.ExStyle := Params.ExStyle + WS_EX_APPWINDOW; //主窗体
end;
procedure TFrmBase.WMSysCommand(var Message: TWMSysCommand);
begin
case Message.CmdType of
SC_MINIMIZE :
DefWindowProc(Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
SC_RESTORE:
DefWindowProc(Handle,WM_SYSCOMMAND,SC_RESTORE,0);
else
inherited;
end;
end;
end.