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

解决方案 »

  1.   


    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;
    }
      

  2.   

    接受端负责delete啊。在OnMessage1里头delete 就行了。
      

  3.   

    还要加ON_COMMAND(message1,onMessage1F) ba
      

  4.   

    LRESULT SendMessage( 
    UINT message, 
    WPARAM wParam = 0, 
    LPARAM lParam = 0 );
      

  5.   

    不一定要new吧,这样也省得deletestruct T  sT;PostMessage(WM_COPYDATA, (void *)&sT, ...)   
      

  6.   

    如果发送端new, 则发送过后发送端delte接受处是从中复制了数据的
      

  7.   

    somexing,你那样不行的。你那在栈里头分配的,出了函数就被清了。
     接受端拿到这个地址访问的是错误的数据。
      

  8.   

    错了应该是SendMessage发送copydata消息且接受侧肯定不能删除消息内容
    见 MSDN  
    WM_COPYDATARes
    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. 且接受侧肯定不能删除消息内容;它是复制消息内容的