<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Here is a wrapper class you can look at<br>
<br>
(*<br>
<br>
&nbsp; This source code is Copyright (C) 2000&nbsp; Kyley Harris<br>
<br>
&nbsp; This software is provided 'as-is', without any express or implied<br>
&nbsp; warranty.&nbsp; In no event will the author be held liable for any damages<br>
&nbsp; arising from the use of this software.<br>
<br>
&nbsp; Permission is granted to anyone who has received permission from the
author<br>
&nbsp; in writing, or purchased a licence to use from the author to use this<br>
&nbsp; software for any purpose, including commercial applications, and to
alter it<br>
&nbsp; freely, subject to the following restrictions:<br>
<br>
&nbsp; 1. The origin of this software must not be misrepresented; you must
not<br>
&nbsp;&nbsp;&nbsp;&nbsp; claim that you wrote the original software. If you use this
software<br>
&nbsp;&nbsp;&nbsp;&nbsp; in a product, an acknowledgment in the product documentation would
be<br>
&nbsp;&nbsp;&nbsp;&nbsp; appreciated but is not required.<br>
&nbsp; 2. Altered source versions must be plainly marked as such, and must
not be<br>
&nbsp;&nbsp;&nbsp;&nbsp; misrepresented as being the original software.<br>
&nbsp; 3. This notice may not be removed or altered from any source
distribution.<br>
&nbsp; 4. The source codes may not be redistributed without permission.<br>
&nbsp; 5. This header must not be removed or altered.<br>
<br>
&nbsp; Any changes to the code would be appreciated to be emailed to the
author<br>
&nbsp; for consideration to any improvements.<br>
<br>
&nbsp; Kyley Harris, Auckland, New Zealand<br>
&nbsp; <a class="moz-txt-link-abbreviated" href="mailto:Kyley@HarrisSoftware.com">Kyley@HarrisSoftware.com</a><br>
<br>
*)<br>
(*<br>
&nbsp; $History: uHssHAndle.pas $<br>
&nbsp;* <br>
&nbsp;* *****************&nbsp; Version 5&nbsp; *****************<br>
&nbsp;* User: Kyley&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date: 10/06/05&nbsp;&nbsp; Time: 1:14a<br>
&nbsp;* Updated in $/Code/HssShare<br>
&nbsp;* <br>
&nbsp;* *****************&nbsp; Version 4&nbsp; *****************<br>
&nbsp;* User: Kyley&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date: 1-12-04&nbsp;&nbsp;&nbsp; Time: 3:34p<br>
&nbsp;* Updated in $/Code/HssShare<br>
&nbsp;* <br>
&nbsp;* *****************&nbsp; Version 3&nbsp; *****************<br>
&nbsp;* User: Kyley&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date: 7-08-04&nbsp;&nbsp;&nbsp; Time: 8:34p<br>
&nbsp;* Updated in $/Code/HssShare<br>
*)<br>
{&amp;&amp;
--------------------------------------------------------------------------<br>
<br>
&nbsp; Intention:<br>
&nbsp;&nbsp;&nbsp; Object which allows any other object to have a windows handle to use<br>
&nbsp;&nbsp;&nbsp; the message command on methods without inheriting from TWinControl<br>
<br>
&nbsp; $Header: /Code/HssShare/uHssHAndle.pas 5&nbsp;&nbsp;&nbsp;&nbsp; 10/06/05 1:14a Kyley $<br>
<br>
<br>
&nbsp; Copyright &copy; 1999 by Harris Software Ltd<br>
&nbsp; Author:Kyley Harris<br>
&nbsp; <a class="moz-txt-link-freetext" href="Http://www.HarrisSoftware.Com">Http://www.HarrisSoftware.Com</a><br>
------------------------------------------------------------------------------}<br>
<br>
unit uHssHandle;<br>
<br>
interface<br>
uses<br>
&nbsp; windows,<br>
&nbsp; classes,<br>
&nbsp; sysutils,<br>
&nbsp; messages;<br>
<br>
type<br>
&nbsp; EHssHandle = class(Exception);<br>
<br>
&nbsp; THssHandle = class(TComponent)<br>
&nbsp; private<br>
&nbsp;&nbsp;&nbsp; FHandle:HWND;<br>
&nbsp;&nbsp;&nbsp; FMessageHandler: TObject;<br>
&nbsp;&nbsp;&nbsp; function GetHandle: HWND;<br>
&nbsp;&nbsp;&nbsp; procedure SetMessageHandler(const Value: TObject);<br>
&nbsp;&nbsp;&nbsp; function GetHandleAllocated: boolean;<br>
&nbsp; protected<br>
&nbsp;&nbsp;&nbsp; procedure Notification(AComponent: TComponent; Operation:
TOperation);override;<br>
&nbsp;&nbsp;&nbsp; procedure WndProc(var Msg: TMessage);virtual;<br>
&nbsp; public<br>
&nbsp;&nbsp;&nbsp; constructor Create(AOwner:TComponent);override;<br>
&nbsp;&nbsp;&nbsp; destructor Destroy;override;<br>
&nbsp;&nbsp;&nbsp; procedure CreateHandle;<br>
&nbsp;&nbsp;&nbsp; procedure RemoveHandle;<br>
&nbsp;&nbsp;&nbsp; property Handle:HWND read GetHandle;<br>
&nbsp; published<br>
&nbsp;&nbsp;&nbsp; property HandleAllocated:boolean read GetHandleAllocated;<br>
&nbsp;&nbsp;&nbsp; property MessageHandler:TObject read FMessageHandler write
SetMessageHandler;<br>
&nbsp; end;<br>
<br>
&nbsp; THssHandleClass = class of THssHandle;<br>
<br>
<br>
implementation<br>
<br>
<br>
<br>
constructor THssHandle.create(AOwner: TComponent);<br>
begin<br>
&nbsp; inherited;<br>
&nbsp; FHandle := 0;<br>
&nbsp; FMessageHandler := AOwner;<br>
&nbsp; CreateHandle;<br>
end;<br>
<br>
procedure THssHandle.CreateHandle;<br>
begin<br>
&nbsp; if FHandle = 0 then<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; FHandle := AllocateHWnd(WndProc);<br>
&nbsp; end;<br>
end;<br>
<br>
destructor THssHandle.destroy;<br>
begin<br>
&nbsp; RemoveHandle;<br>
&nbsp; inherited;<br>
end;<br>
<br>
function THssHandle.GetHandle: HWND;<br>
begin<br>
&nbsp; CreateHandle;<br>
&nbsp; result := FHandle;<br>
end;<br>
<br>
function THssHandle.GetHandleAllocated: boolean;<br>
begin<br>
&nbsp; result := FHandle &lt;&gt; 0;<br>
end;<br>
<br>
procedure THssHandle.Notification(AComponent: TComponent;<br>
&nbsp; Operation: TOperation);<br>
begin<br>
&nbsp; inherited;<br>
&nbsp; if Operation = opRemove then<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; if AComponent = FMessageHandler then<br>
&nbsp;&nbsp;&nbsp; begin<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FMessageHandler := nil;<br>
&nbsp;&nbsp;&nbsp; end;<br>
&nbsp; end;<br>
end;<br>
<br>
procedure THssHandle.RemoveHandle;<br>
begin<br>
&nbsp; if HandleAllocated then<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; try<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DeAllocateHwnd(FHandle);<br>
&nbsp;&nbsp;&nbsp; finally<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FHandle := 0;<br>
&nbsp;&nbsp;&nbsp; end;<br>
&nbsp; end;<br>
end;<br>
<br>
procedure THssHandle.SetMessageHandler(const Value: TObject);<br>
begin<br>
&nbsp; if assigned(FMessageHandler) and (FMessageHandler &lt;&gt; self ) and
(FMessageHandler &lt;&gt; Value ) and (not (CsDesigning in
ComponentState)) then<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; raise EHssHandle.create('Cannot Re-Assign Handler');<br>
&nbsp; end;<br>
<br>
&nbsp; FMessageHandler := Value;<br>
<br>
end;<br>
<br>
procedure THssHandle.WndProc(var Msg: TMessage);<br>
begin<br>
&nbsp; if assigned(MessageHandler) then<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; MessageHandler.Dispatch(Msg);<br>
&nbsp; end else<br>
&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; EHssHandle.create('Message Handler Must be assigned');<br>
&nbsp; end;<br>
end;<br>
<br>
end.<br>
<br>
Ross Levis wrote:
<blockquote cite="mid014401c57ae7$48177ca0$5100a8c0@levis4" type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <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 size="4" width="90%">
_______________________________________________
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>
</body>
</html>