Solved

Component based on TGraphicControl

Posted on 2002-06-27
8
464 Views
Last Modified: 2010-04-04
I wrote a small component based on TGraphicControl. For some reason however, it receives messages of the entire parent form, even if you click outside the control itself. What can I do about that? Should I base my component on another ancestor type? I considered using TWinControl, but this doesn't have a Canvas property, and I haven't got a clue on how to draw/paint a control without Canvas.
0
Comment
Question by:herr_apfelschnitt
8 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 200 total points
ID: 7115179
See http://www.experts-exchange.com/delphi/Q_20317124.html

I just posted an ewxample of how to draw on a control w/o access to it's canvas.


Good luck!!


BTW, as a rule, I would suggest NOT using TGRaphicControl for a base class of any component that you're going to want to handle messages for, since you need an HWND (handle to a window) to process messages and TGraphicControl doesn't have one. Food for thought.


GL

0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115191
Thx, i'll try it. I'll be gone for the weekend, so you'll get your points next week if it works.

Thanks again

herr_apfelschnitt
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115194
Thx, i'll try it. I'll be gone for the weekend, so you'll get your points next week if it works.

Thanks again

herr_apfelschnitt
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7115305
You could use TCustomControl as the base class.
It will of course depend on what you want to do.
What's your question, anyway?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Expert Comment

by:Slick812
ID: 7115433
you say
" it receives messages of the entire parent form, even if you click outside the control itself. What can I do about that?"

the TGraphic Control components I have made only get the "OnClick" OnMouseMove ect message events if the Click, Mouse move, ect. happends INSIDE the control , UNLESS you have done something to confuse the fake message events (they are fake messages because it is NOT a window control). Did you do something to get the parents onClick events?
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115737
My question is:
I'm trying to create alternatives for TCheckBox, TEdit, TButton... All the usual GUI components... What would be the best class to derive these from? DrDelphi already explained how to draw on controls without Canvas property. I still need to try it though, and I won't be any where near a computer this weekend, so I'll have to do that next week.

I think this may be because of my older version of Delphi, but TGraphicControl doesn't seem to be able to handle events (no OnClick, OnMouseMove ... properties).
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7115791
> What would be the best class to derive these from?
Probably TCustomControl which provides a base class for windowed controls (with a window handle).
The window handle is a must if you need keyboard focus (tabstop) for the control.
TCustomControl also provides a Canvas property.

> because of my older version of Delphi
It seems I have to ask this: What version of Delphi are you using?

> TGraphicControl doesn't seem to be able to handle events (no OnClick, OnMouseMove ... properties).
OnClick, OnMouseMove are declared in TControl already, so TGraphicControl does have them; they're just not published.

Anyway, because of the keyboard focus you should probably derive from TCustomControl.

Another option would be to use the TCustomXXX classes from StdCtrls: TCustomEdit for edit, TCustomCheckBox for checkbox etc. In this case, you'd need to override CreateParams so that the control does not create the underlying Windows standard control (see CreateSubClass).

These TCustomXXX classes implement their properties by sending appropriate messages to their window handle. Therefore you'd need to write the messages handlers, reimplementing the standard window controls.

For example, TCustomEdit.SetReadOnly(Value: Boolean) (setter for ReadOnly property) is implemented with SendMessage(Handle, EM_SETREADONLY, Ord(Value), 0);
This method is private so you cannot change it; what you can do is write your own message handler for EM_SETREADONLY to emulate behaviour of standard edit control.

HTH
TOndrej
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7130489
Thanks to everyone else, too!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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: …

759 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