Board index » delphi » how can I handle child-window button clicks?

how can I handle child-window button clicks?

Can anyone help me with this little problem I've got? I expect there's a
trivial solution, but I can't find one.

The situation:
I'm reading in lots of strings from a (potentially infinite) file, and then
creating a childwindow. Each of the strings becomes a TRadioButton, TEdit or
TButton object. So, potentially, this child window (a TConfigWindow object - a
descendent of TWindow) can contain 1000s of clickable icons of various sorts.

The problem:
How can I get ObjectWindows to tell me when someone clicks on a button??
I know it's easy if there are a fixed number of icons; i can define several
message-response methods to cope with them... eg.

TConfigWindow = object(TWindow)
                ...
                procedure IDCancel(var Msg: TMessage); virtual id_first+id_OK;
                end;

and then the IDCancel procedure would be called when someone clicks on OK.
But, using this technique, I'd have to define an infinite number of methods to
solve my problem. So, what I'm looking for is a SINGLE method I can override
that gets called each time someone clicks on a button, and then I can decode
the button's ID number to determine what action to take.

So... is there such a method?? If not, how could I solve my problem???

Thanks
Phil

 

Re:how can I handle child-window button clicks?


In article <3t9u0j$...@news.ox.ac.uk>,
philip.geo...@christ-church.oxford.ac.uk says...

Quote
>I'm reading in lots of strings, ... and then
>creating a childwindow. Each of the strings becomes a TRadioButton, TEdi
>t or
>TButton object...
>How can I get ObjectWindows to tell me when someone clicks on a button?

I don't know if this will help, but you might try capturing the Msg
record (Msg: TMessage) with something like : id_First + WMLButtonDown.
This should log everytime someone clicks on the child window. Then you
could seperate out Msg.lParamLo (the x coordinate of the clicked point)
and Msg.lParamHi (the y coordinate of the clicked point) and from the
(x,y) location of the mouse click determine if a button was clicked, and
which one.
Can't think of any other generic method to solve this problem.

--
    77   77    'Omnibus absentibus, date ut viderais mortuus' John Banta
---(_______).> 'When all else fails, roll over and play dead' Bantaville

Re:how can I handle child-window button clicks?


In article <3t9u0j$...@news.ox.ac.uk>, <philip.geo...@christ-church.oxford.ac.uk>
writes:

Quote
> The situation:
> I'm reading in lots of strings from a (potentially infinite) file, and then
> creating a childwindow. Each of the strings becomes a TRadioButton, TEdit or
> TButton object. So, potentially, this child window (a TConfigWindow object - a
> descendent of TWindow) can contain 1000s of clickable icons of various sorts.

> The problem:
> How can I get ObjectWindows to tell me when someone clicks on a button??
> I know it's easy if there are a fixed number of icons; i can define several
> message-response methods to cope with them... eg.

> TConfigWindow = object(TWindow)
>                 ...
>                 procedure IDCancel(var Msg: TMessage); virtual id_first+id_OK;
>                 end;

> and then the IDCancel procedure would be called when someone clicks on OK.
> But, using this technique, I'd have to define an infinite number of methods to
> solve my problem. So, what I'm looking for is a SINGLE method I can override
> that gets called each time someone clicks on a button, and then I can decode
> the button's ID number to determine what action to take.

> So... is there such a method?? If not, how could I solve my problem???

Here my method :
================

I OVERWRITE the DefWndProc method (even if Borland says :"(Override: Never)" !!!).

Example :
  TNewWindow = object(TWindow)
               ...
               procedure   DefWndProc(var Msg: TMessage); virtual;
               ...
               end;
..
procedure TNewWindow.DefWndProc(var Msg: TMessage);
begin
if msg.Message=WM_COMMAND then
   begin
   case msg.wParam of
      ID_OK     : MyMethodOK;
      ID_CANCEL : MyMethodCancel;
      ID_xxx    : MyMethodxxx;
      ....
      else      inherited DefWndProc(Msg);
      end;
   end
else inherited DefWndProc(Msg);
end;

May the Force be with You !
==========================================================================
Jean-Claude BELLAMY         | Electricite de France - Etudes et Recherches
Phone : (33.1)47.65.50.59   | 1, avenue du General de Gaulle
Fax   : (33.1)47.65.30.01   | 92141 CLAMART CEDEX -  F R A N C E
URL   : http://www.edf.fr
Jean-Claude.Bell...@der.edf.fr

Re:how can I handle child-window button clicks?


Quote
philip.geo...@christ-church.oxford.ac.uk (Phil George) wrote:

> Can anyone help me with this little problem I've got? I expect there's a
> trivial solution, but I can't find one.

> The situation:
> I'm reading in lots of strings from a (potentially infinite) file, and then
> creating a childwindow. Each of the strings becomes a TRadioButton, TEdit or
> TButton object. So, potentially, this child window (a TConfigWindow object - a
> descendent of TWindow) can contain 1000s of clickable icons of various sorts.

> The problem:
> How can I get ObjectWindows to tell me when someone clicks on a button??
> I know it's easy if there are a fixed number of icons; i can define several
> message-response methods to cope with them... eg.

> TConfigWindow = object(TWindow)
>                 ...
>                 procedure IDCancel(var Msg: TMessage); virtual id_first+id_OK;
>                 end;

> and then the IDCancel procedure would be called when someone clicks on OK.
> But, using this technique, I'd have to define an infinite number of methods to
> solve my problem. So, what I'm looking for is a SINGLE method I can override
> that gets called each time someone clicks on a button, and then I can decode
> the button's ID number to determine what action to take.

> So... is there such a method?? If not, how could I solve my problem???

> Thanks
> Phil

Hi..
Capture the messages in DefCommandProc, or DefChildProc.
Determine from the message the window, and/or Id, and use
case btnId of
..
end

Hope this helps..
  James :-)

Other Threads