Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

Win32 HICON

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

JoshyFun

Hello General,

I have some platform independent code that in Windows must return something like a "TIcon" (the object is not necessary TIcon, I can change it) which must be an independent icon to be added to an imagelist.

I only have a HICON reported by Windows, I try to create a TIcon using:

Ic:=TIcon.Create;
Ic.Handle:=HICON;

But I'm quite sure this is buggy and also I'm unable to add a TIcon to the image list in any way.

So, in resume, I need help in a function or alike that receives an HICON and insert the referenced icon in a given imagelist.

Can anybody help me in the basic steps or function calls needed to this job ?

I'm using Lazarus 0.9.26.1 and fpc 2.2.2 but SVN versions are valid for this code as it is in early development.

Best regards, JoshyFun
Paul Ishenin
to JoshyFun
JoshyFun wrote 9 lines
I only have a HICON reported by Windows, I try to create a TIcon using: Ic:=TIcon.Create; Ic.Handle:=HICON; But I'm quite sure this is buggy and also I'm unable to add a TIcon to the image list in any way.

No, it is not buggy. TIcon must work this way too. About TImageList - it just does not supports AddIcon to create a Bitmap and assign your icon to it first then add that bitmap into imagelist:

var
  B: TBitmap;
begin
  B := TBitmap.Create;
  B.Assign(Ic);
  ImageList.Add(Ic, nil);
end;

Best regards,
Paul Ishenin.

JoshyFun
to Paul Ishenin

Hello Paul,

Friday, December 19, 2008, 12:49:43 AM, you wrote:

PI> No, it is not buggy. TIcon must work this way too. About TImageList - it PI> just does not supports AddIcon > Try to create a Bitmap and assign your icon to it first then add that PI> bitmap into imagelist:

PI> var
PI>   B: TBitmap;
PI> begin
PI>   B := TBitmap.Create;
PI>   B.Assign(Ic);
PI>   ImageList.Add(Ic, nil);
PI> end;

Do not work, but the problem seems to not be related to the bitmap creation, instead in the TIcon creation as:

var
  IC: TIcon;
begin
  IC:=TIcon.Create();
  IC.Handle:=MyHICON;
  Writeln(format('%d,%d',[IC.Width,IC.Height]);
  IC.SetSize(16,16);
  Writeln(format('%d,%d',[IC.Width,IC.Height]);
end;

returns two nice "0,0" :-? So I'm not completly sure that this is the process I must follow to generate the TIcon object. I'll try to, using win32 api, draw the icon somewhere to verify that MyHICON is the expected HICON and not other kind of handle.

Best regards, JoshyFun