各位前辈高人,小弟写了个程序,为了防止二次运行而在在工程文件里加了
const
  hfck=wm_user+$1000;
  appname='kav';
var
  myhandle:hwnd;{$R *.res}begin
myhandle:=findwindow(appname,nil);
if myhandle>0 then
  begin
  postmessage(myhandle,hfck,0,0);
  exit;
end;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.在UNIT文件里加
const
  hfck=wm_user+$1000;
  appname='kav';procedure TForm1.createparams(var params: tcreateparams);
begin
  inherited createparams(params);
  params.WinClassName:=appname;
end;procedure TForm1.restorerequest(var msg: tmessage);
begin
 if isiconic(application.Handle )=true then
  application.Restore
  else
  application.BringToFront ;
end;这些代码,但是在有的机子上运行正常,而在有的机子上只在进程里显示,却不显示主窗体,
机子都是XP系统的,会是怎么一回事,请指点一下。

解决方案 »

  1.   

    你在 unit里面添加的那些代码,跟防止二次运行没关系吧,去掉试试
      

  2.   

    需要用窗体的标题FindWindow才有效,用Mutex防止二次运行比较好点
      

  3.   

    你的自定义的消息hfck,它在哪里处理了,没有看到它的处理代码啊
      

  4.   

    参考一下……  //只运行一个实例
      hApp := FindWindow('TApplication', '秋风人事档案管理系统');
      if hApp <> 0 then
      begin
        //找登录窗口
        hLogin := FindWindow('TfrmLogin', nil);
        if hLogin <> 0 then
          SetForegroundWindow(hLogin)
        //找主窗口
        else
        begin
          hMain := FindWindow('TfrmMain', nil);
          if hMain <> 0 then
          begin
            if IsIconic(hMain) then OpenIcon(hMain);
            //这里置前hApp,是因为MainForm前有模式窗口时,仍然是MainForm激活的问题
            SetForegroundWindow(hApp);
          end
        end;    Application.Terminate;
        Application.ShowMainForm := False;
      end;
      

  5.   

    提示一下,虽然不知道你的是不是这个问题。Delphi编写的程序如果设置了窗体位置,在连接多显示器的机器上会显示到最后一个显示器上,从而出现一种本机只有进程没有窗体的情况。虽然你的不一定是这个问题,我只是提示下。
      

  6.   

    program Live;   
      
    uses  
      Windows,   
      Forms,   
      ShellApi,   
      SysUtils;   
      
    {$R *.TLB}  
      
    {$R *.res}  
    var  
      HMutex:Hwnd;   
      Ret:Integer;   
    begin  
      
      Application.Initialize;   
      aTitle := 'LiveAuction';   
      Application.Title := 'LiveAuction';   
      
      HMutex:=CreateMutex(nil,False,Pchar(aTitle));  //建立互斥对象,名字为aTitle--'LiveAuction'   
      Ret:=GetLastError;   
      If Ret<>ERROR_ALREADY_EXISTS Then   
      begin  
         //做我们正常该做的事情   
      end else  
        ReleaseMutex(hMutex);  //防止创建多个程序实例   
      
      Application.Run;   
    end.