Solved

Adding to a component's canvas

Posted on 1998-04-27
5
203 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now