Win32当然不能这样,各个process是独立的
可以该这样:
hwnd = FindWindow( "TLogin", NULL );
if(hwnd)
{
MessageBox(NULL,"Already run!","Login", MB_OK);
return 0;
}
可以该这样:
hwnd = FindWindow( "TLogin", NULL );
if(hwnd)
{
MessageBox(NULL,"Already run!","Login", MB_OK);
return 0;
}
我的网站上现在正在上传一个开机后自动login的程序
(有源代码)
晚上就可以看到了
http://cppsource.yeah.net
WINDOWS,
Forms,
MainApp in 'MainApp.pas' {MainForm},
{$R *.RES}
const
classname = 'TMainForm';
var
handle : integer;
begin
handle := findwindow(classname,nil);
if handle <> 0 then begin
showwindow(handle,SW_SHOW);
halt;
end;
Application.Initialize;
Application.Title := 'aaa';
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
因为Found the Window.可以试试以下的方法.本人已经测试过.1、主窗口的修改 TFormCapture = class(TForm) ... protected //增加
procedure CreateParams(var Params: TCreateParams); override;
procedure RequestRestore(var Message: TMessage); message CM_RESTORE;
end;implementation{$R *.DFM}...procedure TFormCapture.CreateParams(var Params: TCreateParams);
begin
Inherited CreateParams(Params);
Params.WinClassName := 'MAINFORM'; //新的类名
end;procedure TFormCapture.RequestRestore(var Message: TMessage);
begin
if IsIconIc(Application.Handle) then
Application.Restore
else
Application.BringToFront;
end;
2、工程文件的修改program TEST;uses
... Main in 'Main.pas' {MainForm},
{$R *.RES}
var
M_Handle : THandle;
begin
Application.Initialize;
M_Handle := findwindow('MAINFORM',nil); //查找修改的类名
if M_Handle <> 0 then
begin
PostMessage(M_Handle, CM_RESTORE, 0, 0);
Exit;
end;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
本网站的delphi资料库中有很多小技巧,你的问题的答案就在其中,没必要浪费分数!
xixi(^^)
program Project1;uses
Forms,Windows,SysUtils,
unit1 in 'unit1.pas' {Form1};
{$R *.RES}
Var
hMutex:HWND;
Ret:Integer;
begin
Application.Initialize;
Application.Title := 'hello';
hMutex:=CreateMutex(nil,False,'NoTwice');
Ret:=GetLastError;
If Ret<>ERROR_ALREADY_EXISTS Then
Begin
Application.CreateForm(TForm1, Form1);
Application.Run;
End
Else
Application.Terminate;
ReleaseMutex(hMutex);
end.上文已调试通过.
不妨前去一试!