Maybe anyone could help me to solve this as I came to the dead end with this
problem.
I use the code below to send text info from one application to another.
The bad thing with this code is that it send message to all applications and
some responts to my message
like Outlook gives error.
To solve this I have changed HWND_BROADCAST to FindWindow('TfrmMyForm', nil)
to send message directly to my program, but there is another problem with
it. This code does not works if listener program is minimized.
I have tried to register message with
WM_TESTPOST:=RegisterWindowMessage(PChar('MyMessage'));
and replace WM_COPYDATA with WM_TESTPOST, but it does not work also.
I have tried to search through borland newsgroup and it showed few examples
how to send Integer type
variable using SendMessage but I did not found how to send String exept what
that I wrote below. Can it be done?
Receiver
procedure Receiver(var msg: TMessage); message WM_COPYDATA;
procedure TForm1.Receiver(var msg: TMessage); // message WM_COPYDATA;
var
PData: PCopyDataStruct;
AAction, ASource, Adocurl, Adoctitle, ArangeHTMLText, ArangeText, Aelesrc,
Aelealt: string;
AHTML: string;
begin
PData := PCopyDataStruct(Pointer(msg.LParam));
case PData.dwData of
0:
ASource := (PChar(PData.lpData));
1:
;
end;
ShowMessage(ASource);
end;
Sender
procedure TForm1.Button2Click(Sender: TObject);
var
ADataLeft: TCopyDataStruct;
AWindow: HWND;
AMessage: string;
begin
AMessage := 'Text to send';
ADataLeft.dwData := 0;
ADataLeft.lpData := PChar(AMessage);
ADataLeft.cbData := Length(AMessage) + 1;
SendMessage(HWND_BROADCAST, WM_COPYDATA, 0, LParam(@ADataLeft))
end;
Regards,
Mike
> procedure TForm1.Receiver(var msg: TMessage); // message WM_COPYDATA;
> var
> PData: PCopyDataStruct;
> AAction, ASource, Adocurl, Adoctitle, ArangeHTMLText, ArangeText,
> Aelesrc,
> Aelealt: string;
> AHTML: string;
> begin
>
> PData := PCopyDataStruct(Pointer(msg.LParam));
> case PData.dwData of
> 0:
> ASource := (PChar(PData.lpData));
i can't help with messages, but this won't work even if message will
finally be delivered. string is actually a reference to the actual
characters stored in heap. you cannot simply transfer a string from
one task to another, because only the reference will travel, the
characters themselves don't.
simple solution to use string[255] or other fixed string types in
the data you pass. other is to create a memory stream, write data in,
then transmit the stream's memory block.
"krisztian pinter" <pint...@freemail.hu> wrote in message
news:ops1gszouqwwfehv@karwst_pint...
>My previously posted example works without problem and string is delivered
>correctly to my application, the biggest problem is that
>message is delivered for all applications, and some applications response to
>it.
See my response in the other thread, basically you should BROADCAST a
unique windows message, expecting an answer with the window handle from
your other application (which *should* be the only application that
reacts to this message).
Then you WM_COPYDATA your data to *this window handle*.
You should never BROADCAST a WM_COPYDATA message.
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
I have tried to replaced HWND_BROADCAST with code FindWindow('TfrmMyForm',
nil)
to find out my application window handler and send message only ot it, but
problem is in minimize.
If receiver program is in minimized state, FindWindow('TfrmMyForm', nil)
does not find it.
>
> You should never BROADCAST a WM_COPYDATA message.
Do you have an code example how to use RegisterWindowsMessage() ?
Can anybody drop some ideas how to send string from one app to another
without using
SendMessage?
>
> I use the code below to send text info from one application to
> another. The bad thing with this code is that it send message to
> all applications and some responts to my message
> like Outlook gives error.
They may use WM_COPYDATA for their own purposes, and try to process
your passed data in the wrong way.
>
> To solve this I have changed HWND_BROADCAST to
> FindWindow('TfrmMyForm', nil) to send message directly to my
> program, but there is another problem with it. This code does not
> works if listener program is minimized.
I'm not certain why that is, but I'm not surprised. I'd suggest
using Window Spy or a similar tool to find which windows are
available, and what their names and classes are. Some should be
unchanged when the app is minimised.
I've put a library unit I created when solving a similar problem at:
http://www.carlyleclarke.plus.com/delphi/WindowControl.html
It may serve as a useful starting point for you.
>
> I have tried to register message with
> WM_TESTPOST:=RegisterWindowMessage(PChar('MyMessage'));
> and replace WM_COPYDATA with WM_TESTPOST, but it does not work
> also.
This will not work, because WM_COPYDATA does something special that
other messages do not do. String data (whether string or pchar) is
a pointer to data that is private to your process. The other
application cannot get hold of it. The WM_COPYDATA message actually
makes a copy of the data in the COPYDATASTRUCT that is available to
the other process.
>I have tried to replaced HWND_BROADCAST with code FindWindow('TfrmMyForm',
>nil)
>to find out my application window handler and send message only ot it, but
>problem is in minimize.
>If receiver program is in minimized state, FindWindow('TfrmMyForm', nil)
>does not find it.
That's why you should implement a minimal protocol, with the BROADCAST
message only asking "anyone out there?" and the responding program
answers with a suitable windows handle.
>Do you have an code example how to use RegisterWindowsMessage() ?
I couldn't find anything obvious on my disk at work with a quick search,
but I know I have done things like this before. I'll try to find
something...
Strange thing happen, I have tried one more time to replace HWND_BROADCAST
with FindWindow to find window handle and now it's works even if receiver in
minimized state.
This is solves all my problems :)
Thanks for all one more time.
"Anders Isaksson" <anders....@REMOVEcej.se> wrote in message
news:fpigp1d0kh0vqhtfh...@4ax.com...
Russ
"Mike Meyer" <m.m...@cox.com> wrote in message
news:4398...@newsgroups.borland.com...