怎样使用PostMessage把一个Struct传给一个窗体?

lk_cool 2005-03-28 12:28:53
怎样使用PostMessage把一个Struct传给一个窗体?
...全文
235 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
gnixemos 2005-03-29
  • 打赏
  • 举报
回复
错了

应该是SendMessage发送copydata消息

且接受侧肯定不能删除消息内容


见 MSDN
WM_COPYDATA

Remarks
An application must use theSendMessage function to send this message, not thePostMessage function.

应该是SendMessage发送copydata消息

The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data.

While this message is being sent, the referenced data must not be changed by another thread of the sending process.

The receiving application should consider the data read-only. The pcds parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by pcds. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.

且接受侧肯定不能删除消息内容;它是复制消息内容的


gnixemos 2005-03-29
  • 打赏
  • 举报
回复
接受处是从中复制了数据的
DentistryDoctor 2005-03-28
  • 打赏
  • 举报
回复
delete由谁负责?
horisly 2005-03-28
  • 打赏
  • 举报
回复
上楼 ok
cut9 2005-03-28
  • 打赏
  • 举报
回复

struct {...} ST;

1.发送:

ST * p = new ST;
p->.. = ;
p->.. = ;


PostMessage(hwindow, message1, (WPARAM)p, LPARAM lparam);

2.接受
//在你的窗口

LONG onMessage1(WPARAM wparam, LPARAM lparam)
{
ST * p = (ST*) wparam;
if (0 == p)
{
//process error here
}
else
{
p->.. 取数据
处理
}

return 1L;
}
cut9 2005-03-28
  • 打赏
  • 举报
回复
somexing,你那样不行的。你那在栈里头分配的,出了函数就被清了。
接受端拿到这个地址访问的是错误的数据。
gnixemos 2005-03-28
  • 打赏
  • 举报
回复
如果发送端new, 则发送过后发送端delte

接受处是从中复制了数据的
gnixemos 2005-03-28
  • 打赏
  • 举报
回复
不一定要new吧,这样也省得delete

struct T sT;

PostMessage(WM_COPYDATA, (void *)&sT, ...)



hongjun_han 2005-03-28
  • 打赏
  • 举报
回复
LRESULT SendMessage(
UINT message,
WPARAM wParam = 0,
LPARAM lParam = 0 );
surstar 2005-03-28
  • 打赏
  • 举报
回复
还要加ON_COMMAND(message1,onMessage1F) ba
oyljerry 2005-03-28
  • 打赏
  • 举报
回复
用全局,或堆数据
Mr-Chen 2005-03-28
  • 打赏
  • 举报
回复
只需要传递指向结构的指针就可以,不过这个指针空间必须是全局的
cut9 2005-03-28
  • 打赏
  • 举报
回复
接受端负责delete啊。在OnMessage1里头delete 就行了。

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧