Показать сообщение отдельно
  #2  
Старый 08.01.2015, 19:37
lmikle lmikle вне форума
Модератор
 
Регистрация: 17.04.2008
Сообщения: 8,105
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
По умолчанию

Я делал так.
В файле проекта:
Код:
function AllowSetForegroundWindow(dwProcessId: DWORD): BOOL; stdcall; external 'user32.dll';

function CanStart : Boolean;
var
  hMutex : THandle;
begin
  Result := True;

  WndMessage := RegisterWindowMessage(PChar(GetMessageName));

  hMutex := CreateMutex(Nil, True, PChar(GetMutexName));
  If hMutex<>0 Then
    If GetLastError=ERROR_ALREADY_EXISTS Then
      Begin
        AllowSetForegroundWindow(DWORD(-1));
        PostMessage(HWND_BROADCAST,WndMessage,0,0);
        Result := False;
      End;
end;

begin
  If CanStart Then
    Begin
      Application.Initialize;
      Application.Title := 'Visual Reminder';
      Application.CreateForm(TMainForm, MainForm);
      Application.HookMainWindow(MainForm.HookMessageProc);
      Application.Run;
    End;
end.

В главной форме:
Код:
type
  TMainForm = class TForm
  ..
    function HookMessageProc(var Message : TMessage) : Boolean;
  end;

var
  MainForm: TMainForm;
  WndMessage : Cardinal;

function TMainForm.HookMessageProc(var Message: TMessage): Boolean;
begin
  Result := False;
  If Message.Msg = WndMessage Then
    Begin
      TrayIcon.ShowMainForm;
      Application.BringToFront;
      SetForegroundWindow(Self.Handle);
      Result := True;
    End;
end;

Надеюсь, ничего не забыл...
Ответить с цитированием