<!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>I found the problem and it's now working.&nbsp; A 
silly error.&nbsp; Thanks for your help.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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><FONT face=Arial size=2></FONT>&nbsp;</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&nbsp;an 
application&nbsp;handle, and I would like to experiment with that.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Is that possible?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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: #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 11:27 
  AM</DIV>
  <DIV style="FONT: 10pt arial"><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>&nbsp;</DIV>
    <DIV><FONT face=Arial size=2>Yes, I do receive WM_USER messages.&nbsp; This 
    is how the DLL communicates.&nbsp; 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>&nbsp;</DIV>
    <DIV><FONT face=Arial size=2>Here is all my relevant code.</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>TMyComponent = 
    class(TComponent)<BR>private<BR>&nbsp;&nbsp;FHandle: 
    HWnd;<BR>&nbsp;&nbsp;procedure WndProc(var Message: TMessage);</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>end;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>constructor 
    TMyComponent.Create;<BR>begin<BR>&nbsp; inherited Create(AOwner);<BR>&nbsp; 
    FHandle := AllocateHWnd(WndProc);<BR>end;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>destructor 
    TMyComponent.Destroy;<BR>begin<BR>&nbsp; DeallocateHWnd(FHandle);<BR>&nbsp; 
    inherited Destroy;<BR>end;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>procedure 
    TMyComponent.WndProc(var Message: TMessage);<BR>begin<BR>&nbsp; with Message 
    do<BR>&nbsp; if Msg = WM_USER then<BR>&nbsp;&nbsp;begin</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>&nbsp;&nbsp;&nbsp; Result 
    :=&nbsp;lparam +&nbsp;wparam //(for example)</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>&nbsp; end</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>&nbsp; else Result := 
    DefWindowProc(FHandle, Msg, wParam, lParam);<BR>end;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial size=2>I&nbsp;get a couple&nbsp;messages when the 
    program loads but I never get Msg =&nbsp;WM_USER.</FONT></DIV>
    <DIV><FONT face=Arial size=2>Do you see any problems with this 
    code?</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial size=2>The following&nbsp;code, however,&nbsp;when 
    placed in the mainform does detect WM_USER messages.</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>TForm1 = class(TForm)<BR>&nbsp; 
    ...</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>&nbsp; procedure WMUSER(var 
    Message: TMessage); message WM_USER;</FONT></DIV>
    <DIV><FONT face=Arial color=#000080 size=2>end;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=Arial color=#000080 size=2>procedure TForm1.WMUSER(var 
    Message: TMessage);<BR>begin<BR>&nbsp; with Message do<BR>&nbsp; if Msg = 
    WM_USER then showmessage('It Works!');<BR>end;</FONT></DIV>
    <DIV>&nbsp;</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.&nbsp; In fact I still get other messages when the program 
    starts.</FONT></FONT></DIV>
    <DIV>&nbsp;</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>&nbsp; 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.&nbsp; I managed to 
        implement AllocateHWnd etc, and everything appears correct and 
        logical.&nbsp; It's picking up some Windows messages but not the WM_USER 
        messages being sent.&nbsp; WM_USER is message number 1024.&nbsp; I'm 
        getting Message.Msg =&nbsp;28 and that's about it.</FONT></DIV>
        <DIV>&nbsp;</DIV>
        <DIV><FONT face=Arial size=2>I tried the same code&nbsp;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>&nbsp;</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>&nbsp;</DIV>
        <DIV><FONT face=Arial size=2>I tried this in the unit and it doesn't 
        make any difference.&nbsp; Message 28 is still getting to the procedure 
        and no 1024.</FONT></DIV>
        <DIV>&nbsp;</DIV>
        <DIV><FONT face=Arial size=2>You can tell I'm no expert when it comes to 
        this.&nbsp; Do I need to use your fancy looking wrapper 
        class?</FONT></DIV>
        <DIV>&nbsp;</DIV>
        <DIV><FONT face=Arial size=2>I must be missing something.</FONT></DIV>
        <DIV>&nbsp;</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;&nbsp; { moved to Classes.pas 
          }<BR>{$EXTERNALSYM AllocateHWnd}<BR>procedure DeallocateHWnd(Wnd: 
          HWND);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          deprecated;&nbsp; { 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.&nbsp; 
            After loading the DLL, I&nbsp;need to tell&nbsp;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.&nbsp; I know how to do it in 
            the mainform of a program but not in a separate unit.&nbsp; The 
            messages sent to the mainform do not appear to reach my 
            unit.</FONT></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><FONT face=Arial size=2>What do I need to do to make this 
            happen?</FONT></DIV>
            <DIV>&nbsp;</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>
      <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>