?
Solved

Component based on TGraphicControl

Posted on 2002-06-27
8
Medium Priority
?
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 600 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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