Icons

delphi package - easy access to kernel objects etc.
Post Reply
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

Icons

Post by stOrM! »

Hello,
i have a short question because of the process icons...

maybe i've overlooked something but the imagelist contains only 1 icon :confused:

Code: Select all

For I := 0 To Processes.ItemCount -1 Do
  Begin
FIcon.Handle :=  MadKernel.Icon(Processes.Items[i].ExeFile, True, False);
Imagelist1.AddIcon(FIcon);
This is working correct:
(Entry of the Grid is selected Icon is display'd seperatly in an image component)

Code: Select all

 Image1.Picture.Icon.Handle := MadKernel.Icon(GridView1.Cells[2, ARow] + GridView1.Cells[1, ARow], false, False);
Sorry for the stupid question (this happens when a gfx'ler try's to programm) :blush:

regards
s!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Icons

Post by madshi »

stOrM! wrote:maybe i've overlooked something but the imagelist contains only 1 icon :confused:

Code: Select all

For I := 0 To Processes.ItemCount -1 Do
  Begin
FIcon.Handle :=  MadKernel.Icon(Processes.Items[i].ExeFile, True, False);
Imagelist1.AddIcon(FIcon);
First of all: Please use "with Processes do". The way you're doing it (I mean calling Processes multiple times) the process enumeration is done multiple times, too, which is very bad for performance. You should call "Processes" only once, if possible. Anyway, that's nothing to do with your problem.

Don't know why you only get one icon in the image list. Try using "ImageList_AddIcon(Imagelist1.Handle, iconHandle)". You should then call "DestroyIcon" to clean the icon returned by madKernel up.
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

Ok I see thank you for your time anyway...
Maybe it's a problem with the component which later shows the icons??
Have to proof that again...

Another problem I forgot to talk about is:
When I click on a Process my Grid shows, I got back the commandline and Exetype in 2 different Labels but before that happend the very first time I click on an entry in the Grid I get: "madCHook.dll not found"

This appears only once afther starting the application and clicking on an entry the very first time...

Nevermind I copy'd it into the application directory the error is gone now...
Guess it had something todo while receiving the commandline in the Label?!

best regards
s!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

madKernel internally uses madCodeHook - *IF* you install madCodeHook. But madCodeHook in the non-commercial edition links to the madCHook.dll. So you need to copy that dll to your application's folder. If you don't like that, just don't install madCodeHook. However, madKernel will have slightly limited functionality then.
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

Thank you for explaining.
best regards
s!
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

Maybe not sure but could this be the Problem:

I first need to tell I'm using a Grid to display most information of the processes , threads and of course the icons of them...
Grid is from Bergsoftware.net

So I was playing around with the MadKernel.Icon(...ExeFile, True, False); routine and noticed that Exefile needs the full path of the exefile (hope I'm right here...

So I started like this:

Code: Select all

procedure TForm1.FormShow(Sender: TObject);
var I : Integer;
    StripP,
    StripE,
    Whole : String;
begin
   GridView1.ClearRows;
   EnableAllPrivileges;
   GridView1.BeginUpdate;
   ConvertTo32BitImageList(ImageList2);
with Processes do
 For I := 0 To ItemCount -1 Do
  Begin
    GridView1.AddRow(1);
    ImageList2.AddIcon(Image1.Picture.Icon);
    GridView1.Cell[1, I].AsString := ExtractFileName(Items[I].ExeFile);
    GridView1.Cell[2, I].AsString := ExtractFilePath(Items[I].ExeFile);
    GridView1.Cell[3, I].AsString := IntToStr(Items[I].ID);
    GridView1.Cell[4, I].AsString := IntToStr(Processes[I].Threads.ItemCount);
    StripP := ExtractFilePath(Items[I].ExeFile);
    StripE := ExtractFileName(Items[I].ExeFile);
    Whole := StripP + StripE;
    Image1.Picture.Icon.Handle :=  MadKernel.Icon(Whole, True, False);
    ImageList2.AddIcon(Image1.Picture.Icon);
    GridView1.EndUpdate;
  end;
end;
In "Whole" i putted together the filename and the path to the executeable while Madkernel.Icon should extract the icon and put it into the Image component then into the Imagelist...
The Gridview always display's just a folder icon doesn't matter what executeable it is...

The crazy thing is when I do it manually like using an image1 and just the gridview while clicking on an item i'll extract the icon for that file and display it in the image this works without any problems :confused:

Madshi do you know whats up???
regards
s!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I don't know how the grid control works, sorry...
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

I understand too many controls not possible to know them all...
But I mean can it be that Madkernel.Icon isn't able to handle what I made???
Like I say if I do this for example it works:

Code: Select all

procedure TForm1.GridView1SelectCell(Sender: TObject; ACol, ARow: Integer);
begin
    Image1.Picture.Icon.Handle := MadKernel.Icon(GridView1.Cells[2, ARow] + GridView1.Cells[1, ARow], false, False);

Cell 2 of the Gridview holds the Path only while Cell 1 holds the executeable name without path...

So thats why I'm not sure whats went wrong while looking at the code above
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I don't know what went wrong, either. But if it works in one situation and not in another situation, then most likely it's not the fault of madKernel.
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

Ok that makes sense I have to try and error then...
I'll let you know when you're interested when I have a solution...

best regards and thank you for your time...
s!
stOrM!
Posts: 51
Joined: Thu Jul 15, 2004 7:38 pm

re

Post by stOrM! »

Yo Madshi as promised I got the Icons working :D
The Imagelist wasn't filled with just 1 icon as assumed, it was full filled bye your function: MadKernel.Icon();

The Problem was that I have filled the Imagelist with Icons but din't assigned the index of them to the Gridview.cell[0, I] maybe this makes it clearer:

Code: Select all

 Whole := StripP + StripE; // holds the path and executeable name of each process

SHGetFileInfo(PChar(Whole), 0, FileInfo,
            SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);

    icon.Handle := FileInfo.hIcon;

//now the line which makes it work!!
    GridView1.Cell[0, I].AsInteger := ImageList2.AddIcon(Icon);

So maybe if someone also used BergGrid and runs into the same problem it might help

best regards
s!
Post Reply