以下是对第一个问题的回嘴。
program Project1;
uses
Forms,
windows,
Messages,
Unit1 in 'Unit1.pas' {Laihua};
const
CM_RESTORE = WM_USER + $1000;
Var
RvHandle : hWnd;
{$R *.RES}
begin
RvHandle := FindWindow('这是一个测试程序!', NIL);
if RvHandle > 0 then
begin
PostMessage(RvHandle, CM_RESTORE, 0, 0);
Exit;
end;
Application.Initialize;
Application.CreateForm(TLaihua, Laihua);
Application.Run;
end.
================================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
CM_RESTORE = WM_USER + $1000;
//自定义窗口消息
type
TLaihua = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams);
override;
Procedure RestoreRequest(var message: TMessage);
message CM_RESTORE;
end;
var
Laihua: TLaihua;
implementation
{$R *.DFM}
procedure TLaihua.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
//继承缺省的窗口创建过程
Params.WinClassName := '这是一个测试程序!';
//设置窗口类名称
end;
procedure TLaihua.RestoreRequest(var message: TMessage);
begin
if IsIconic(Application.Handle) = TRUE then
//如果程序是最小化为任务条上的图标时,将窗口恢复
Application.Restore
else
Application.BringToFront;
//否则将它被其它窗口遮住的程序主窗口带到前面来
end;
end.
=============================================================
2
你可以设置在按下停止后生成一个Flag ,然后的计算中判断它的状态,然后退出。