Article View: borland.public.cppbuilder.nativeapi
Article #14805Re: Trapping button message
From: Vladimir Afanasyev
Date: Wed, 30 Jul 2003 12:56
Date: Wed, 30 Jul 2003 12:56
51 lines
2560 bytes
2560 bytes
Hi Mattias,
"Mattias Carleson" <mattias.carleson@home.se> wrote:
>
>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
I am not sure that understand you, try follow code,
may be it helps.
void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
if(Msg.message == WM_LBUTTONDOWN)
{
TPoint click=Form1->ScreenToClient(Msg.pt);
TControl* cntrl=Form1->ControlAtPos(click,False,False);
if(!cntrl)return;
if(SpeedButton1 == dynamic_cast<TSpeedButton*>(cntrl))ShowMessage("Button event catched!");
}
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->OnMessage = AppMessage;
}
I hope it explains also how detect what button pressed.
Vladimir.
Technical Details
Message-ID:
<3f27c07b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<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 06:05:09 PST From: "Vladimir Afanasyev" <avv@systema.kiev.ua> Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua> Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua> Subject: Re: Trapping button message Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 212.82.216.226 212.82.216.226 X-Forwarded-For: 192.168.0.147 References: <3f26ea7c$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3f27c07b$1@newsgroups.borland.com> Date: 30 Jul 2003 05:56:27 -0700 X-Trace: newsgroups.borland.com 1059569787 207.105.83.65 (30 Jul 2003 05:56:27 -0700) Lines: 51 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail