[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding to a component's canvas

Posted on 1998-04-27
5
Medium Priority
?
213 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

831 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