<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html;charset=ISO-8859-1>
<META content="MSHTML 6.00.2900.2668" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Perhaps I should add TWinControl to the class
defination. The control is based on another control called TACSControl
which I can't change, so I believe I can do this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>TMyControl = class(TACSControl,
TWinControl);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Would my object then receive all messages sent to
the application that was not handled somewhere else?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Cheers,<BR>Ross.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=KyleyHarris@gmail.com href="mailto:KyleyHarris@gmail.com">Kyley
Harris</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=delphi@ns3.123.co.nz
href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group - Delphi
List</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, June 28, 2005 2:52
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [Spam] Re: [Spam] Re: [Spam] Re:
[DUG] Intercepting messages in separateunits</DIV>
<DIV><BR></DIV>if SendMessage is being used, then only the Handle that is sent
the message will receive it. If you delve into the VCL you will notice how
TForms and TApplication propagate messages to all their TWincontrol
children. I really cant help much without knowing the specific context
of this dll and how it binds itself into a windows handle, otherwise I am just
speculating on nothing.<BR><BR>regards<BR> K<BR><BR>Ross Levis wrote:
<BLOCKQUOTE cite=mid003b01c57b81$51b23bc0$5100a8c0@levis4 type="cite">
<META content="MSHTML 6.00.2900.2668" name=GENERATOR>
<DIV><FONT face=Arial size=2>I read the following in the help for
TApplicationEvents:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>OnMessage only receives messages
that are posted to the message queue, not those sent directly with the
Windows API SendMessage function</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I believe it is SendMessage that is being
used to communicate with the application. I don't suppose there
are any other options?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Cheers,<BR>Ross.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">-----
Original Message ----- </DIV>
<DIV
style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial"><B>From:</B>
<A title=KyleyHarris@gmail.com href="mailto:KyleyHarris@gmail.com">Kyley
Harris</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B>
<A title=delphi@ns3.123.co.nz href="mailto:delphi@ns3.123.co.nz">NZ
Borland Developers Group - Delphi List</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B>
Tuesday, June 28, 2005 12:32 PM</DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B>
[Spam] Re: [Spam] Re: [DUG] Intercepting messages in separate units</DIV>
<DIV><BR></DIV>Yes. Use the TApplicationEvents object and the OnMessage
event. This captures all messages to the application.<BR><BR>Ross Levis
wrote:
<BLOCKQUOTE cite=mid00ab01c57b78$67121f20$5100a8c0@levis4 type="cite">
<META content="MSHTML 6.00.2900.2668" name=GENERATOR>
<DIV><FONT face=Arial size=2>I found the problem and it's now
working. A silly error. Thanks for your help.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>On a similar subject, </FONT><FONT
face=Arial size=2>I was wondering if it's possible to obtain messages
sent to the Application object handle within a component (separate
unit), without altering any mainform source?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>This DLL can also communicate with other
external applications by entering the Windows class name to search and
obtain an application handle, and I would like to experiment
with that.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Is that possible?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><FONT face=Arial
size=2>Thanks,</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2>Ross.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">-----
Original Message ----- </DIV>
<DIV
style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial"><B>From:</B>
<A title=KyleyHarris@gmail.com
href="mailto:KyleyHarris@gmail.com">Kyley Harris</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B>
<A title=delphi@ns3.123.co.nz href="mailto:delphi@ns3.123.co.nz">NZ
Borland Developers Group - Delphi List</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B>
Tuesday, June 28, 2005 11:27 AM</DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B>
[Spam] Re: [DUG] Intercepting messages in separate units</DIV>
<DIV><BR></DIV>Hi Ross. <BR>How and where are you telling the DLL
which window handle to post its messages to? <BR><BR>is there a dll
call such as SetWindowHandleformessaging(MyInstance.Handle) ? or does
it just happen like magic?<BR><BR>Ross Levis wrote:
<BLOCKQUOTE cite=mid021101c57b18$dad7bb50$5100a8c0@levis4
type="cite"><META content="MSHTML 6.00.2900.2668" name=GENERATOR>
<DIV><FONT face=Arial size=2>Hi Kyley</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Yes, I do receive WM_USER
messages. This is how the DLL communicates. As I
mentioned, it works perfectly if I put all the message checking in
the mainform, but it doesn't work in the separate unit, even with
the AllocateHWnd.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Here is all my relevant
code.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>TMyComponent =
class(TComponent)<BR>private<BR> FHandle:
HWnd;<BR> procedure WndProc(var Message:
TMessage);</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>constructor
TMyComponent.Create;<BR>begin<BR> inherited
Create(AOwner);<BR> FHandle :=
AllocateHWnd(WndProc);<BR>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>destructor
TMyComponent.Destroy;<BR>begin<BR>
DeallocateHWnd(FHandle);<BR> inherited
Destroy;<BR>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>procedure
TMyComponent.WndProc(var Message: TMessage);<BR>begin<BR> with
Message do<BR> if Msg = WM_USER
then<BR> begin</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2> Result
:= lparam + wparam //(for example)</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2> end</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2> else Result :=
DefWindowProc(FHandle, Msg, wParam, lParam);<BR>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I get a couple messages when
the program loads but I never get Msg = WM_USER.</FONT></DIV>
<DIV><FONT face=Arial size=2>Do you see any problems with this
code?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>The following code,
however, when placed in the mainform does detect WM_USER
messages.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>TForm1 =
class(TForm)<BR> ...</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2> procedure
WMUSER(var Message: TMessage); message WM_USER;</FONT></DIV>
<DIV><FONT face=Arial color=#000080 size=2>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial color=#000080 size=2>procedure
TForm1.WMUSER(var Message: TMessage);<BR>begin<BR> with
Message do<BR> if Msg = WM_USER then showmessage('It
Works!');<BR>end;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I've tried different combinations of
the syntax, including the <FONT color=#000080>message
WM_USER;</FONT><FONT color=#000000> bit in the unit but it doesn't
make any difference at all. In fact I still get other messages
when the program starts.</FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks for the help.</FONT></DIV>
<DIV><FONT face=Arial size=2>Ross.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">-----
Original Message ----- </DIV>
<DIV
style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial"><B>From:</B>
<A title=KyleyHarris@gmail.com
href="mailto:KyleyHarris@gmail.com">Kyley Harris</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B>
<A title=delphi@ns3.123.co.nz
href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group -
Delphi List</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B>
Monday, June 27, 2005 10:01 PM</DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B>
[Spam] Re: [DUG] Intercepting messages in separate units</DIV>
<DIV><BR></DIV>Try the wrapper class just incase you have made a
blooper. but it is unlikely that you will ever receive a message
with the ID WM_USER. that is simply an offset to coordinate with
windows messages. eg WM_USERLOGON = WM_USER+1 is an example of a
user defined message.<BR><BR>then <BR>myobject =
class(TObject)<BR> procedure WMUSERLOGON(var
msg:TMessage);message WM_USERLOGON; <BR>end;<BR><BR>the above
procedure will only ever receive that one message. You need to
know exactly what messages you are expecting from the
dll.<BR><BR>if you use my wrapper, and attached an instance of the
above object to message handler it will route the messages to that
instance..<BR><BR>Ross Levis wrote:
<BLOCKQUOTE cite=mid019b01c57af5$e31e7f10$5100a8c0@levis4
type="cite">
<META content="MSHTML 6.00.2900.2668" name=GENERATOR>
<DIV><FONT face=Arial size=2>Thanks for that Kyley. I
managed to implement AllocateHWnd etc, and everything appears
correct and logical. It's picking up some Windows messages
but not the WM_USER messages being sent. WM_USER is
message number 1024. I'm getting Message.Msg = 28 and
that's about it.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I tried the same code in the
mainform as a test and this worked but only after I specified
the following:</FONT></DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>procedure MyMessage(var Message:
TMessage); message WM_USER;</FONT></DIV>
<DIV> </DIV></FONT></DIV>
<DIV><FONT face=Arial size=2>If I leave off "message WM_USER",
then nothing gets through to the procedure in the mainform at
all.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I tried this in the unit and it
doesn't make any difference. Message 28 is still getting
to the procedure and no 1024.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>You can tell I'm no expert when it
comes to this. Do I need to use your fancy looking wrapper
class?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I must be missing
something.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks,</FONT></DIV>
<DIV><FONT face=Arial size=2>Ross.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">-----
Original Message ----- </DIV>
<DIV
style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial"><B>From:</B>
<A title=KyleyHarris@gmail.com
href="mailto:KyleyHarris@gmail.com">Kyley Harris</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B>
<A title=delphi@ns3.123.co.nz
href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group
- Delphi List</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B>
Monday, June 27, 2005 7:13 PM</DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B>
[Spam] Re: [DUG] Intercepting messages in separate units</DIV>
<DIV><BR></DIV>in the forms unit<BR><BR>function
AllocateHWnd(Method: TWndMethod): HWND; deprecated; {
moved to Classes.pas }<BR>{$EXTERNALSYM
AllocateHWnd}<BR>procedure DeallocateHWnd(Wnd:
HWND);
deprecated; { moved to Classes.pas }<BR><BR><BR>read the
help will sort you out just fine<BR><BR>Ross Levis wrote:
<BLOCKQUOTE cite=mid014401c57ae7$48177ca0$5100a8c0@levis4
type="cite">
<META content="MSHTML 6.00.2900.2668" name=GENERATOR>
<STYLE></STYLE>
<DIV><FONT face=Arial size=2>I'm writing a component which
communicates with a 3rd party DLL using WM_USER
messages. After loading the DLL, I need to
tell the DLL the handle to send user messages back to,
so my unit can intercept them, but I don't know where to get
a handle from. I know how to do it in the mainform of
a program but not in a separate unit. The messages
sent to the mainform do not appear to reach my
unit.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>What do I need to do to make
this happen?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><FONT
color=#000000>Thanks,</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT
color=#000000>Ross.</FONT></FONT></DIV><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
Delphi mailing list
<A class=moz-txt-link-abbreviated href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A>
<A class=moz-txt-link-freetext href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A>
</PRE></BLOCKQUOTE>
<HR>
_______________________________________________<BR>Delphi
mailing list<BR><A class=moz-txt-link-abbreviated
href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A><BR><A
class=moz-txt-link-freetext
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A><BR></BLOCKQUOTE><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
Delphi mailing list
<A class=moz-txt-link-abbreviated href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A>
<A class=moz-txt-link-freetext href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A>
</PRE></BLOCKQUOTE>
<HR>
_______________________________________________<BR>Delphi mailing
list<BR><A class=moz-txt-link-abbreviated
href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A><BR><A
class=moz-txt-link-freetext
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A><BR></BLOCKQUOTE><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
Delphi mailing list
<A class=moz-txt-link-abbreviated href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A>
<A class=moz-txt-link-freetext href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A>
</PRE></BLOCKQUOTE>
<HR>
_______________________________________________<BR>Delphi mailing
list<BR><A class=moz-txt-link-abbreviated
href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A><BR><A
class=moz-txt-link-freetext
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A><BR></BLOCKQUOTE><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
Delphi mailing list
<A class=moz-txt-link-abbreviated href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A>
<A class=moz-txt-link-freetext href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A>
</PRE></BLOCKQUOTE>
<P></P>
<HR>
_______________________________________________<BR>Delphi mailing
list<BR><A class=moz-txt-link-abbreviated
href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A><BR><A
class=moz-txt-link-freetext
href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A><BR></BLOCKQUOTE><PRE wrap=""><HR width="90%" SIZE=4>
_______________________________________________
Delphi mailing list
<A class=moz-txt-link-abbreviated href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A>
<A class=moz-txt-link-freetext href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A>
</PRE></BLOCKQUOTE>
<P>
<HR>
<P></P>_______________________________________________<BR>Delphi mailing
list<BR>Delphi@ns3.123.co.nz<BR>http://ns3.123.co.nz/mailman/listinfo/delphi<BR></BLOCKQUOTE></BODY></HTML>