We help IT Professionals succeed at work.

SetFocus to own Component

Oli2
Oli2 asked
on
Medium Priority
406 Views
Last Modified: 2010-04-06
I have a Component descending from TGraphicControl.
This does not support the SetFocus procedure.
How can I implement that?

And this is probably connected,
TGraphicControl does not receive WM_MOUSEWHEEL messages,
since they get sent to the Parent Form which handles them, if I remember right. How to implement that?

regards,
Oli
Comment
Watch Question

Commented:
Hi Oli!

A TGraphicControl has no own window handle, that is good and bad at the same time. It saves resources big time, but it makes some things more difficult. Because it has no own window handle, it does not really get messages (though Delphi simulates it), furthermore it does not support focus stuff. You can simulate focus stuff yourself, but it's quite complicated. You will have to check whether your parent has focus or not. If it has, then you also have. If your parent has let's say 4 of your components as childs, then your childs have to work together and share the focus of the parent somehow.

You could probably use SetWindowLong(GWL_WNDPROC) to subclass the parent's window procedure. This way you will probably get WM_MOUSEWHEEL messages and also WM_SETFOCUS messages.

Regards, Madshi.

Commented:
I think Madshi's answer is pretty good - I'll just offer one point of clarification -

A TGraphic doesn't get those messages (or _any_ others) because it's _not_ a window. Essentialy it's only a little bmp drawn on the parent & the parent _pretends_ it's a control.

GL
Mike
Is your control a TGraphicControl because it needs to be transparent?
If not you should consider making it a windowed control. Then you will gain Focus access.

Author

Commented:
Thanks Madshi, I'll try SetWindowLong.
Thanks Mike for the clarification.  ;-)
Robert -> Yes, I want to implement transperency.

regards,
Oli

Author

Commented:
Thanx Madshi!
Works perfect!

:-)

Oli

Explore More ContentExplore courses, solutions, and other research materials related to this topic.