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