社区
Delphi
帖子详情
delphi sendmessge 如何传递字符串内容的信息?
clark_x
2004-04-25 12:27:39
sendmessage(application.handle, MESSAGE, WPARAM, LPRAM );
怎么放想传递的字符串信息呢?
...全文
378
8
打赏
收藏
delphi sendmessge 如何传递字符串内容的信息?
sendmessage(application.handle, MESSAGE, WPARAM, LPRAM ); 怎么放想传递的字符串信息呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
楚人无衣
2004-04-25
打赏
举报
回复
var
s: string;
begin
s := 'season';
sendmessage(application.handle, MESSAGE, WPARAM, Integer(@s));
...
end;
miky
2004-04-25
打赏
举报
回复
传指针
clark_x
2004-04-25
打赏
举报
回复
另外还要注明的是 我是用DELPHI 调用 一个 VB (WM_SETTEXT).是VB 传递过来的字符串信息,由于涉及到两公司的开发,可能接口不好改变了 大家有没有好办法?
clark_x
2004-04-25
打赏
举报
回复
我仅仅是传递一个 字符串 而已也而且我用的是自己 RegisterWindowMessage 的消息 ,这样可以保证传递的可靠性 。 不会出现系统其它的一些东东;
实际上,我们现在是使用WM_SETTEXT 来传递的,在这样的一些条件下,如何解决这个问题呢?
qizhanfeng
2004-04-25
打赏
举报
回复
学习
miky
2004-04-25
打赏
举报
回复
两个程序之间用消息传递数据
两个程序之间用消息传递数据。
问题:我想用SendMessage和自定义消息在两个程序之间传递一个字符串,问题是如果这个字符串是一个常量,SendMessage(h,CM_MYMESSAGE,0,integer(pchar('abcdef')));另外一个程序对CM_MYMESSAGE进行处理可以收到'abcdef',然而,把abcdef变成一个pchar或者string进行传递,就无法正常使用了!如何解决呢?
解答:可以利用WM_COPYDATA来做。
下面代码仅仅演示,细节错误不予考虑
procedure Init;
var
s : pchar;
h : hwnd;
buf:tagCOPYDATASTRUCT;
begin
h := FindWindow('TForm1', 'Form1');
if h <> 0 then
begin
GetMem(s,100);
buf.lpData :=s;
buf.cbData:=100;
buf.dwData :=100;
strpcopy(s, ParamStr(0));
SendMessage(h, WM_COPYDATA, 0, integer(@buf));
end;
end;
procedure TForm1.WM_COPYDATA(var msg: TMessage);
var
P:^tagCOPYDATASTRUCT;
begin
p:=Pointer(Msg.lParam);
ShowMessage(strpas(p.lpData));
end;
***********************************************************************************
{
The WM_COPYDATA messages makes it possible to transfer information
between processes. It does this by passing the data through the kernel.
Space is allocated in the receiving process to hold the information that is copied,
by the kernel, from the source process to the target process.
The sender passes a pointer to a COPYDATASTRUCT, which is defined as a structure
of the following:
}
type
TCopyDataStruct = packed record
dwData: DWORD; // anwendungsspezifischer Wert
cbData: DWORD; // Byte-L?nge der zu übertragenden Daten
lpData: Pointer; // Adresse der Daten
end;
{ Sender Application }
unit SenderApp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure SendCopyData(hTargetWnd: HWND; ACopyDataStruct:TCopyDataStruct);
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// Sender: Send data
// Sender: Daten schicken
procedure TForm1.SendCopyData(hTargetWnd: HWND; ACopyDataStruct:TCopyDataStruct);
begin
if hTargetWnd <> 0 then
SendMessage(hTargetWnd, WM_COPYDATA, Longint(Handle), Longint(@ACopyDataStruct))
else
ShowMessage('No Recipient found!');
end;
// Send Text from Edit1 to other app
// Text von Edit1 an andere Anwendung schicken
procedure TForm1.Button1Click(Sender: TObject);
var
MyCopyDataStruct: TCopyDataStruct;
hTargetWnd: HWND;
begin
// Set up a COPYDATASTRUCT structure for use with WM_COPYDATA
// TCopyDataStruct mit den Sende-Daten Infos ausfüllen
with MyCopyDataStruct do
begin
dwData := 0; // may use a value do identify content of message
cbData := StrLen(PChar(Edit1.Text)) + 1; //Need to transfer terminating #0 as well
lpData := PChar(Edit1.Text)
end;
// Find the destination window for the WM_COPYDATA message
// Empf?nger Fenster anhand des Titelzeilentextes suchen
hTargetWnd := FindWindow(nil,PChar('Message Receiver'));
// send the structure to the receiver
// Die Struktur an den Empf?nger schicken
SendCopyData(hTargetWnd, MyCopyDataStruct);
end;
// Send Image1 to other app
// Image1 an andere Anwendung schicken
procedure TForm1.Button2Click(Sender: TObject);
var
ms: TMemoryStream;
MyCopyDataStruct: TCopyDataStruct;
hTargetWnd: HWND;
begin
ms := TMemoryStream.Create;
try
image1.Picture.Bitmap.SaveToStream(ms);
with MyCopyDataStruct do
begin
dwData := 1;
cbData := ms.Size;
lpData := ms.Memory;
end;
// Search window by the window title
// Empf?nger Fenster anhand des Titelzeilentextes suchen
hTargetWnd := FindWindow(nil,PChar('Message Receiver'));
// Send the Data
// Daten Senden
SendCopyData(hTargetWnd,MyCopyDataStruct);
finally
ms.Free;
end;
end;
end.
{*********************************************************************}
{ Receiver Application }
unit ReceiverApp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Label1: TLabel;
private
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMCopyData(var Msg: TWMCopyData);
var
sText: array[0..99] of Char;
ms: TMemoryStream;
begin
case Msg.CopyDataStruct.dwData of
0: { Receive Text, Text empfangen}
begin
StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);
label1.Caption := sText;
end;
1: { Receive Image, Bild empfangen}
begin
ms := TMemoryStream.Create;
try
with Msg.CopyDataStruct^ do
ms.Write(lpdata^, cbdata);
ms.Position := 0;
image1.Picture.Bitmap.LoadFromStream(ms);
finally
ms.Free;
end;
end;
end;
end;
end.
clark_x
2004-04-25
打赏
举报
回复
我是在两个进程间传递这个消息的 ? 这个内存信息会出现问题吗?
clark_x
2004-04-25
打赏
举报
回复
如何接收呢?
Delphi
7高级应用开发随书源码
Delphi
7高级应用开发随书源码
获得CPU序列号和CPU厂商名
资源文件Cpuid.res包含应用程序的非文本数据,如图标、
字符串
表或其他本地化
信息
。在这个案例中,它可能包含与UI相关的图标和错误消息,或者预定义的
字符串
来展示CPU序列号和厂商名。 **获取CPU序列号和厂商名的...
实现启动画面
Delphi
中的资源文件可以包含位图(Bitmap)、图标(Icon)、
字符串
资源等。在"splash.res"中,可能包含以下
内容
: - **Splash Bitmap**:一个位图图像,可能是静态的Logo或者动态的转场效果,为用户提供视觉反馈。 ...
使用Internet控件的简单Web浏览器
- BABYWEB.RES 和 BABYFTP.RES:这些是资源文件,包含图标、
字符串
和其他非代码的二进制资源。 在这个项目中,开发者可能使用
Delphi
集成开发环境(IDE),通过引用WebBrowser控件来创建用户界面,并实现与控件交互...
Delphi
如何计算
字符串
表达式呢?
今天工作上遇到一个问题,需要计算
字符串
形式的表达式,比如: var s:string; begin s:='2+4*1.7'; end; 问s等于多少。 我认为这需要一个
字符串
解析器,把
字符串
解析成真正的表达式才行。 经过...
Delphi
5,930
社区成员
262,943
社区内容
发帖
与我相关
我的任务
Delphi
Delphi 开发及应用
复制链接
扫一扫
分享
社区描述
Delphi 开发及应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章