想让程序同时只有一个实例运行,因为程序中使用了托盘,所以试了很多方法都不好,特在此请教。

解决方案 »

  1.   

    参见http://expert.csdn.net/Expert/topic/2054/2054062.xml?temp=.1067316
      

  2.   

    program DEL3test;
    usesFormsWindowsSysUtils
    DEL3unit in 'DEL3unit.pas' {Form1};
    {$R *.RES}
    VarhMutex:HWND;Ret:Integer;beginApplication.Initialize;Application.Title := 'aaaaaa';hMutex:=CreateMutex(nilFalse'aaaaaa');Ret:=GetLastError;If Ret<>ERROR_ALREADY_EXISTS ThenBeginApplication.CreateForm(TForm1Form1);Application.Run;EndElseApplication.MessageBox('Run Twice!''Notes!'MB_OK);ReleaseMutex(hMutex);end.
    试试吧!