뮤텍스를 작성하여 응용 프로그램의 다른 인스턴스가 이미 실행중인 경우 기본 양식의 OnCreate 중에 확인하는 응용 프로그램이 있습니다. 그럴 경우 두 번째 인스턴스는 첫 번째 인스턴스로 메시지를 전달한 다음 자신을 닫습니다. 두 번째 응용 프로그램의 작은 중괄호가 닫히기 전에 화면에 잠시 동안 기본 양식을 깜박임을 제외하고는 정상적으로 작동합니다.두 번째 응용 프로그램 인스턴스를 거의 즉시 닫을 때 양식이 잠깐 깜박임 중지
기본 폼 WindowState를 wsMinimize로 설정하여 응용 프로그램을 시작한 다음 폼을 최대화하기 위해 1ms 지연 타이머를 사용하는 것이 좋습니다. 그러나 이것은 끔찍한 해킹처럼 보입니다.
더 좋은 아이디어가 있습니까?
procedure TMyAwesomeForm.FormCreate(Sender: TObject);
var
h: HWND;
begin
// Try to create mutex
if CreateMutex(nil, True, '6EACD0BF-F3E0-44D9-91E7-47467B5A2B6A') = 0 then
RaiseLastOSError;
// If application already running
if GetLastError = ERROR_ALREADY_EXISTS then
begin
// Prevent this instance from being the receipient of it's own message by changing form name
MyAwesomeForm.Name := 'KillMe';
// If this instance was started with parameters:
if ParamCount > 0 then
begin
h := FindWindow(nil, 'MyAwesomeForm');
//Pass the parameter to original application
SendMessage(h, WM_MY_MESSAGE, strtoint(ParamStr(1)),0);
end;
// Shut this instance down - there can be only one
Application.Terminate;
end;
// Create Jump Lists
JumpList := TJumpList.Create;
JumpList.ApplicationId := 'TaskbarDemo.Unique.Id';
JumpList.DeleteList;
CreateJList();
end;
은 * .DPR 파일에서 호출됩니다. – TLama
이것은 [이 질문] (http://stackoverflow.com/q/15136960/62576)과 매우 유사합니다. 아마도 거기에 대한 대답이 도움이 될 수 있습니다. (당신이 너무 늦게 체크하고있다 - FormCreate를 치기 전에 너무 늦어서 막을 수 없으며,'Application.Terminate'는 주 윈도우에 단순히'WM_QUIT' 메시지를 게시한다. 이전 인스턴스를 체크 할 필요가있다. 'Application.Initialize'가 호출되기 전에'.dpr' 파일에.) –