Board index » cppbuilder » How to asign an OnClick event to a TBevel ??
Ramy
![]() CBuilder Developer |
Ramy
![]() CBuilder Developer |
How to asign an OnClick event to a TBevel ??2004-06-22 09:16:02 PM cppbuilder93 Hi, I'm creating new 'button' from a class based on a TPanel, on this panel i have a Bevel which is part of the class and it's size is exactly the size of the Panel. The problem is that TBevel doesn't have an 'OnClick' event, so i can't assign an 'OnClick' function to it, then how exactly do i solve this problem? I need that when the user click the bevel an OnClick function will be fires just like if it was a TImage with an 'OnClick' event. Thanks! Ramy |
Ramy
![]() CBuilder Developer |
2004-06-22 10:35:17 PM
Re:How to asign an OnClick event to a TBevel ??
Hi again,
I think that i have found a good solution for my problem, what do you think about it? is there any better way to do that? This is what i did - void __fastcall TBaseButton::WndProc( TMessage &Message ) { if( Message.Msg == CM_MOUSEENTER ) { MouseInImage = true; OnMouseEnter(); } else if( Message.Msg == CM_MOUSELEAVE ) { MouseInImage = false; OnMouseLeave(); } else { if ( ( Message.Msg == 514 ) && MouseInImage ) { MyOnClickFunction(); // My OnClick Event !!! } } From try-and-check i have found that Message.Msg == 514 means that the user let go of the mouse button, how do i find now which event it is so that i can write something nice like - if ( ( Message.Msg == CM_MOUSEBUTTONUP) && MouseInImage ) { } instead of '== 514' ? Thanks! Ramy. [...] QuoteI'm creating new 'button' from a class based on a TPanel, on |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-06-23 01:18:13 AM
Re:How to asign an OnClick event to a TBevel ??
"Ramy" < XXXX@XXXXX.COM >wrote in message
QuoteFrom try-and-check i have found that Message.Msg == 514 {smallsort} |
Ramy
![]() CBuilder Developer |
2004-06-23 01:52:22 AM
Re:How to asign an OnClick event to a TBevel ??
Thanks very much Gambit!
So is my method good anough? isn't there a better way to create OnClick event for a TBevel? I searched the word "CM_MOUSELEAVE" and then "WM_LBUTTONUP" all over the PC in all the H files in order to see the full list of this defines, but i couldn't find it, in which file can i see this list? Thanks. Ramy Quote>From try-and-check i have found that Message.Msg == 514 |
JD
![]() CBuilder Developer |
2004-06-24 05:27:19 AM
Re:How to asign an OnClick event to a TBevel ??
"Ramy" < XXXX@XXXXX.COM >wrote:
QuoteI think that i have found a good solution for my problem, 100%. As it happens, when you enter or leave the image, those messages are sent through the Parent control - the panel. If the user moves just into the panel, the panel is sent the CM_MOUSEENTER message. If the user next moves into the image, the panel is again sent the CM_MOUSEENTER message that it passes on to the image. This also happens with CM_MOUSELEAVE. If the user leaves the image but stays inside the panel, the panel will get a CM_MOUSELEAVE message. This complicates things a bit but it's a good thing because you need a central location to correctly handle this event for both controls when one lives inside the other: void __fastcall TBaseButton::WndProc( TMessage &Message ) { static bool MouseWasInImage = false; if( Message.Msg == CM_MOUSEENTER || Message.Msg == CM_MOUSELEAVE ) { TImage* pImage = dynamic_cast<TImage*>( reinterpret_cast<TControl*>(Message.LParam) ); if( Message.Msg == CM_MOUSEENTER ) { if( pImage ) { // the mouse just entered the image MouseWasInImage = true; } else // The mouse just entered the panel { if( !MouseWasInImage ) { // do MouseOnEnter stuff } else { // do nothing because mouse entered panel from the image } } } else // CM_MOUSELEAVE { if( !pImage ) // mouse left the panel { // check to see if the mouse left the panel into the image RECT Rect; POINT Point; ::GetWindowRect( Handle, &Rect ); ::GetCursorPos( &Point ); if( ! ::PtInRect(&Rect, Point) ) { MouseWasInImage = false; // do OnMouseLeave stuff } else { // do nothing because the mouse left the panel into the image } } else { // do nothing because the mouse just left the image } } } inherited::WndProc( Message ); } ~ JD |
Ramy
![]() CBuilder Developer |
2004-06-24 10:12:25 PM
Re:How to asign an OnClick event to a TBevel ??
Thanks JD, i like your solution.
By the way can i delete from this code all the - [...] else { // do nothing because the mouse just left the image } parts? they have no use, right? I'll use your method, thanks again, Ramy "JD" < XXXX@XXXXX.COM >wrote: Quote
|
JD
![]() CBuilder Developer |
2004-06-25 03:51:20 AM
Re:How to asign an OnClick event to a TBevel ??
"Ramy" < XXXX@XXXXX.COM >wrote:
Quote[...] By the way can i delete from this code and modify it later. I left it that way just for clearity. void __fastcall TBaseButton::WndProc( TMessage &Message ) { static bool MouseWasInImage = false; if( Message.Msg == CM_MOUSEENTER || Message.Msg == CM_MOUSELEAVE ) { TImage* pImage = dynamic_cast<TImage*>( reinterpret_cast<TControl*>(Message.LParam) ); if( Message.Msg == CM_MOUSEENTER ) { if( pImage ) MouseWasInImage = true; else if( !MouseWasInImage ) { // do MouseOnEnter stuff } } else if( !pImage ) { RECT Rect; POINT Point; ::GetWindowRect( Handle, &Rect ); ::GetCursorPos( &Point ); if( ! ::PtInRect(&Rect, Point) ) { MouseWasInImage = false; // do OnMouseLeave stuff } } } inherited::WndProc( Message ); } ~ JD |
Ramy
![]() CBuilder Developer |
2004-06-27 09:26:28 PM
Re:How to asign an OnClick event to a TBevel ??
Thanks JD your new code is much clearer and i'm using it, also
your solution for my ToolBar problem works perfectly :-) Thanks very much, Ramy "JD" < XXXX@XXXXX.COM >wrote: Quote
|