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