Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Responding to a new componet's OnMouseUP

Posted on 2008-10-30
1
605 Views
Last Modified: 2013-12-14
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

//----------------------------------------------------------------------
#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);
      }
   }
}

Open in new window

0
Comment
Question by:graber
1 Comment
 
LVL 2

Accepted Solution

by:
graber earned 0 total points
ID: 22870261
WMMouse Message is not completed it's clean up
void _fastcall TPnlSW::WMMouse(Messages::TWMMouse & msgMouse)
{
   //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(msgMouse.Msg == WM_LBUTTONUP)
   {
      if(bOn)
      {
         this->SetbOn(false);
      }
      else
      {
         this->SetbOn(true);
      }
   }
   if(this->ControlStyle.Contains(csCaptureMouse))
   {
      this->MouseCapture = false;
   }
   if(this->ControlState.Contains(csClicked))
   {
      this->ControlState >> csClicked;
      if(PtInRect(this->ClientRect, TPoint(msgMouse.XPos, msgMouse.YPos)))
         this->Click();
   }
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question