Hi Kyley
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.
Here is all my relevant code.
TMyComponent =
class(TComponent)
private
FHandle:
HWnd;
procedure WndProc(var Message: TMessage);
end;
constructor
TMyComponent.Create;
begin
inherited Create(AOwner);
FHandle := AllocateHWnd(WndProc);
end;
destructor
TMyComponent.Destroy;
begin
DeallocateHWnd(FHandle);
inherited Destroy;
end;
procedure TMyComponent.WndProc(var
Message: TMessage);
begin
with Message do
if Msg =
WM_USER then
begin
Result
:= lparam + wparam //(for example)
end
else Result :=
DefWindowProc(FHandle, Msg, wParam, lParam);
end;
I get a couple messages when the program
loads but I never get Msg = WM_USER.
Do you see any problems with this
code?
The following code, however, when placed
in the mainform does detect WM_USER messages.
TForm1 = class(TForm)
...
procedure WMUSER(var Message:
TMessage); message WM_USER;
end;
procedure TForm1.WMUSER(var Message:
TMessage);
begin
with Message do
if Msg = WM_USER then
showmessage('It Works!');
end;
I've tried different combinations of the syntax,
including the message WM_USER;
bit in the unit but it doesn't make any difference at all. In fact I still
get other messages when the program starts.
Thanks for the help.
Ross.
----- Original Message -----
Sent: Monday, June 27, 2005 10:01
PM
Subject: [Spam] Re: [DUG] Intercepting
messages in separate units
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.
then
myobject =
class(TObject)
procedure WMUSERLOGON(var msg:TMessage);message
WM_USERLOGON;
end;
the above procedure will only ever receive that
one message. You need to know exactly what messages you are expecting from the
dll.
if you use my wrapper, and attached an instance of the above
object to message handler it will route the messages to that
instance..
Ross Levis wrote:
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.
I tried the same code in the mainform as a
test and this worked but only after I specified the following:
procedure MyMessage(var Message: TMessage);
message WM_USER;
If I leave off "message WM_USER", then nothing
gets through to the procedure in the mainform at all.
I tried this in the unit and it doesn't make
any difference. Message 28 is still getting to the procedure and no
1024.
You can tell I'm no expert when it comes to
this. Do I need to use your fancy looking wrapper class?
I must be missing something.
Thanks,
Ross.
-----
Original Message -----
Sent:
Monday, June 27, 2005 7:13 PM
Subject:
[Spam] Re: [DUG] Intercepting messages in separate units
in the forms unit
function AllocateHWnd(Method:
TWndMethod): HWND; deprecated; { moved to Classes.pas
}
{$EXTERNALSYM AllocateHWnd}
procedure DeallocateHWnd(Wnd:
HWND);
deprecated; { moved to Classes.pas }
read the help will
sort you out just fine
Ross Levis wrote:
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.
What do I need to do to make this
happen?
Thanks,
Ross.
_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing
list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing
list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi