如果是自己的,看以前的帖子,已经解决了。
如果是别人的,先用findwindow查找看看。

解决方案 »

  1.   

    修改工程文件:
    var hMutex: Hwnd;
        Ret: integer;
    begin
      Application.Initialize;
      Application.Title:='Program Run Once Test':
      hMutex:=CreateMutex(nil,false,'Program Run Once Test');
      Ret:=GetLastError;
      if Ret<>Error_Already_Exists then 
         begin
           Application.Create(TForm1,Form1);
           Application.Run;
         end
      else
        Application.MessageBox('This Program is running','Warning',MB_OK);
      ReleaseMutex(hMutex);
    end;
      

  2.   

    给你一个我修改后的构件
    {
    JustOne v1.1 - A Delphi Component
    By: Steven L. Keyser
        email: 71214,[email protected]  ####################################################################
      # Modified By He Kai, ZIQ, China, email : [email protected]
      #  Delphi 3.0                    26-Jun-1998
      # In order to use in Win95, I Modified the program, the original can only
      #  use in win31
      ####################################################################    Purpose: JustOne is a component which makes it easy to limit the
        number of your application's instances to just one.  If a second
        instance of your application starts, the first instance is brought
        to the front and given the focus (or restored if it was minimized
        to an icon).  The second instance then halts.}
    unit Justone;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, DsgnIntf;type
    TMyDataType = record
    Name : string;
    end;type
      TJustOne = class(TComponent)
      private
      public
        constructor Create(AOwner:TComponent); override;
        destructor Destroy; override;
        procedure GoToPreviousInstance;
      published
      end;procedure Register;type
      PHWND = ^HWND;
      // Modified By He Kai
      // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export;
      function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export; stdcall;implementation{########################################################################}
    procedure Register;
    {If you want, replace 'SLicK' with whichever component page you want
    JustOne to show up on.}
    begin
      RegisterComponents('HK Invisible', [TJustOne]);
    end;{########################################################################}
    // Modified by He Kai
    {
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      ClassName : array[0..30] of char;
    begin
      result := TRUE;
      if GetWindowWord(Wnd,GWW_HINSTANCE) = hPrevInst then
         begin
           GetClassName(Wnd,ClassName,30);
           if StrIComp(ClassName,'TApplication') = 0 then
             begin
               TargetWindow^ := Wnd;
               result := FALSE;
             end;
         end;
    end;
    }
    // Modified By He Kai
    // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      TheClassName  : array[0..200] of char;
      TheTitleName  : array[0..200] of char;
      ThisTitleName : String;
    begin
      result := TRUE;
      GetClassName(Wnd,TheClassName,200);
      if StrIComp( TheClassName,'TApplication' ) = 0 then
      begin
        GetWindowText( Wnd, TheTitleName, 200 );
        ThisTitleName := Application.Title;
        If (Wnd<>Application.Handle) And (StrIComp( PChar(ThisTitleName), TheTitleName ) = 0) Then
        Begin
          TargetWindow^ := Wnd;
          result := FALSE;
        End;
      End;
    end;{########################################################################}
    procedure TJustOne.GotoPreviousInstance;
    var
      PrevInstWnd : HWND;
    begin
      PrevInstWnd := 0;
      EnumWindows(@EnumFunc,longint(@PrevInstWnd));  if PrevInstWnd <> 0 then
      Begin
        if IsIconic(PrevInstWnd) then
          ShowWindow(PrevInstWnd,SW_RESTORE)
        else
          SetForegroundWindow(PrevInstWnd);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Sleep(450);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Halt;
      End
    end;{########################################################################}
    constructor TJustOne.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);
    // modified by He Kai
    // if hPrevInst <> 0 then
    //    begin
      GotoPreviousInstance;
    //      halt;
    //    end;
    end;{########################################################################}
    destructor TJustOne.Destroy;
    begin
      inherited Destroy;
    end;{########################################################################}
    end.
      

  3.   

    给你一个我修改后的构件
    {
    JustOne v1.1 - A Delphi Component
    By: Steven L. Keyser
        email: 71214,[email protected]  ####################################################################
      # Modified By He Kai, ZIQ, China, email : [email protected]
      #  Delphi 3.0                    26-Jun-1998
      # In order to use in Win95, I Modified the program, the original can only
      #  use in win31
      ####################################################################    Purpose: JustOne is a component which makes it easy to limit the
        number of your application's instances to just one.  If a second
        instance of your application starts, the first instance is brought
        to the front and given the focus (or restored if it was minimized
        to an icon).  The second instance then halts.}
    unit Justone;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, DsgnIntf;type
    TMyDataType = record
    Name : string;
    end;type
      TJustOne = class(TComponent)
      private
      public
        constructor Create(AOwner:TComponent); override;
        destructor Destroy; override;
        procedure GoToPreviousInstance;
      published
      end;procedure Register;type
      PHWND = ^HWND;
      // Modified By He Kai
      // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export;
      function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export; stdcall;implementation{########################################################################}
    procedure Register;
    {If you want, replace 'SLicK' with whichever component page you want
    JustOne to show up on.}
    begin
      RegisterComponents('HK Invisible', [TJustOne]);
    end;{########################################################################}
    // Modified by He Kai
    {
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      ClassName : array[0..30] of char;
    begin
      result := TRUE;
      if GetWindowWord(Wnd,GWW_HINSTANCE) = hPrevInst then
         begin
           GetClassName(Wnd,ClassName,30);
           if StrIComp(ClassName,'TApplication') = 0 then
             begin
               TargetWindow^ := Wnd;
               result := FALSE;
             end;
         end;
    end;
    }
    // Modified By He Kai
    // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      TheClassName  : array[0..200] of char;
      TheTitleName  : array[0..200] of char;
      ThisTitleName : String;
    begin
      result := TRUE;
      GetClassName(Wnd,TheClassName,200);
      if StrIComp( TheClassName,'TApplication' ) = 0 then
      begin
        GetWindowText( Wnd, TheTitleName, 200 );
        ThisTitleName := Application.Title;
        If (Wnd<>Application.Handle) And (StrIComp( PChar(ThisTitleName), TheTitleName ) = 0) Then
        Begin
          TargetWindow^ := Wnd;
          result := FALSE;
        End;
      End;
    end;{########################################################################}
    procedure TJustOne.GotoPreviousInstance;
    var
      PrevInstWnd : HWND;
    begin
      PrevInstWnd := 0;
      EnumWindows(@EnumFunc,longint(@PrevInstWnd));  if PrevInstWnd <> 0 then
      Begin
        if IsIconic(PrevInstWnd) then
          ShowWindow(PrevInstWnd,SW_RESTORE)
        else
          SetForegroundWindow(PrevInstWnd);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Sleep(450);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Halt;
      End
    end;{########################################################################}
    constructor TJustOne.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);
    // modified by He Kai
    // if hPrevInst <> 0 then
    //    begin
      GotoPreviousInstance;
    //      halt;
    //    end;
    end;{########################################################################}
    destructor TJustOne.Destroy;
    begin
      inherited Destroy;
    end;{########################################################################}
    end.
      

  4.   

    给你一个我修改后的构件
    {
    JustOne v1.1 - A Delphi Component
    By: Steven L. Keyser
        email: 71214,[email protected]  ####################################################################
      # Modified By He Kai, ZIQ, China, email : [email protected]
      #  Delphi 3.0                    26-Jun-1998
      # In order to use in Win95, I Modified the program, the original can only
      #  use in win31
      ####################################################################    Purpose: JustOne is a component which makes it easy to limit the
        number of your application's instances to just one.  If a second
        instance of your application starts, the first instance is brought
        to the front and given the focus (or restored if it was minimized
        to an icon).  The second instance then halts.}
    unit Justone;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, DsgnIntf;type
    TMyDataType = record
    Name : string;
    end;type
      TJustOne = class(TComponent)
      private
      public
        constructor Create(AOwner:TComponent); override;
        destructor Destroy; override;
        procedure GoToPreviousInstance;
      published
      end;procedure Register;type
      PHWND = ^HWND;
      // Modified By He Kai
      // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export;
      function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean; export; stdcall;implementation{########################################################################}
    procedure Register;
    {If you want, replace 'SLicK' with whichever component page you want
    JustOne to show up on.}
    begin
      RegisterComponents('HK Invisible', [TJustOne]);
    end;{########################################################################}
    // Modified by He Kai
    {
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      ClassName : array[0..30] of char;
    begin
      result := TRUE;
      if GetWindowWord(Wnd,GWW_HINSTANCE) = hPrevInst then
         begin
           GetClassName(Wnd,ClassName,30);
           if StrIComp(ClassName,'TApplication') = 0 then
             begin
               TargetWindow^ := Wnd;
               result := FALSE;
             end;
         end;
    end;
    }
    // Modified By He Kai
    // function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    function EnumFunc(Wnd:HWND; TargetWindow:PHWND): boolean;
    var
      TheClassName  : array[0..200] of char;
      TheTitleName  : array[0..200] of char;
      ThisTitleName : String;
    begin
      result := TRUE;
      GetClassName(Wnd,TheClassName,200);
      if StrIComp( TheClassName,'TApplication' ) = 0 then
      begin
        GetWindowText( Wnd, TheTitleName, 200 );
        ThisTitleName := Application.Title;
        If (Wnd<>Application.Handle) And (StrIComp( PChar(ThisTitleName), TheTitleName ) = 0) Then
        Begin
          TargetWindow^ := Wnd;
          result := FALSE;
        End;
      End;
    end;{########################################################################}
    procedure TJustOne.GotoPreviousInstance;
    var
      PrevInstWnd : HWND;
    begin
      PrevInstWnd := 0;
      EnumWindows(@EnumFunc,longint(@PrevInstWnd));  if PrevInstWnd <> 0 then
      Begin
        if IsIconic(PrevInstWnd) then
          ShowWindow(PrevInstWnd,SW_RESTORE)
        else
          SetForegroundWindow(PrevInstWnd);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Sleep(450);
        FlashWindow(PrevInstWnd, True );
        Sleep(450);
        FlashWindow(PrevInstWnd, false );
        Halt;
      End
    end;{########################################################################}
    constructor TJustOne.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);
    // modified by He Kai
    // if hPrevInst <> 0 then
    //    begin
      GotoPreviousInstance;
    //      halt;
    //    end;
    end;{########################################################################}
    destructor TJustOne.Destroy;
    begin
      inherited Destroy;
    end;{########################################################################}
    end.
      

  5.   

    Apollo47(): 错误 Hwnd CreateMutex ReleaseMutex 没有定义啊 现在怎么版啊