zoukankan      html  css  js  c++  java
  • 跨进程发送消息数据

     1 //1.发送窗体
     2 procedure TForm2.Button1Click(Sender: TObject);
     3 var
     4   h: HWND;
     5   Size: Integer;
     6   CopyDataStruct: TCopyDataStruct;
     7 begin
     8   h := FindWindow(nil, '接收窗口'); { 按标题查找目标窗口 }
     9   if h > 0 then
    10   begin
    11     Size := ByteLength(Edit1.Text) + 2;   { 多出的两个字节用于后面的 #0 }
    12     CopyDataStruct.lpData := PChar(Edit1.Text + #0); { 要发送的字符串, #0 表示 PChar 结束}
    13     CopyDataStruct.dwData := WM_COPYDATA;            { 指定消息类型 }
    14     CopyDataStruct.cbData := Size;                   { 指定要发送的数据的大小 }
    15     SendMessage(h, WM_COPYDATA, 0, Integer(@CopyDataStruct)); { 发送 }
    16   end;
    17 end;
    18 
    19 //2.接收窗体
    20 //2.1定义接收事件
    21 protected
    22     procedure WMCopyData(var Message: TWMCopyData); message WM_COPYDATA;
    23 
    24 //2.2执行接收事件事
    25 procedure TForm2.WMCopyData(var Message: TWMCopyData);
    26 begin
    27   Memo1.Lines.Add(PChar(Message.CopyDataStruct.lpData));
    28 end;
    29 
    30 //2.3改变窗体名
    31  procedure TForm2.FormCreate(Sender: TObject);
    32 begin
    33  Caption := '接收窗口';
    34 end; 
  • 相关阅读:
    HackerRank "Arithmetic Expressions" !
    HackerRank "Poker Nim"
    HackerRank "Nimble Game"
    HackerRank "Misère Nim"
    HackerRank "Triangle Numbers"
    HackerRank "Flipping the Matrix"
    HackerRank "Chessboard Game, Again!"
    HackerRank "Tower Breakers, Again!"
    HackerRank
    HackerRank "Richie Rich"
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/5843118.html
Copyright © 2011-2022 走看看