Im overriding Application.OnMessage.
In that, I want to find the form handle for any message handle which goes
through.
How to find the form handle from any handle
By handle, I mean Windows message handle for a control or any window object.
GetParentForm(FindControl(Msg.Hwnd)) - doesnt seems to work for
a combobox control
regards
Venu
if (screen.activeform<>nil) then
begin
getclassname(screen.activeform.handle,@tmpcstr[0],cClassNameLength);
if strpas(@tmpcstr[0])='Tnewappointmentform' then
begin
if
msg.hwnd=Tnewappointmentform(screen.activeform).timeproclistbox.Handle then
begin
case msg.message of
wm_mousemove,wm_lbuttondown,wm_lbuttonup,wm_rbuttondown,wm_rbuttonup:
begin
handled:=true;
end;
end;
// debugmsg('Listbox message - '+textwm_message(msg.message));
end;
end;
end;
Russ
"Venu" <ve...@hotmail.com> wrote in message
news:4591...@newsgroups.borland.com...
Try calling GetAncestor(Msg.HWnd, ga_Root). That will get you the root
parent window, which should be the handle of the form. Call FindControl
on that handle to get a reference to the form object.
> By handle, I mean Windows message handle for a control or any window object.
>
> GetParentForm(FindControl(Msg.Hwnd)) - doesnt seems to work for
> a combobox control
Does it work for everything else? Combo boxes are composed of at least
two windows -- an edit box and a list box. I think Delphi only
instruments the main container window handle, not the subwindows, which
could explain why FindControl doesn't work.
--
Rob
An easier way of writing all of the above lines is this:
if Screen.ActiveForm is TNewAppointmentForm then begin
Your method forces Delphi to construct and destroy an AnsiString for
every message that comes through your program. You can at least avoid
the string allocation by calling StrComp to compare the character array
instead of calling StrPas.
> if
> msg.hwnd=Tnewappointmentform(screen.activeform).timeproclistbox.Handle then
> begin
> case msg.message of
> wm_mousemove,wm_lbuttondown,wm_lbuttonup,wm_rbuttondown,wm_rbuttonup:
> begin
> handled:=true;
> end;
> end;
For such a focussed use, it may be more straightforward to just set the
WndProc property of the list box. That way, you're only running custom
code for one control, instead of checking the active form's ancestry for
*every* message that ever arrives for your program.
--
Rob
> In that, I want to find the form handle for any message handle
> which goes through.
The MSG structure contains an HWND as a member. Pass that HWND to
FindControl(), which will return a TWinControl pointer. You can then use
the 'is' operator to see if that is a TForm, or pass it to GetParentForm()
if needed.
> GetParentForm(FindControl(Msg.Hwnd)) - doesnt seems to work
> for a combobox control
A ComboBox is actually made up of two inner controls - an Edit and a
ListBox. Most of the messages you receive for a ComboBox are actually meant
for those inner controls, which have no ties to the VCL at all. In that
situation, try using the Win32 API GetParent() function to get the HWND of
the ComboBox container itself. Then you should be able to use FindControl()
and GetParentForm() normally.
Gambit
I am an old win api programmer and old habits die hard. That code has been
in there a long time I'll look it over.
Russ
"Rob Kennedy" <m...@privacy.net> wrote in message
news:45916c4f$1...@newsgroups.borland.com...