Recent

Author Topic: SendMessage WM_COPYDATA is not recognized by Program  (Read 12636 times)

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« on: June 26, 2007, 04:14:11 pm »
Lazarus 0.9.23b, FPC 2.1.5, Win2k

I've a strange problem with sending messages between Forms.

For testing purposes I've made a small app for sending and recieving.
I start two instances of the program and try to send messages between them.
Using Spy++ I can see the messages beeing delivered to the right instance of my program.

I can send a WM_USER-Message (I've set the PassWin32MessagesToLCL define), but WM_COPYDATA messages don't reach the function i defined for them.


Code: [Select]

unit uMain;

{$mode Delphi}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Buttons, ExtCtrls, Windows;

const
  WM_TESTMSG=WM_USER+33;

type

  { TfMain }

  TfMain = class(TForm)
    btCopyData: TButton;
    btTestMsg: TButton;
    btSize: TButton;
    eNum: TEdit;
    eText: TEdit;
    mLog: TMemo;
    Panel1: TPanel;
    procedure btCopyDataClick(Sender: TObject);
    procedure btSizeClick(Sender: TObject);
    procedure btTestMsgClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  protected
procedure TestMsgProc(var msg: TMessage); message WM_TESTMSG;
procedure TestCopyProc(var msg: TMessage); message WM_COPYDATA;
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  fMain: TfMain;

implementation

uses ussnFuncLib;

{ TfMain }

procedure TfMain.TestMsgProc(var msg: TMessage);
begin
  mLog.Lines.Add('Testmessage erhalten!');
end;

procedure TfMain.TestCopyProc(var msg: TMessage);
begin
  mLog.Lines.Add('Copymessage erhalten!');
end;

procedure TfMain.FormCreate(Sender: TObject);
begin
  ssnDbgOutputEnabled:=True;
  Caption:=ITS(self.Handle)+' '+IntToHex(Self.Handle,8);
  eNum.Text:=ITS(self.Handle);
  eText.Text:='Testnachricht von '+ITS(Self.Handle);
  mLog.Lines.Clear;
end;

procedure TfMain.btTestMsgClick(Sender: TObject);
var W:Integer;
begin
  W:=STI(eNum.Text);
  mLog.Lines.Add('Sende Testnachricht an: '+ITS(W));
  SendMessage(W,WM_TESTMSG,0,0);
end;

procedure TfMain.btCopyDataClick(Sender: TObject);
Var CopyData:TCopyDataStruct;
    Data:TData;
    W:Integer;
begin
  Data.Nr:=0;
  Data.Text:=eText.Text;
CopyData.dwData:=201175;
  CopyData.lpData:=@Data;
  CopyData.cbData:=SizeOf(Data);
  W:=STI(eNum.Text);
  mLog.Lines.Add('Sende Copynachricht an: '+ITS(W));
  SendMessage(W,WM_COPYDATA,self.Handle,LongInt(@CopyData));
end;

procedure TfMain.btSizeClick(Sender: TObject);
begin
  SendMessage(STI(eNum.Text),WM_SIZE,self.Handle,201175);
end;

initialization
  {$I uMain.lrs}

end.


Anyone an Idea where to look for my WM_COPYDATA Messages?

regards

Lukas

grl

  • New Member
  • *
  • Posts: 41
RE: SendMessage WM_COPYDATA is not recognized by Program
« Reply #1 on: June 28, 2007, 04:45:32 pm »
*push*

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: SendMessage WM_COPYDATA is not recognized by Program
« Reply #2 on: June 28, 2007, 05:44:04 pm »
Rebuild your LCL with the PassWin32MessagesToLCL option:

http://wiki.lazarus.freepascal.org/LCL_Defines#Win32_defines

to rebuild lazarus use the menu: Tools --> Configure build Lazarus

and type -dPassWin32MessagesToLCL on the edit field there. And you only need to rebuild LCL, so set LCL to clean+build and everything else to NONE

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« Reply #3 on: June 29, 2007, 12:19:54 am »
As described in my posting i've already done this:

Quote
I can send a WM_USER-Message (I've set the PassWin32MessagesToLCL define), but WM_COPYDATA messages don't reach the function i defined for them.


If not, WM_USER-Messages won't work as well - but they work as expected.

Only WM_COPYDATA-Messages won't reach the messagehandler!

Regards
Lukas

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
SendMessage WM_COPYDATA is not recognized by Program
« Reply #4 on: June 29, 2007, 07:16:26 am »
You also need to override the WndProc.

Here is a real life example:

http://magnifier.cvs.sourceforge.net/magnifier/magnifierv3/app.pas?revision=1.39&view=markup

Look for the WndProc and it's implementation.

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« Reply #5 on: July 02, 2007, 12:04:26 pm »
sekel,

Thanks for your response but:

1.) I already tried that - same effect - WM_USER works, WM_COPYDATA does not.
My implementation of WndProc was quite simple:
Code: [Select]

procedure TfMain.WndProc(var msg: TMessage);
begin
  if msg.msg=WM_COPYDATA then begin
    mLog.Lines.Add('Copymessage/WndProc erhalten!');
  end else begin
    inherited WndProc(Msg);
  end;
end;    


2.) AFAIK you don't have to overwrite WndProc if you explicit request a Message-Type - as I've done in my example...
Look at the code provided by me: TestMsgProc works, TestCopyProc doesn't.

regards
Lukas

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« Reply #6 on: July 07, 2007, 01:30:03 am »
As no one seems to be able to help I opened a bug-report with ID 9210

regards

Lukas

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
SendMessage WM_COPYDATA is not recognized by Program
« Reply #7 on: July 07, 2007, 09:04:23 am »
As bug reports are no support requests, I don't thinkt that is going to help you either (unless you are willing to wait 2-3 years).

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« Reply #8 on: July 07, 2007, 06:48:18 pm »
This is no support-request in the bug-tracker.

As no one finds a bug in my code (and the same code works as expected in Delphi7) i presume a bug in Lazarus (or the LCL to be specific).

Regards
Lukas

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
SendMessage WM_COPYDATA is not recognized by Program
« Reply #9 on: July 07, 2007, 07:26:35 pm »
Of course, you can assume a LCL bug. Then I think WM_COPYDATA fixes are unlikely to be handled soon.

Or you can assume that the LCL is a VCL clone and think that if it works with the VCL, it must work with the LCL too. Then you are mistaken.

grl

  • New Member
  • *
  • Posts: 41
SendMessage WM_COPYDATA is not recognized by Program
« Reply #10 on: July 17, 2007, 06:15:44 pm »
As I've found at least a workaround I'm now searching for the right place to discuss this possibility.

Can anyone point me to the right place?

regards
Lukas

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
SendMessage WM_COPYDATA is not recognized by Program
« Reply #11 on: July 17, 2007, 07:12:00 pm »
Lazarus mailing list.

 

TinyPortal © 2005-2018