unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1             : TForm1;

implementation

{$R *.dfm}

const
  WM_MiniSQLMsg     = WM_USER + $829;   //定义接收消息索引号
  cMiniSqlStop      = $0001;
  cMiniSqlStart     = $0002;
  cMiniSqlClose     = $0003;
  cMiniSqlTitle     = $0004;
  cTitle            = '迷你SQL2000 v1.22 for Windows(x86/x64)';

function SetMiniSql(vMode: Integer; vTitle: string = ''): Boolean;
var
  vH                : HWND;
begin
  vH := findwindow('TfrmMain', PChar(cTitle));
  if vH = 0 then
  begin
    Result := False;
    Exit;
  end;
  if vMode = 4 then
    sendmessage(vH, WM_SETTEXT, 255, Integer(PChar(vTitle)))
  else
    PostMessage(vH, WM_MiniSQLMsg, vMode, 0);
  Result := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if SetMiniSql(cMiniSqlStop) then
    ShowMessage('ok!')
  else
    ShowMessage('error!');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if SetMiniSql(cMiniSqlStart) then
    ShowMessage('ok!')
  else
    ShowMessage('error!');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if SetMiniSql(cMiniSqlClose, Edit1.Text) then
    ShowMessage('ok!')
  else
    ShowMessage('error!');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if SetMiniSql(cMiniSqlTitle, Edit1.Text) then
    ShowMessage('ok!')
  else
    ShowMessage('error!');
end;

end.

