Board index » cppbuilder » How to asign an OnClick event to a TBevel ??

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
 
 

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.
[...]
Quote
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
 

Re:How to asign an OnClick event to a TBevel ??

"Ramy" < XXXX@XXXXX.COM >wrote in message
Quote
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
514 = WM_LBUTTONUP
Gambit
 

{smallsort}

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
>means that the user let go of the mouse button, how do i find
>now which event it is

514 = WM_LBUTTONUP

Gambit
 

Re:How to asign an OnClick event to a TBevel ??

"Ramy" < XXXX@XXXXX.COM >wrote:
Quote
I think that i have found a good solution for my problem,
what do you think about it?
I didn't examine the code's 'OnClick' effectiveness but I saw
that your OnMouseEnter/Leave needs some work because it's not
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
 

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

[...]

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
 

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
Corret. Actually you could reformat the block even more (see
below). I always initially build blocks as in my first example
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
 

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

"Ramy" < XXXX@XXXXX.COM >wrote:
>[...] By the way can i delete from this code

Corret. Actually you could reformat the block even more (see
below). I always initially build blocks as in my first example
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