程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 防止程序多次運行

防止程序多次運行

編輯:Delphi
  [dpr部分]
  program Project1;
  
  uses
    Forms,
    Unit1 in 'Unit1.pas' {Form1}
     ,Windows, Messages;
  
  const
  hfck=wm_user+$1000;
  appname='myname';
  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.
  
  [form部分]
  unit Unit1;
  
  interface
  
  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs;
  const
  hfck=wm_user+$1000;
  appname='myname';
  type
    TForm1 = class(TForm)
    private
      { Private declarations }
    public
    procedure createparams(var params:tcreateparams);override;
    procedure restorerequest(var msg:tmessage);message hfck;
  
  
      { Public declarations }
    end;
  
  var
    Form1: TForm1;
  
  implementation
  
  {$R *.dfm}
  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;
  end.
  
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved