• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

Component based on TGraphicControl

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
herr_apfelschnitt
Asked:
herr_apfelschnitt
1 Solution
 
DrDelphiCommented:
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
 
herr_apfelschnittAuthor Commented:
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
 
herr_apfelschnittAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
TOndrejCommented:
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
 
Slick812Commented:
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
 
herr_apfelschnittAuthor Commented:
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
 
TOndrejCommented:
> 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
 
herr_apfelschnittAuthor Commented:
Thanks to everyone else, too!
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now