Board index » delphi » Icon for non-visual component

Icon for non-visual component

I've used a freeware TSockets component that uses the code below to
display an icon during the design phase.  When running, the icon does
disappear, but there's an area that seems to cover up or interfere with
visual components.  If I'm lucky, there's a place on the form I can put
the design icon that's out of the way, but I'd like to do this a bit
more professionally....like the Timer design icon or the design icons
for all the nonb-visual components that come with the VCL
I've looked at the source code for the Timer component, but this doesn't
seem to be here.
Any help?
procedure TSockets.TWMPaint(var msg: TWMPaint);
var
  icon: HIcon;
  dc: HDC;
begin
  if csDesigning in ComponentState then
  begin
    icon := LoadIcon(HInstance,MAKEINTRESOURCE('TSOCKETS'));
    dc := GetDC(Handle);
    Width := 32;
    Height := 32;
    DrawIcon(dc,0,0,icon);
    ReleaseDC(Handle,dc);
    FreeResource(icon);
  end;
  ValidateRect(Handle,nil);
end;
[Gary T. Desrosiers, 1995}

And it seems that there's a lot of reliance on the Windows API [all that
HIcon, HDC stuff].  Couldn't you use a TIcon object?:
Thanks in advance.
--jim

 

Re:Icon for non-visual component


Jim,

Derive your component from TComponent and it automatically picks up the same
behavior as the other non-visual components in the VCL. If your deriving it
from TCustomControl or TWinControl because you need a window handle, look at
the source code for TTimer (specifically the calls to AllocateHWnd and
DeAllocateHwnd) to see how it gets a window handle in a TComponent derived
component.

Gerald

Re:Icon for non-visual component


Hmmm.  The one Sockets class is derived from TWinControl, not TComponent.  Guess
it's time to start modifying some code.
Many thanks.
--jim
Quote
Gerald Nunn wrote:
> Jim,

> Derive your component from TComponent and it automatically picks up the same
> behavior as the other non-visual components in the VCL. If your deriving it
> from TCustomControl or TWinControl because you need a window handle, look at
> the source code for TTimer (specifically the calls to AllocateHWnd and
> DeAllocateHwnd) to see how it gets a window handle in a TComponent derived
> component.

> Gerald

Other Threads