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.
Asked
Active
Viewed 323 times
0
-
1A `HWND` is a *window* handle. A window is not an icon. An *icon* handle is called a `HICON`. To get the icon of a window, that is, to get the `HICON` of the `HWND`, send the [`WM_GETICON`](http://msdn.microsoft.com/en-us/library/ms632625(VS.85).aspx) message to the window. – Andreas Rejbrand May 08 '11 at 11:56
-
@Andreas, I think Jeff wants to get the icon belonging to the window that he's got a HWND for. – Johan May 08 '11 at 12:02
-
@Johan: Yes, and that's why I told him to use `WM_GETICON`! – Andreas Rejbrand May 08 '11 at 12:03
-
@Andreas I know that I should use the function - my question is: How do I make the image appear in my VirtualStringtree? ;) – Jeff May 08 '11 at 12:08
-
I have never used that control, so Rob Kennedy or some other expert will help you out on this one! – Andreas Rejbrand May 08 '11 at 12:20
1 Answers
2
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;
-
1IconClass is a very bad name for an object reference. It's not a class. I'd call it `Icon`. To make it even simpler I'd just write `ImageList_AddIcon(ImageList1.Handle, IconHandle)` and avoid using a `TIcon` altogether. – David Heffernan May 08 '11 at 13:06
-
@David - I've edited the answer by your suggestions. Thanks. About the IconClass, I know it's a bad name; it's the instance not a class. – May 08 '11 at 13:55