我想用SendMessage来发送字符串,怎么办
1个回答
展开全部
发送 :
COPYDATASTRUCT cds;
AnsiString Data=Edit2->Text;//"Just a test";
cds.dwData=sizeof(COPYDATASTRUCT);
cds.cbData=Data.Length();
cds.lpData=(LPVOID)Data.c_str();
//想目标窗口发消息WM_COPYDATA
SendMessage((HWND)Edit1->Text.ToInt(),WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
接收:
if(Message.Msg==WM_COPYDATA)
{
COPYDATASTRUCT *cds;
char* DataBuf;
cds=(COPYDATASTRUCT*)Message.LParam;
DataBuf=new char[cds->cbData];
CopyMemory(DataBuf,cds->lpData,cds->cbData);
AnsiString Str=AnsiString(DataBuf);
Memo1->Lines->Add("Str="+Str);
delete[] DataBuf;
}
COPYDATASTRUCT cds;
AnsiString Data=Edit2->Text;//"Just a test";
cds.dwData=sizeof(COPYDATASTRUCT);
cds.cbData=Data.Length();
cds.lpData=(LPVOID)Data.c_str();
//想目标窗口发消息WM_COPYDATA
SendMessage((HWND)Edit1->Text.ToInt(),WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
接收:
if(Message.Msg==WM_COPYDATA)
{
COPYDATASTRUCT *cds;
char* DataBuf;
cds=(COPYDATASTRUCT*)Message.LParam;
DataBuf=new char[cds->cbData];
CopyMemory(DataBuf,cds->lpData,cds->cbData);
AnsiString Str=AnsiString(DataBuf);
Memo1->Lines->Add("Str="+Str);
delete[] DataBuf;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询