首先你先确定你的句柄是应用程序的还是主窗体的,这点很关键(我只试验了Delphi中的)<br><br>如果你的B程序的Handle是通过FindWindow得到的,请确定你查找的窗体<br>FindWindow(nil,B.Application.Title) 而不是 FindWindow(nil,B.MainForm.Caption)<br><br>在我这里试验,如果你的句柄真的是B.Application的话,是不会有问题的<br>你可以用以下语句试验一下<br>(生成一个空程序,Application.Title='TestState'; //B.Application.Caption<br> MainFrom.Caption='FormState' //B.MainForm.Caption<br>运行她)<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button2: TButton;<br> Button3: TButton;<br> Edit1: TEdit;<br> Edit2: TEdit;<br> Button1: TButton;<br> Button4: TButton;<br> Button5: TButton;<br> procedure Button2Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button4Click(Sender: TObject);<br> procedure Button5Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> aHwnd:Hwnd;<br>begin<br> aHwnd:=Edit1.Tag;<br> if not IsWindow(aHwnd) then exit;<br> SendMessage(aHwnd,WM_SYSCOMMAND,SC_RESTORE,0);<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> aHwnd:Hwnd;<br>begin<br> aHwnd:=Edit1.Tag;<br> if not IsWindow(aHwnd) then exit;<br> ShowWindow(aHwnd,SW_RESTORE);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> aHwnd,bHwnd:HWND;<br>begin<br> aHwnd:=FindWindow(nil,'TestState'); //B.Application.Caption<br> bHwnd:=FindWindow(nil,'FormState'); //B.MainForm.Caption<br> Edit1.Tag:=aHwnd;<br> Edit1.Text:='$'+IntToHex(aHwnd,8);<br> Edit2.Tag:=bHwnd;<br> Edit2.Text:='$'+IntToHex(bHwnd,8);<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>var<br> aHwnd:Hwnd;<br>begin<br> aHwnd:=Edit2.Tag;<br> if not IsWindow(aHwnd) then exit;<br> SendMessage(aHwnd,WM_SYSCOMMAND,SC_RESTORE,0);<br>end;<br><br>procedure TForm1.Button5Click(Sender: TObject);<br>var<br> aHwnd:Hwnd;<br>begin<br> aHwnd:=Edit2.Tag;<br> if not IsWindow(aHwnd) then exit;<br> ShowWindow(aHwnd,SW_RESTORE);<br>end;<br><br>end.