Solved

Adding to a component's canvas

Posted on 1998-04-27
5
205 Views
Last Modified: 2010-04-06
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!
0
Comment
Question by:SQLwill
5 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1337849
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
0
 

Author Comment

by:SQLwill
ID: 1337850
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.
0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1337851
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
0
 

Author Comment

by:SQLwill
ID: 1337852
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.  =]
0
 
LVL 1

Accepted Solution

by:
dvaline earned 100 total points
ID: 1337853
Declare a TCanvas:
NewCanvas:= TCanvas;
Initialize the canvas:
NewCanvas := TCanvas.Create;

Next, each time an object is painted to the canvas you want to "keep" save the image to the TCanvas.  This way you have full control.

VisibleCanvas.Assign(NewCanvas) {this might be backwards, I didn't have a chance to check it out, but I know it works}

You can put into an event OnMinimize, OnMaximize, OnPaint, whatever to get the canvas back to the control by just reversing the operation.

NewCanvas.Assign(VisibleCanvas)

Make sure that you put some kind of switch if you use an onpaint event, assigning will cause a paint event, if you don't put a switch it will keep repainting, not a pretty picture, crashola if you know what I mean.




0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calling Tcolordialog in dll make the form disappear 8 111
Comparing dates in Delphi. Greater than/ Less than 3 152
Printing problem 2 93
Firemonkey allowing RTL on android 6 32
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question