var Hwnd:THandle;
begin
  Hwnd:= findwindow(nil,'美容院管理系统'); // frm_main.caption = '美容院管理系统'
  if (Hwnd<>0) then  //表示已经有实例
  begin
    SetForegroundWindow(Hwnd); //激活已运行的程序实例,但程序最小化时无效
  end
  else   //表示还没有实例
  begin
    try
      Application.Initialize;
      Application.Title :='美容院管理系统1.0';
      Application.CreateForm(Tfrm_main, frm_main);
      Application.CreateForm(TDMod, DMod);
      Application.CreateForm(Tfrm_login, frm_login);
      frm_login.ShowModal;
      if frm_login.logined then Application.Run;
    except
      MessageBox(Application.Handle,'联接数据库服务器失败,请与管理员联系!','提示',mb_ok+mb_iconinformation);
    end;
  end;end.

解决方案 »

  1.   

    If the function succeeds, the return value is a handle to the window that has 
    the specified class name and window name.
    If the function fails, the return value is NULL. 
    To get extended error information, call GetLastError. 
      

  2.   

    楼主是不是在调试的时候,如果你在Delphi中打开了哪个窗口的话,你就会找到的.像这种程序只能启动一次最好用信号量.
      

  3.   

    怎么可能找的到呢?'美容院管理系统 '  肯定不等于   '美容院管理系统1.0 '所以你返回的肯定为0. Hwnd:=   findwindow(nil, '美容院管理系统 ');  //改成FindWindow(nil, '美容院管理系统1.0 ');后面为啥都要多个空格呢?
     ....
     Application.Title   := '美容院管理系统1.0 '; 
      

  4.   

    sorry, 看错了,我以为你没找到。那样的话就是Bear_hx 所说的了情况了。
      

  5.   

    简而言之:用信号量 CreateMutex
      

  6.   

    如果你是在debug环境下运行的,
    系统会找到你工程中那个窗口,就认为已经存在了。