🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14807

Re: Trapping button message

#14807
From: Rodolfo Frino
Date: Wed, 30 Jul 2003 14:10
160 lines
5182 bytes
I don't know if I understand what you want to do, but If you have 2 buttons
then you can do this

1).h file

#ifndef WndProcSpeedButtonH
#define WndProcSpeedButtonH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
//--------------------------------------------------------------------------
-
class TUserSpeedButton : public TSpeedButton
{


  public:
   __fastcall TUserSpeedButton(TComponent* Owner): TSpeedButton(Owner)
   {
   }

   __fastcall ~TUserSpeedButton()
   {
   }
   void __fastcall WndProc(Messages::TMessage &MessageUser);
};

class TForm1 : public TForm
{
__published: // IDE-managed Components
        TEdit *Edit1;
        void __fastcall UserSpeedButtonClick(TObject *Sender);

private: // User declarations
public:  // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif

2) cpp file
#include <vcl.h>
#pragma hdrstop

#include "WndProcSpeedButton.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"

TUserSpeedButton* p;
TUserSpeedButton* p2;
TColor OriginalColor;

TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    p = new TUserSpeedButton(this);
    p->Parent = this;
    p->Width = 200;
    p->Height = 100;
    p->Top = 100;
    p->Left = 100;
    p->Caption = "UserSpeedButton";
    p->OnClick = UserSpeedButtonClick;

    p2 = new TUserSpeedButton(this);
    p2->Parent = this;
    p2->Width = 200;
    p2->Height = 100;
    p2->Top = 100;
    p2->Left = 300;
    p2->Caption = "UserSpeedButton 2";
    p2->OnClick = UserSpeedButtonClick;

    OriginalColor = Color;
    Edit1->Text = "";
}
//--------------------------------------------------------------------------
-

void __fastcall TUserSpeedButton::WndProc(Messages::TMessage &Message)
{
// Intercept the two messages: WM_RBUTTONDOWN
// and WM_LBUTTONDOWN and respond doing some
// action

   if (Message.Msg == WM_RBUTTONDOWN)
   {
       //Form1->Edit1->Text = "Right Button Pressed: SB is Flat";
       Flat = true;
       Form1->Color = clPurple;
       Form1->Edit1->Color = clRed;
   }

   if (Message.Msg == WM_LBUTTONDOWN)
   {
       //Form1->Edit1->Text = "Left Button Pressed: SB is not Flat";
       Flat = false;
       Form1->Color = OriginalColor;
       Form1->Edit1->Color = clWhite;
   }

   TSpeedButton::WndProc(Message);
}
//-----------------------------------------------------------------------


void __fastcall TForm1::UserSpeedButtonClick(TObject *Sender)
{
   if (Sender == p)
     ShowMessage("SpeedButton1");

   if (Sender == p2)
     ShowMessage("SpeedButton2");
}


Rodolfo


"Mattias Carleson" <mattias.carleson@home.se> wrote in message
news:3f26ea7c$1@newsgroups.borland.com...
>
> Hi!
> I want to trap the message generated by pressing a TSpeedButton.
> I�ve been trying it in the Application->OnMessage, and I�ve been trying it
by overriding the WndProc method. If Im right it�s the
> WM_COMMAND that should be trapped, but it doesnt seem to work.
> This is what I try to do:
>
> void __fastcall TMainForm::AppMessage(tagMSG &Msg, bool &Handled)
> {
>    if(Msg.message == WM_COMMAND)
>    {
>       if(HIWORD(Msg.wParam=BN_CLICKED))
>       {
>          ShowMessage("Button event catched!");
>       }
> }
>
> My second question is how to know which button object caused
> the message? I know LOWORD(Msg.wParam) should contain the
> identifier and that Msg.lParam contains the handle, but the
> TSpeedButton class and its parents doesnt seem to include any
> varible or function returning any of it.
>
> How should this be done? Thanks for your time.
> /Mattias
Technical Details
Message-ID: <3f27d1bc@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f26ea7c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10cc67,77c37ce9ffa755d1
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-30 07:12:53 PST
From: "Rodolfo Frino" <rodolfofrino@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f26ea7c$1@newsgroups.borland.com>
Subject: Re: Trapping button message
Date: Thu, 31 Jul 2003 00:10:37 +1000
Lines: 162
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 203.206.18.177
Message-ID: <3f27d1bc@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059574204 203.206.18.177 (30 Jul 2003 07:10:04 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail