如何在Delphi中没有MainForm? [英] How to not have a MainForm in Delphi?
问题描述
我一直在尝试在我的应用程序中获得一些无模式的表单,以显示在任务栏上 - 利用Windows 7中的新的有用任务栏。
i've been trying to get some modeless forms in my application to appear on the taskbar - taking advantage of the new useful taskbar in Windows 7.
在任务栏上可能存在一个表单之前需要撤销的VCL的许多问题。
There's are many issues with the VCL that need to be undone before a form can exist on the taskbar.
但是最后一个问题是最小化VCL已经指定的主窗体导致应用程序中的所有窗口消失。
But the final issue is that minimizing the form that the VCL has designated the main form causes all windows in the application to vanish.
十年前,Peter Below(TeamB)记录了这些问题并试图解决这些问题。但有一些问题是无法解决的。这些问题在VCL本身中运行得如此之深,Delphi应用程序的行为是非常有效的。
Ten years ago, Peter Below (TeamB) documented these problems, and attempts to work around them. But there are some issues that cannot be solved. The issues run so deep within the VCL itself, that it's effectively impossible to make Delphi applications behave properly.
这一切都来自于您看到的按钮在工具栏上不代表应用程序的窗口;它代表 TApplications
窗口,这是隐藏的,从未见过的。然后有应用程序的 MainForm
,然后充满特殊功能,如果它被最小化,则指示应用程序隐藏自身。 / em>
It all stems from the fact that the button you see on the toolbar does not represent the application's window; it represents the TApplications
window, which is hidden and never seen. And then there is the application's MainForm
, which is then imbued with special abilities where if it is minimized then it instructs the application to hide itself.
在我看来,如果我可以做
It seems to me that if i can do
Application.MainForm := nil;
然后所有这些错误都会消失。应用程序可以有其隐藏的窗口,同时我将覆盖应用程序中的每个 其他 表单,包括我的主窗体, :
then all these bugs would go away. The application can have its hidden window, and in the meantime i'll override every other form in the application, including my main form, with:
procedure TForm2.CreateParams(var params: TCreateParams );
begin
inherited CreateParams(params);
params.ExStyle := params.ExStyle or WS_EX_APPWINDOW;
end;
但是在Delphi中, Application.MainForm
属性是只读的。
But in Delphi the Application.MainForm
property is read-only.
如何在Delphi中没有一个 MainForm
How can i not have a MainForm
in Delphi?
- (stackoverflow) Delphi: What is Application.Handle?
- (newsgroup) Hiding Main Window but not child
推荐答案
如果没有分配MainForm,则无法运行GUI项目。主消息循环将立即退出,没有一个。但是,这并不意味着MainForm必须运行您的UI。您可以使用空白的隐藏的TForm作为分配的MainForm,然后将其实例化为您的真实MainForm作为辅助TForm。例如:
You cannot run a GUI project without a MainForm assigned. The main message loop will exit immediately without one. However, that does not mean that the MainForm has to run your UI. You can use a blank hidden TForm as the assigned MainForm, and then have it instantiate your real MainForm as a secondary TForm. For example:
HiddenMainFormApp.dpr:
HiddenMainFormApp.dpr:
project HiddenMainFormApp;
uses
..., Forms, HiddenMainForm;
begin
Application.Initialize;
Application.CreateForm(THiddenMainForm, MainForm);
Application.ShowMainForm := False;
Application.Run;
end.
HiddenMainForm.cpp:
HiddenMainForm.cpp:
uses
..., RealMainForm;
procedure THiddenMainForm.FormCreate(Sender: TObject);
begin
RealMainForm := TRealMainForm.Create(Self);
RealMainForm.Show;
end;
RealMainForm.cpp:
RealMainForm.cpp:
procedure TRealMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Application.Terminate;
end;
或者:
HiddenMainFormApp.dpr:
HiddenMainFormApp.dpr:
project HiddenMainFormApp;
uses
..., Forms, HiddenMainForm, RealMainForm;
begin
Application.Initialize;
Application.CreateForm(THiddenMainForm, MainForm);
Application.ShowMainForm := False;
RealMainForm := TRealMainForm.Create(Application);
RealMainForm.Show;
RealMainForm.Update;
Application.Run;
end.
RealMainForm.cpp:
RealMainForm.cpp:
procedure TRealMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Application.Terminate;
end;
这篇关于如何在Delphi中没有MainForm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!