Link to home
Start Free TrialLog in
Avatar of SQLwill
SQLwill

asked on

Adding to a component's canvas

I need a good abstarct way, hopefully off of TControl or TWinControl methods or props, that will allow me to make additions to the canvas of many components of unknown type at run time.  EX: Adding a small red circle to the upper left corner of a textbox that will remain when the form is minimized and restored.  If at all possible, I'd like to do this without redirecting WndProcs...   I have, in fact, gotten to draw on the canvas of a textbox using a Canvas i have created and set the Handle of to a GetDC call on the control, but i can't get the image i draw on the control to persist....  all ideas are worth a shot on this one!
Avatar of pjdb
pjdb

Use the onpaint event of the components the circle will be redrawed each time (event after a minimize). To avoid to redraw every thing, you can use the form on paint event and use the form.canvas.cliprect (return the area that need to be redrawed) to test if the circle need to redraw or not.

JDB
Avatar of SQLwill

ASKER

This won't work in the manner in which I intend to use it.  I need a *abstract* method with which to do my assigned task whereupon i do not choose or mess with any components at design time other than to add them to a "WatchedComponents" StringList.
I think you need something like :

function NewWindowProc (wnd:Hwnd; Msg:UINT; Wparam:wparam ;
lparam:lparam): longint; stdcall;
begin
  if Msg=WM_PAINT then begin
     // Do your painting
  end;
  Result := CallWindowProc (OldProc,Wnd,Msg,wParam,lParam);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OldProc :=Pointer(SetWindowLong(      Edit1.Handle,gwl_wndproc,longint(@NewWindowProc)));
end;

Greetings,
MvZ
Avatar of SQLwill

ASKER

This looks like what i might have to do.  I'm trying, however, to do my best to avoid moving around WndProcs, since doing so gets extremely ugly when more than one WndProc stealing component is used.  =]
ASKER CERTIFIED SOLUTION
Avatar of dvaline
dvaline

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial