Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Eigener Systemtray (https://www.delphipraxis.net/28738-eigener-systemtray.html)

helen 29. Aug 2004 15:53


Eigener Systemtray
 
Hallo,

ich versuche derzeit einen Ersatz für den Systemtray zu entwickeln.
Wie kann ich in meiner Anwendung das Icon, welches von der Anwendung XYZ mit

Code:
  fIcon := TIcon.Create;
  fIcon.Assign(Application.Icon);
  if not (csDesigning in ComponentState) then
  begin
    FillChar(fData, SizeOf(fData), 0);
    fData.cbSize := SizeOf(fData);
    fData.Wnd := AllocateHwnd(OnMessage); // handle to get notification message
    fData.hIcon := Icon.Handle; // icon to display
    StrPLCopy(fData.szTip, Application.Title, SizeOf(fData.szTip) - 1);
    fData.uFlags := Nif_Icon or Nif_Message;
    if Application.Title <> '' then
      fData.uFlags := fData.uFlags or Nif_Tip;
    fData.uCallbackMessage := WM_CALLBACK_MESSAGE;
    if not Shell_NotifyIcon(NIM_ADD, @fData) then // add it
      raise EOutOfResources.Create('Cannot create shell notification icon');
      {
        Replace the application's minimize and restore handlers with
        special ones for the tray. The TrayIcon component has its own
        OnMinimize and OnRestore events that the user can set.
      }
    Application.OnMinimize := AppMinimize;
    Application.OnRestore := AppRestore;
  end;
gesendet wurde in meiner Anwendung wieder als Icon auspacken?

Mein Ziel ist also, das Icon, welches mit
Code:
  fIcon := TIcon.Create;
  fIcon.Assign(Application.Icon);
  fData.hIcon := Icon.Handle;
eingepackt wurde in meiner Anwendung wieder auszupacken.

Meine Empfangsprocedure:
Code:
procedure TX11TBNA.WMCopyData (var Msg : TWMCopyData);
  type
    TBNApaket = record
       cbsize : Cardinal;
       Icon : Pointer; //HIcon;
       szTip : String [100];
       CallBackMsg : Cardinal;
       Flags : Cardinal;
       ID : Cardinal;
       Wnd : HWND;

       dwMessage : DWord;
    end;

  var paket : TBNApaket; lppaket : ^TBNApaket;
      i, imgpos : Integer; img : TICon;
begin
  lppaket := Msg.CopyDataStruct.lpData;
  paket := lppaket^;


  imgpos := -1;
  For i := 0 to Listview1.Items.Count-1 do
      if (StrToInt (Listview1.Items[i].SubItems[0]) = paket.Wnd){ and
         (StrToInt (Listview1.Items[i].SubItems[1]) = paket.uID)} then
         imgpos := I;

  img := Ticon.Create; //paket.Icon;

  if paket.dwMessage = NIM_ADD then begin
     //ShowMessage ('ADD');

     If imgpos < 0 then
        with Listview1.Items.Add do begin
              ImageIndex := ImageList1.AddIcon (img); //ImageList1.AddIcon (paket.Icon);
              Caption := paket.szTip;

              SubItems.Add (IntToStr(paket.Wnd));
              SubItems.Add (IntToStr(paket.ID));
        end;
  end
  else

  if paket.dwMessage = NIM_MODIFY then begin
     //ShowMessage ('Modify');

     If imgpos > -1 then
        with ListView1.Items [imgpos] do begin
             ImageIndex := ImageList1.AddIcon (img); // ImageList1.AddIcon (paket.Icon);
              Caption := paket.szTip;
        end
     else
         with Listview1.Items.Add do begin
              ImageIndex := ImageList1.AddIcon (img); // ImageList1.AddIcon (paket.Icon);
              Caption := paket.szTip;
             
              SubItems.Add (IntToStr(paket.Wnd));
              SubItems.Add (IntToStr(paket.ID));
        end;
  end
  else

  if paket.dwMessage = NIM_DELETE then begin
     //ShowMessage ('Delete');

     If imgpos > -1 then
        ListView1.Items.Delete (imgpos);
  end

  else ShowMessage ('Command not found!');
end;
Die 2. Frage:
Wie kann ich auf Ereignisse reagieren, wenn z.b. der Nutzer auf das Icon clickt?

Danke für die Hilfe

Helen


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:10 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz