如何强制把某个程序最小化(包括它开的所有窗口)(100分)

G

gdxkz

Unregistered / Unconfirmed
GUEST, unregistred user!
ShowWindow针对的是单独的窗口,有没有对应用程序的API或其他的方法。
 
application.Mxxxxxxx(具体的我记不清了

你在IDE里面找一下吧
 
Application.Minimize;
 
Winexec(*.Exe, SW_MINIMIZE);
 
下例我们将 Windows 自带的 “计算器” 程序最小化(先要启动'计算器'):
procedure TForm1.Button1Click(Sender: TObject);
var
H:HWND;
begin
H:=FindWindow(nil, '计算器');
if H > 0 then
SendMessage(H,$0112,$F020,0);
end;
或者是 Microsoft Word (测试时,也请先打开 Word 程序):
procedure TForm1.Button2Click(Sender: TObject);
var
H:HWND;
begin
H:=FindWindow(nil, '文档 1 - Microsoft Word');
if H > 0 then
SendMessage(H,$0112,$F020,0);
end;
 
Re:abc_xp,Derlin
用Application是最小化自己,我是想把其他程序最小化
Re:小雨哥
你的方法是最小化某个窗口,如果我要最小化的程序有很多个窗口就不行了。

我目前只能采用运行Window带的那个Show Desktop来小化,不过所有的都小化了。
 
Re:gdxkz:
你是如何调用windows带的那个show desketop来最小化的?请赐教。
 
那是Window 的快捷方式,98和2000的路径都不一样,在Quick Launch里
 
对主窗口发送最小化消息!
 
这不一样吗?既然程序可以编,在你将主窗口最小化时,不能引发一个事件或消息,在这个
消息或事件代码里枚举所有正在显示的子窗口,一一最小化就行了.再说了,如果你窗口
层次安排正确的话,最小化主窗口后,所有子窗口应该也自动最小化的呀.
 
模态窗口是无法直接最小化的。
 
// 模态窗口是无法直接最小化的
不会吧,只是不能到任务条。看下面演示:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unit Unit1; // MainForm
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
uses Unit3;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin // 显示模式 Form3
Form3.ShowModal;
end;
end.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unit Unit2; // 这个窗体需要动态建立
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
end;
var
Form2: TForm2;
implementation
uses Unit3;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin // 最小化模式 Form3
SendMessage(Form3.Handle,$0112,$F020,0);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
FormStyle:= fsStayOnTop;
end;
procedure TForm2.FormShow(Sender: TObject);
begin
Width := 210;
Height:=160;
end;
end.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unit Unit3; // 被模式显示的窗体
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm3 = class(TForm)
procedure FormShow(Sender: TObject);
end;
var
Form3: TForm3;
implementation
uses unit2;
{$R *.DFM}
procedure TForm3.FormShow(Sender: TObject);
begin
Form2:=TForm2.Create(Self);
form2.Show;
end;
end.
 
这里讲一个使用 Windows 自己的系统特性最小化全部窗口的简单方法:
打开 Delphi ,在菜单 project 下导入类型库,点添加,导入 shell32.dll
注意这个测试我是在我的 Windows 2000 下进行的,如果你是 Win98 之类,我没有测试过。
然后新建一个工程项目,把刚刚导入的 Shell32.dll 的一个控件“Shell”放到 Form 上,
再在 Form 上放一个 Button ,在它的 OnClick 事件中加如下代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
Shell1.MinimizeAll;
end;
点这个按钮,当前打开的所有窗口将全部最小化。
[ 再次强调:我这是在 Windows 2000 + Delphi 5 下测试成功的,由于 Shell32.dll 的版本
缘故,其他的配置状况我没有测试。相同配置方案如果有问题,我可以负责解答,不同方案
我就无法解答了。]
 
我引入后,不能编译,提示不能对只读属性更改。(Shell32版本1。0 XP系统)
我想做一个外部程序,能对其他程序做小化控制,因此并不知道其他程序的窗口打开规律,一般只要对它的主程序最下化就可以同时小化它的子窗口。
 
在D6的ActiveX里有一个VSSpell,是由shell32.dll产生,但没有MinimizeAll这个方法
 
我还是测试了 98 的情况,2000 编好的东西到 98 下一样有效。在 XP 中更简单了,直接
就有 “最小化全部窗口” 的方法,你可以在导入的类型库里找找,应该有:
IShellDispatch4.ToggleDesktop()
MSDN 如此说:
The IShellDispatch4 object extends the IShellDispatch4 object.
In addition to the properties and methods supported by IShellDispatch4,
IShellDispatch4 supports four additional methods.
四个中的其中一个就是:ToggleDesktop Method 。
ToggleDesktop Method:
Raises and lowers the desktop.
Minimum DLL Version shell32.dll version 5.0 or later
Minimum operating systems Windows XP
The ToggleDesktop method does not display any user interface.
我没有在 XP 下装任何工作软件,所以也没有办法做这个测试,你可以试试。
 
我找了一下,引入的类库表中并没有IShellDispatch,MSDN上也没讲是包含在哪个DLL中,无法引入。
我估计此方法应该也适用于98,因为98和XP都有一个快捷,点了能小化所有的窗口,而且它们的快捷里的命令都是ToggleDesktop.
 
这个方法就在 Shell32.dll 中,怎么会没有?
Windows 2000 下到 IID_IShellDispatch2 ,
Windows XP 如下:
IID_IShellDispatch: TGUID = '{D8F015C0-C278-11CE-A49E-444553540000}';
IID_IShellDispatch2: TGUID = '{A4C6892C-3BA9-11D2-9DEA-00C04FB16162}';
IID_IShellDispatch3: TGUID = '{177160CA-BB5A-411C-841D-BD38FACDEAA0}';
IID_IShellDispatch4: TGUID = '{EFD84B2D-4BCF-4298-BE25-EB542A59FBDA}';
xxxxxxxxxxxxxx
IShellDispatch = interface;
IShellDispatchDisp = dispinterface;
IShellDispatch2 = interface;
IShellDispatch2Disp = dispinterface;
IShellDispatch3 = interface;
IShellDispatch3Disp = dispinterface;
IShellDispatch4 = interface;
IShellDispatch4Disp = dispinterface;
xxxxxxxxxxxxxxx
Shell = IShellDispatch;
xxxxxxxxxxxxxxx
IShellDispatch4 = interface(IShellDispatch3)
['{EFD84B2D-4BCF-4298-BE25-EB542A59FBDA}']
procedure WindowsSecurity; safecall;
procedure ToggleDesktop; safecall; // <----------- 它是什么啊?????
function ExplorerPolicy(const bstrPolicyName: WideString): OleVariant; safecall;
function GetSetting(lSetting: Integer): WordBool; safecall;
end;
xxxxxxxxxxxxxxxxxxx
看清了吗?没有吗?我已经告诉你了,你管它 MSDN 上说什么,再说 MSDN 每季都在更新。
 
接受答案了.
 
顶部