在最小化应用程序时隐藏表单 [英] Hide form when application is minimized
问题描述
我有一个主表单和一个状态表单,当我在应用程序中进行工作时会显示它们。如果工作完成,我只需在状态表单上调用 Hide
,状态表单就会消失。
我的问题发生了当我最小化主窗体而等待窗体可见时。然后这两种形式都被隐藏了,这就是我想要的。但是,如果在最小化主窗体的同时完成工作,那么当我还原它时,状态窗体也将还原,即使在最小化时调用了 Hide
。 / p>
可见
对于状态表来说,似乎为 False
应用程序已最小化,因此调用 Hide
似乎没有任何效果(帮助说它只是将 Visible
设置为 False
)。
观察是否正确?当应用程序再次获得焦点时,如何恢复表单的可见性?
可见 c显示形式的>确实是错误的,并且在最小化应用程序时调用
Hide
不会执行任何操作,因为作为最小化机制的一部分,应用程序会将其隐藏。
代码调用 ShowOwnedPopups
,在应用程序最小化时,第一个 False为 bShow,然后在恢复应用程序时,将 True作为 bShow 。由于该函数显示了上一个调用隐藏的所有窗口,因此更改
窗体之间的可见性无效。
现在,请参阅函数文档的备注部分,
如果使用ShowWindow函数使用
隐藏了弹出窗口,随后
将fShow
参数设置为TRUE调用ShowOwnedPopups不会导致
窗口显示
因此,一种解决方案是在应用程序将其隐藏之前将其隐藏,这样还原时就不会显示它。但是,我们必须知道还原时实际上是要隐藏还是显示该显示表单。这可以通过在显示表单上放置属性或使用全局变量来实现。在下面, ShouldBeVisible是一个假设属性,如果我们要显示信息,它将返回true:
type
TForm1 = class(TForm)
..
private
过程WMSysCommand(var Msg:TWMSysCommand);消息WM_SYSCOMMAND;
...
过程TForm1.WMSysCommand(var Msg:TWMSysCommand);如果(Msg.CmdType = SC_MINIMIZE)和Assigned(Form2)和Form2.Visible,则
开始
,然后
Form2.Hide;
继承了;
if(Msg.CmdType = SC_RESTORE)和Assigned(Form2)和Form2.ShouldBeVisible则
Form2.Show;
结尾;
I have a main form and a status form that I display when work is going on in my application. If the work is finished I just call Hide
on the status form and the status form disappears.
My problem occurs when I minimize the main form whilst the wait form is visible. Then both forms are hidden which is what I want. However, if the work finishes whilst the main form is minimized then when I restore it, the status form is also restored, even though Hide
has been called on it whilst minimized.
Visible
seems to be False
for the status form when the application is minimized and therefore calling Hide
seems to have no effect (the help says it just sets Visible
to False
).
Are that observations correct? How is the form visibility restored when the application gets focus again? How can I hide my form while the application is minimized?
Visible
of the display form is indeed false and calling Hide
does nothing when the application is minimized, because it is hidden by the application as part of the minimization mechanism.
Code calls ShowOwnedPopups
with first 'False' as 'bShow' while the application is minimizing, and then with 'True' as 'bShow' while the application is restoring. Since the function shows all windows which was hidden by a previous call, changing visibility of a form
in between has no effect.
Now, see this quote from the remarks section of the documentation of the function,
if a pop-up window is hidden by using the ShowWindow function, subsequently calling ShowOwnedPopups with the fShow parameter set to TRUE does not cause the window to be shown
So, one solution can be to hide the form before the application hides it, so it won't get shown while restoring. But then we have to know if the display form is actually to be hidden or shown when we restore. This can be achieved by putting a property on the display form or with a global variable perhaps. In the below, 'ShouldBeVisible' is a hypothetical property that would return true if we are to display information:
type
TForm1 = class(TForm)
..
private
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
...
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if (Msg.CmdType = SC_MINIMIZE) and Assigned(Form2) and Form2.Visible then
Form2.Hide;
inherited;
if (Msg.CmdType = SC_RESTORE) and Assigned(Form2) and Form2.ShouldBeVisible then
Form2.Show;
end;
这篇关于在最小化应用程序时隐藏表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!