Solved

Component based on TGraphicControl

Posted on 2002-06-27
8
482 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 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

718 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