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 Create Sys Tray / Capture (https://www.delphipraxis.net/136488-create-sys-tray-capture.html)

Razor 1. Jul 2009 14:12


Create Sys Tray / Capture
 
Hey!


I was wondering is it possible to get icons and place all of them in a panel or something..
Mad Kernel is supposed to do this but not work with Win7/Vista/X64.

Also Sharp E does it too but it works in 64 bit but theres tooo much code.I only need the tray and taskbar snippet.To test..

Fridolin Walther 1. Jul 2009 15:56

Re: Create Sys Tray / Capture
 
The systray is essentially a Toolbar. You can just search for it and get a list of pointer that point to datastructures holding the information about each item inside the systray. You can than read those datastructures using ReadProcessMemory. The whole process is outlined here:

http://www.codeproject.com/KB/applic...lTrayInfo.aspx

This will work for XP and later. Getting the tray icon information for earlier Windows versions is a little bit trickier but doable.

[EDIT: By the way. You can't get all icons correctly because some HICON values are simply invalid. I never found the reason why ... I haven't looked much though as I was only interested on the process IDs associated with the tray icons.]

Razor 1. Jul 2009 16:20

Re: Create Sys Tray / Capture
 
Yes thank you thats what i was LOOKING for!But its possible to get to make the icons interactive i mean left and right mouse button

Zitat:

Supported OS
This application only works on Windows XP. It may run on Windows 2003 too, but since I wasn't sure and since I didn't have the option to test it out, I have a version check and the program exits if it's a non-XP OS. If anyone's interested, they can comment out the version check and run it in on 2003 - but I have no idea as to whether it'll work or not.
Are you sure it works on systems newer than xp for example vista/win 7

Razor 2. Jul 2009 15:47

Re: Create Sys Tray / Capture
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ok i finally managed to do something..I can get Number of tray icons + tooltips however no icons or no mouse interactivity yet.So i hope you guys can help on that one.Ive done my part now i expect from you to do the same.

This works on WINDOWS 7264 RTM Build!

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,shellAPI, ComCtrls, ImgList,commctrl, ExtCtrls;

type
  TForm2 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
    h_Tray:hwnd;

function GetSysTrayWnd: HWND;
begin
  Result := FindWindow('Shell_TrayWnd', nil);
  Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil);
  Result := FindWindowEx(Result, 0, 'SysPager', nil);
  Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil);
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  h_ico: HICON;
  h_icolist: TStringlist;
  btn_count, i,handleicon: integer;
  h_Process, dwProcessID:DWord;
  Point: Pointer;
  btn_ico: TTBButton;
  nNumberOfBytesRead: dword;
  buffer: array[0..255] of Char;
begin
  h_Tray:=GetSysTrayWnd;
  btn_count:=sendmessage(h_Tray,TB_BUTTONCOUNT,0,0);
  GetWindowThreadProcessId(h_Tray,@dwProcessID);
  h_Process:=OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE,
                        false,
                        dwProcessID);
  point:=VirtualAllocEx(h_Process,                       nil,
                        4096,
                        MEM_RESERVE or MEM_COMMIT,
                        PAGE_READWRITE);
  for i:=0 to btn_count - 1 do
  begin
    SendMessage(h_Tray, TB_GETBUTTON, i, LPARAM(Point));
    ReadProcessMemory(h_Process,
                      (Point),
                      @btn_ico,
                      sizeof(btn_ico),
                      nNumberOfBytesRead);
    SendMessage(h_Tray, TB_GETBUTTONTEXT , i, LPARAM(Point));
    ReadProcessMemory(h_Process,
                      (Point),
                      @buffer,
                      sizeof(buffer),
                      nNumberOfBytesRead);
    listbox1.Items.Add(buffer);

  end;

  SHOWmessage(inttostr(btn_count));
  handleicon:=SendMessage(h_Tray,TB_GETIMAGELIST,0,0);
  ImageList_GetIcon(handleicon,0,0); ///????
  image1.Canvas.Handle:=ImageList_GetIcon(handleicon,1,0); ///????

Fridolin Walther 2. Jul 2009 15:54

Re: Create Sys Tray / Capture
 
Zitat:

Zitat von Razor
Are you sure it works on systems newer than xp for example vista/win 7

It does work.

Zitat:

Zitat von Razor
Ok i finally managed to do something..I can get Number of tray icons + tooltips however no icons or no mouse interactivity yet.So i hope you guys can help on that one.

Getting the exact icons is tricky and doesn't work for all icons simply because some HICON values are invalid. To implement interactivity you will have to send the messages that the real systray would send to the application. You can take the parameters from the Tooltip data structure (what message to send and the recipient of the message).

May I ask what are you trying to do? Implement an alternative systray?

Razor 2. Jul 2009 16:50

Re: Create Sys Tray / Capture
 
Shell replacment

Fridolin Walther 2. Jul 2009 17:34

Re: Create Sys Tray / Capture
 
Well ... that won't work. I can tell you why:

If you want to build a shell replacement you will replace the shell. Therefore the original shell (Explorer) is not running and the original systray doesn't exist. But you currently read the data from the original systray. You will have to reverse the MSDN-Library durchsuchenShell_NotifyIcon API to find out how exactly the API contacts the systray so you can implement your own one.

Razor 2. Jul 2009 17:52

Re: Create Sys Tray / Capture
 
Liste der Anhänge anzeigen (Anzahl: 1)
Why not find out wich processes have tray then findout wich icons they have?

Edit:/ I have found some untis of sharpe enviroment for delphi wich is a shell replacement.It contains the procedures that you said i need.Can you have a look in shell.dproj.

Razor 2. Jul 2009 19:22

Re: Create Sys Tray / Capture
 
But for start i will rather make it so i can get icons while explorer is ON.Easier.Any tips?

Razor 4. Jul 2009 15:56

Re: Create Sys Tray / Capture
 
24hours past still no reply?


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:02 Uhr.

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