🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Trapping button message

#14806
From: Rodolfo Frino
Date: Wed, 30 Jul 2003 14:00
143 lines
4816 bytes
Perhaps you might like to do something like this

1) WndProcSpeedButton.h

#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;

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

1) WndProcSpeedButton.cpp
//...
TUserSpeedButton* p;
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";
    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);
}

Rodolfo



"Mattias Carleson" <mattias.carleson@commentor.se> wrote in message
news:3f27ad3f$1@newsgroups.borland.com...
> Sorry, was a little quick answering. Now it works trapping WM_COMMAND from
> TButton
> and TBitBtn i WndProc. In Application->OnMessage it doesnt work, but never
> mind. But I
> still whant to trap the message when the user clicks a TSpeedButton. The
> TSpeedButton is placed
> in a TToolBar or a TCoolBar, Ive tried both.
>
> > WM_COMMAND only applies to windowed controls, which TSpeedButton is not.
> > What you are attempting to do would apply for TButton or TBitBtn, but
not
> > TSpeedButton.
>
> Ok, so I wrote the following code. It works, almost.
>
> void __fastcall TForm1::WndProc(TMessage& Msg)
> {
>    if(Msg.Msg == WM_LBUTTONDOWN)
>    {
>         ShowMessage("Left mousebtn trapped in WndProc!");
>     }
> }
>
> There is just one problem. When the form shows for the first time,
clicking
> on the speedbutton or the
> toolbar/coolbar doesnt generate any WM_LBUTTONDOWN. First I have to click
> somewhere on
> the mainforms client area. Doing that generates the message, and after
that
> clicking the speedbutton
> does too. What is the logic and how can I make it generate the message at
> once?
>
> A second question. I need to detect which speedbutton generating the
> message. Do I have to use the
> TControl::ClientToScreen() function and compare coordinates?
>
> Thankyou
> /Mattias
>
>
Technical Details
Message-ID: <3f27cf5b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f26ea7c$1@newsgroups.borland.com> <3f26efb2$1@newsgroups.borland.com> <3f27ad3f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,77c37ce9ffa755d1
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-30 07:08:31 PST
From: "Rodolfo Frino" <rodolfofrino@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f26ea7c$1@newsgroups.borland.com> <3f26efb2$1@newsgroups.borland.com> <3f27ad3f$1@newsgroups.borland.com>
Subject: Re: Trapping button message
Date: Thu, 31 Jul 2003 00:00:28 +1000
Lines: 145
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: <3f27cf5b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059573595 203.206.18.177 (30 Jul 2003 06:59:55 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail