graber
asked on
Responding to a new componet's OnMouseUP
Hey Guys
I am attempting to create a TPanel that responds to a mouse up event to change it's background, Text color and track it's current state. Below is the current state of the component. The component is responding to WM_LBUTTONUP but the component continues to capture the same message even when it not clicking it. Any input would gladly recieved
I am attempting to create a TPanel that responds to a mouse up event to change it's background, Text color and track it's current state. Below is the current state of the component. The component is responding to WM_LBUTTONUP but the component continues to capture the same message even when it not clicking it. Any input would gladly recieved
//----------------------------------------------------------------------
#ifndef CPnlSWH
#define CPnlSWH
//----------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
#include <sysmac.h>
//----------------------------------------------------------------------
class PACKAGE TPnlSW : public TCustomPanel
{
private:
TColor FClrBckOn;
TColor FClrBckOff;
TColor FClrTxtOn;
TColor FClrTxtOff;
TCaption FSWCaption;
bool FbOn;
void __fastcall SetClrBckOn(TColor value);
TColor __fastcall GetClrBckOn();
void __fastcall SetClrBckOff(TColor value);
TColor __fastcall GetClrBckOff();
void __fastcall SetClrTxtOn(TColor value);
TColor __fastcall GetClrTxtOn();
void __fastcall SetClrTxtOff(TColor value);
TColor __fastcall GetClrTxtOff();
void __fastcall SetbOn(bool value);
bool __fastcall GetbOn();
void __fastcall SetText(TCaption value);
TCaption __fastcall GetText();
__property Caption;
__property Color = {default = clBlack};
__property Font;
protected:
void SWReset();
void _fastcall WMMouse(Messages::TWMMouse & atMouse);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_LBUTTONUP, TWMMouse, WMMouse)
END_MESSAGE_MAP(TCustomPanel)
public:
__fastcall TPnlSW(TComponent* Owner);
__published:
__property BevelInner = {default = bvLowered};
__property BevelOuter = {default = bvLowered};
__property Enabled = {default = 1};
__property FullRepaint = {default = 1};
__property Locked = {default = 0};
__property ParentShowHint = {default = 1};
__property PopupMenu;
__property ShowHint;
__property TabOrder = {default = -1};
__property TabStop = {default = 0};
__property Visible = {default = 1};
__property TColor ClrBckOn = { read = GetClrBckOn, write = SetClrBckOn, default = clLime };
__property TColor ClrBckOff = { read = GetClrBckOff, write = SetClrBckOff, default = clBlack };
__property TColor ClrTxtOn = { read=GetClrTxtOn, write = SetClrTxtOn, default = clBlack };
__property TColor ClrTxtOff = { read = GetClrTxtOff, write = SetClrTxtOff, default = clLime };
__property bool bOn = { read = GetbOn, write = SetbOn, default = false };
__property TCaption SWCaption = {read = GetText, write = SetText};
};
//----------------------------------------------------------------------
#endif
//----------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CPnlSW.h"
#pragma package(smart_init)
//----------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TPnlSW *)
{
new TPnlSW(NULL);
}
//---------------------------------------------------------------------------
//Note the constructor is call twice... during design time and runtime
__fastcall TPnlSW::TPnlSW(TComponent* Owner)
:TCustomPanel(Owner)
{
FClrBckOn = clLime; ClrBckOn = clLime;
FClrBckOff = clBlack; ClrBckOff = clBlack;
FClrTxtOn = clBlack; ClrTxtOn = clBlack;
FClrTxtOff = clLime; FClrTxtOff = clLime;
FbOn = false; bOn = false;
BevelInner = bvLowered;
BevelOuter = bvLowered;
Height = 17;
Width = 17;
FSWCaption = "00";
Caption = "00";
SWReset();
}
//---------------------------------------------------------------------------
namespace Cpnlsw
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TPnlSW)};
RegisterComponents("Testing", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TPnlSW::SetClrBckOn(TColor value)
{
if(FClrBckOn != value)
{
FClrBckOn = value;
// if the switch is currently on and its backgroud color changes then update
// the the UI showing its state
if(FbOn)
{
Color = FClrBckOn;
Invalidate();
}
}
}
TColor __fastcall TPnlSW::GetClrBckOn()
{
return FClrBckOn;
}
void __fastcall TPnlSW::SetClrBckOff(TColor value)
{
if(FClrBckOff != value)
{
FClrBckOff = value;
//if the switch is currently off and its background color has changed then update
// the the UI showing its state
if(!FbOn)
{
Color = FClrBckOff;
Invalidate();
}
}
}
TColor __fastcall TPnlSW::GetClrBckOff()
{
return FClrBckOff;
}
void __fastcall TPnlSW::SetClrTxtOn(TColor value)
{
if(FClrTxtOn != value)
{
FClrTxtOn = value;
// if the switch is "On" and its' foreground or text color has changed then update
// the the UI showing its state
if(FbOn)
{
Font->Color = FClrTxtOn;
Invalidate();
}
}
}
TColor __fastcall TPnlSW::GetClrTxtOn()
{
return FClrTxtOn;
}
void __fastcall TPnlSW::SetClrTxtOff(TColor value)
{
if(FClrTxtOff != value)
{
FClrTxtOff = value;
// if the switch is "Off" and its' foreground or text color has changed then update
// the the UI showing its state
if(!FbOn)
{
Font->Color = FClrTxtOff;
Invalidate();
}
}
}
TColor __fastcall TPnlSW::GetClrTxtOff()
{
return FClrTxtOff;
}
void __fastcall TPnlSW::SetbOn(bool value)
{
if(FbOn != value)
{
FbOn = value;
if(FbOn)
{
Font->Color = FClrTxtOn;
Color = FClrBckOn;
}
else
{
Font->Color = FClrTxtOff;
Color = FClrBckOff;
}
}
}
bool __fastcall TPnlSW::GetbOn()
{
return FbOn;
}
void TPnlSW::SWReset()
{
FbOn = false;
if(FbOn)
{
Font->Color = FClrTxtOn;
Color = FClrBckOn;
}
else
{
Font->Color = FClrTxtOff;
Color = FClrBckOff;
}
}
void __fastcall TPnlSW::SetText(TCaption value)
{
if(value.Length() != 0 && value != Caption)
{
Caption = value;
Invalidate();
}
}
TCaption __fastcall TPnlSW::GetText()
{
TCaption c = "";
if(FSWCaption.Length() != 0)
{
c = Caption;
}
return c;
}
void _fastcall TPnlSW::WMMouse(Messages::TWMMouse & taMouse)
{
//currently this is not closing the loop. Once the control has been clicked any further clicks
//outside the client area (ie the parent control) act as if the click was inside the control.
if(taMouse.Msg == WM_LBUTTONUP)
{
if(bOn)
{
this->SetbOn(false);
}
else
{
this->SetbOn(true);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.