Search code examples
windowsdelphiiconswindow-handles

Use HWND (or something similar) as Node Image in Virtual Stringtree


Is it possible to display an Icon obtained from an external Handle, as the Image of my Node in Virtual Stringtree? The Node's Data contains the HWND.


Solution

  • I would use ImageList assigned to your VT's Images property and OnGetImageIndex event. Here's how to fill the image list using WM_GETICON.

    procedure TForm1.Button1Click(Sender: TObject);
    var IconHandle: HIcon;
    
    begin
      IconHandle := SendMessage(123456, WM_GETICON, ICON_SMALL2, 0);
      ImageList_AddIcon(ImageList1.Handle, IconHandle);
    end;
    

    And for example pass the 0 image index to the VirtualTreeView.

    procedure TForm10.VirtualStringTree1GetImageIndex(Sender: TBaseVirtualTree;
      Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
      var Ghosted: Boolean; var ImageIndex: Integer);
    begin
      ImageIndex := 0;
    end;