if Findwindow(NULL,"程序标题") then
begin
  {已经有程序运行所做处理。} 
end
else
begin
  {程序还没运行所做处理。}
end;
大概就是这样,抱歉有些日子没用DELPHI了。语法可能不是很准确。

解决方案 »

  1.   

    program Project1;uses
      Forms, Windows, Messages,
      Unit1 in 'Unit1.pas' {Form1};const
      CM_RESTORE = WM_USER + $1000;var
      RvHandle : hWnd;{$R *.RES}begin
      {If there's another instance already running, activate that one}
      RvHandle := FindWindow('My Delphi program!', NIL);
      if RvHandle > 0 then
      begin
        PostMessage(RvHandle, CM_RESTORE, 0, 0);
        Exit;
      end;  {Else, do the normal stuff}
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;end.
      

  2.   

    在prejiec 中var
       Prev:Variant;
    begin
      Application.Initialize;
      Prev:=findwindow('主窗体名称','主窗休标题');
      if prev<>0 then
      begin
           showmessage('该程序已经在运行!');
           setforeGroundWindow(Prev);
           Application.Terminate ;
      end
      else
      begin
            Application.CreateForm(TmF_Main, mF_Main);
      Application.Run;
      end; 
      

  3.   

    liang_z(千山一刀之忍者神龟) 你的方法我试过,不行,还是能出现第二个窗口
      

  4.   

    int WINAPI WinMain(    HINSTANCE hInstance, // handle to current instance
        HINSTANCE hPrevInstance, // handle to previous instance
        LPSTR lpCmdLine, // pointer to command line
        int nCmdShow  // show state of window
       );
    hPrevInstance可以判断