Result := MIError; end; function NewWndProc(Handle: HWND; Msg: Integer; wParam, lParam: Longint): Longint; StdCall; begin
Result := 1; if Msg = MessageID then begin if IsIconic(Application.Handle) then OpenIcon(Application.Handle) else SetForegroundWindow(Application.Handle); FileWork.LoadFileName(RegWork.RWGetParamStr1); end else Result := CallWindowProc(WProc, Handle, Msg, wParam, lParam); end; procedure SubClassApplication; begin
WProc := TFNWndProc(SetWindowLong(Application.Handle, GWL_WNDPROC, Longint(@NewWndProc))); if WProc = Nil then MIError := MIError or MI_FAIL_SUBCLASS; end; procedure DoFirstInstance; begin
SubClassApplication; MutHandle := CreateMutex(Nil, False, UniqueAppStr); if MutHandle = 0 then MIError := MIError or MI_FAIL_CREATE_MUTEX; end; procedure BroadcastFocusMessage; begin
Application.ShowMainForm := False; PostMessage(HWND_BROADCAST, MessageId,0,0); end; function InitInstance : Boolean; begin
MutHandle := OpenMutex(MUTEX_ALL_ACCESS, False, UniqueAppStr); if MutHandle = 0 then begin ShowWindow(Application.Handle, SW_ShowNormal); Application.ShowMainForm:=True; DoFirstInstance; result := True; end else begin RegWork.RWSetParamStr1; BroadcastFocusMessage; result := False; end; end; initialization begin