Sending Message

how do i passing a additional parameter to my message handler ? let say i write my own message and send my additional parameter to my message handler instead of using the LParam and WParam.
qwertyuiopasdfghjklAsked:
Who is Participating?
 
viktornetConnect With a Mentor Commented:
10Q

btw- Madshi is right about the WM_COPYDATA.

Happy New Year (Well almost)

-Viktor
--Ivanov
0
 
viktornetCommented:
If your additional data is a record then you use a pointer and send it with the lparam or wparam..

SendMessage(Handle, Message, lparam, longint(@data));
0
 
viktornetCommented:
oh, I forgot, then when you receive it you typecast it like this...

var
  myrec : TMYREC;
begin
  myRec := TMYREC(msg.lparam^);
 //Then use your record here... It can work for any variable or type or whatever..You just send a pointer with the message...
end;

-Viktor
--Ivanov
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
viktornetCommented:
is this what you needed??
0
 
scrapdogCommented:
Vik's method is a good idea...however, don't you have to pass the pointer thru the LParam?  [If I remember correctly, WParam is a word, and a pointer is a double-word]
0
 
viktornetCommented:
Oppps... Scrappy :) is right... Actualy that's exactly what I've done, but I have a typo that makes it look if I've exchanged the parameters...

This line

SendMessage(Handle, Message, lparam, longint(@data));

should be

SendMessage(Handle, Message, wparam, longint(@data));

sorry for da typo... :))

Does it help now? Am I allowed to answer the q'n?
0
 
rwilson032697Commented:
Scrappy is only half right (sorry to be picky). Yes you should use LParam, but, Wparam in Win32 is a DWORD!

Cheers,

Raymond.

0
 
MadshiCommented:
Yes, Raymond is right. In win16, wParam is 16 bit long, in win32 it is 32 bit long.

However, if you send messages from one application to another, you can't just give in a pointer to a data block, since the pointer will definitely be invalid in the other application's memory context.
So if you're sending this message from one of your applications to another one of your applications, you'll have to look at the WM_COPYDATA message, which is thought for this purpose.
Otherwise (that means if the message is sent and received from the same application) Viktor's solution is right.
0
 
qwertyuiopasdfghjklAuthor Commented:
ok..Viktor ...you can post it as answer now...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.