Note that there are some explanatory texts on larger screens.

plurals
  1. POFMX - Trayicon message handling
    text
    copied!<p>I'm having trouble setting up a tray icon with FMX (XE3, Windows). I'm using the same code that can be found in countless threads but I did not get the message handling for the icon to work.</p> <p>To ilustrate I've created a testapp that sets up the TrayIcon data in the FormCreate and creates it with a button. It will show the correct icon and the correct tooltip, the TrayMessage procedure will never get called though.</p> <pre><code>unit Unit2; interface uses System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, Messages, Windows, ShellAPI, FMX.Platform.Win; const WM_ICONTRAY = WM_USER + 1; type TForm2 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private TrayIconData: TNotifyIconData; procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY; end; var Form2: TForm2; implementation {$R *.fmx} procedure TForm2.Button1Click(Sender: TObject); begin Shell_NotifyIcon(NIM_ADD, @TrayIconData); end; procedure TForm2.FormCreate(Sender: TObject); begin with TrayIconData do begin cbSize := SizeOf; Wnd := FmxHandleToHWND(self.Handle); uID := 0; uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP; uCallbackMessage := WM_ICONTRAY; hIcon := GetClassLong(FmxHandleToHWND(self.Handle), GCL_HICONSM); StrPCopy(szTip, 'testapp'); end; end; procedure TForm2.TrayMessage(var Msg: TMessage); begin case Msg.lParam of WM_LBUTTONDOWN: ShowMessage('LBUTTON'); WM_RBUTTONDOWN: ShowMessage('RBUTTON'); end; end; end. </code></pre> <p>I have created the same scenario with VCL and it works as expected. The only difference is directly using Form2.Handle instead of the FMX conversion (and Application.Handle to load the icon data, but that's not part of the issue in FMX). Can anyone point me in the right direction ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload