◆◆一个非常简单的程序例子,请各位大哥看看,为什么隐藏主窗口时,任务栏上的按钮不消失呢?◆◆(50分)

  • 主题发起人 主题发起人 小笨苯
  • 开始时间 开始时间

小笨苯

Unregistered / Unconfirmed
GUEST, unregistred user!
这是非常简单的一个程序例子,具体如下:新建一个工程,在Form1上放上一个按钮Button1,再新建一个
Form2,使Form2不能自动生成,完了,就这么简单,代码如下:
----------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
Form2 := TForm2.Create(self);
Form2.Show;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Hide;
end;

end.
----------------------------------------
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams); override;
end;

var
Form2: TForm2;

implementation

{$R *.DFM}

{ TForm2 }

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST or WS_EX_TOOLWINDOW or WS_EX_ACCEPTFILES;
Params.WndParent := GetDesktopWindow;
end;

end.
----------------------------------------
在主窗口Form1启动的时候,也将Form2动态建立,并显示出来。我的问题是:现在按下Form1
中的按钮Button1,将主窗口Form1隐藏,但在Windows的任务栏上还能显示这个程序的按钮,
请问如何隐藏按钮?在Form1再次显示的时候,任务栏上再显示按钮。
 
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
 
fanren945:
大哥,你没明白我的意思,我是想在Form1显示的时候,可以在任务栏中显示程序按钮;当
Form1隐藏时,任务栏中的按钮消失。
 
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);

灵活运用这个函数

if form1隐藏 then
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW)
else
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW); //是不是这么用我忘记了,最好自己查查帮助

我好长时间没用delphi了,主要给你提供思路,另一个函数有很多用法不要死用啊
这个函数可以让程序在任务栏消失肯定也可以让他出现阿
 
谢谢fanren945大哥,不过,我觉得这不是好办法,再看看别人的意见吧
 
Form1.Visible=
在就是fanren945的方法最好了!
 
angelfaceH:
我不太同意你的说法,但也要感谢你,也感谢fanren945大哥,但他的方法绝对不是好方法。
 
showwindow(application.Handle, sw_hide);
 
同意fanren945的看法
来晚了
 
fanren945大哥的方法 + mdc大哥的方法 = 可以实现我的要求
但还想听听有没有更好的方法,如果到今天下午6点钟还没有,就把分给他们啦[:D]
 
刚才试了一下(现装的delphi7)setwindowlong(application.handle,GWL_EXSTYLE,WS_EX_APPWINDOW)不对
应该是setwindowlong(form1.handle,gwl_exstyle,ws_ex_appwindow)

另外
>>Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST or WS_EX_TOOLWINDOW or WS_EX_ACCEPTFILES;
这句代码好像不必要

呵呵搜了一下以前的贴子,看看吧,还有这么多方法呢
==============================================================================================
如何实现当主窗口Show一个窗口时,在Windows的任务栏中显示此窗口,这样可以在主窗口和本窗口的切换。

来自:taozhiyu, 时间:2002-2-23 8:59:00, ID:936502
搜索论坛,讨论过了!


来自:GipsyCN, 时间:2002-2-23 10:22:00, ID:936619
protected
procedure CreateParams(var Params: TCreateParams); override;
....
procedure TfmMatchRec.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.wndParent := GetDesktopWindow;
end;



来自:pioneer_wk, 时间:2002-2-23 10:25:00, ID:936623
学习学习。


来自:jdelphi, 时间:2002-2-23 10:40:00, ID:936654
学习GipsyCN的方法,正确.
主窗体form1调用form2,form2在任务栏显示程序图标:
在form2中添加
protected
procedure CreateParams(var Params: TCreateParams); override;

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.wndParent := GetDesktopWindow;
end;


来自:yt_wyb, 时间:2002-2-23 10:58:00, ID:936688
SetWindowLong(Handle, GWL_EXSTYLE,WS_EX_APPWINDOW);



来自:landina, 时间:2002-2-23 12:30:00, ID:936897
to:yt_wyb
SetWindowLong(Handle, GWL_EXSTYLE,WS_EX_APPWINDOW);
可以实现要求,但有个问题不知阁下是否遇见过,当我Show Form2后,我想在Windows任务栏中切换
可怎么也不行,只能最小化Form2或单击Form1窗口才能切换过来。


来自:yzhshi, 时间:2002-2-23 12:34:00, ID:936906
下面这个也可以。
procedure CreateParams(var Params:TCreateParams);override;

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle:=WS_EX_APPWINDOW;
end;



来自:chemer, 时间:2002-3-7 21:37:00, ID:968178
minimize non-main forms to the taskbar

From: David Watt <bm01393@themis.ag.gov.bc.ca>

I posted a message a few weeks ago asking about how to minimize non-main forms
to the taskbar, or more precisely, how to minimize applications to the taskbar
from forms other than the main form. (I find the fact that secondary forms
minimize to the desktop really unappealing.) I received a number of replies
(and thanks for those) but no one had an answer. After a little surfing and
some trial-and-error I've come up with a solution.

In order to have secondary forms minimize the application to the taskbar all
you need are the following two steps.

1. Declare a private message handling procedure within the secondary form which
will intercept messages destine for the form.


--------------------------------------------------------------------------------

private
{ Private declarations }
procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;


--------------------------------------------------------------------------------

2. Create a procedure in the secondary form's implementation section which
intercepts messages and puts in place a substitution for SC_MINIMIXE messages
so that the Application.Minimize procedure is executed instead. All other
messages pass through normally; they are inherited.


--------------------------------------------------------------------------------

procedure TForm2.WMSysCommand(var Message: TMessage);
begin
if (Message.WParam = SC_MINIMIZE) then
Application.Minimize
else
inherited;
end;


--------------------------------------------------------------------------------

That's does the trick.

特别适合MDI
 
多人接受答案了。
 

Similar threads

后退
顶部