Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to implement an OnMouseDown event for the buttons of a TRadioGroup Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have created a decendant of TRadioGroup called TSuperRadioGroup. With this new 
control, I have surfaced the onmousedown event. But the event is only triggered 
when the mouse goes down on the border or caption of the Group, not the Radio 
Buttons themselves.

Answer:

The solution I use is to register a window procedure for the radiobuttons. You can 
trap the Windows messages there.

1   procedure TSuperRadioGroup.RegisterWndProc;
2   var
3     BtnHnd: hWnd;
4     ItrBtn: Integer;
5   begin
6     inherited;
7     HasWndProc := True;
8     BtnHnd := GetWindow(Handle, GW_CHILD);
9     ItrBtn := 0;
10    while BtnHnd > 0 do
11    begin
12      if GetWindowLong(BtnHnd, GWL_USERDATA) <> 0 then
13        raise Exception.Create('Userdata may not be used');
14      ButtonHandle[ItrBtn] := BtnHnd;
15      OrigWndProc[ItrBtn] := GetWindowLong(BtnHnd, GWL_WNDPROC);
16      SetWindowLong(BtnHnd, GWL_USERDATA, Longint(self));
17      SetWindowLong(BtnHnd, GWL_WNDPROC, Longint(@RadioBtnWndProc));
18      Inc(ItrBtn);
19      BtnHnd := GetWindow(BtnHnd, GW_HWNDNEXT);
20    end;
21  end;
22  
23  {In the RadioBtnWndProc window procedure you can use this code to get at
24   the radiogroup object and the specific button:}
25  
26  Obj := TObject(GetWindowLong(WndHnd, GWL_USERDATA));
27  if Obj is TSuperRadioGroup then
28  begin
29    RadioGrp := TSuperRadioGroup(Obj);
30    for ItrBtn := 0 to RadioGrp.Items.Count - 1 do
31    begin
32      if WndHnd = RadioGrp.ButtonHandle[ItrBtn] then
33      begin
34        OrigWndProc := RadioGrp.OrigWndProc[ItrBtn];
35        break;
36      end;
37    end;
38  end;
39  
40  {If the message is not completely handled, you need to call the 
41  original wndproc at the end of your specialized wndproc:}
42  
43  Result := CallWindowProc(Pointer(OrigWndProc), WndHnd, Msg, WParam, LParam);


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC