Solved

Adding to a component's canvas

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a path if not exists 7 68
Dynamically Created Query 3 49
Delphi and Access based Enumeration 9 44
update joined tables 2 26
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 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: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

11 Experts available now in Live!

Get 1:1 Help Now