zoukankan      html  css  js  c++  java
  • delphi 进程通讯之WM_COPYDATA 发送程序(SendData.exe) 可用

    http://www.delphitop.com/html/wangluo/1529.html

    delphi 进程通讯之WM_COPYDATA 发送程序(SendData.exe)

    作者:admin 来源:未知 日期:2011/4/5 0:07:13 人气:1199 标签:

    进程通讯之WM_COPYDATA 发送程序(SendData.exe):

    unit SendUnit;
    interface
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;
    type
    TFrmSend = class(TForm)
    BtnSend: TButton;
    procedure BtnSendClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    FrmSend: TFrmSend;
    implementation
    {$R *.dfm}
    { TFrmRecv }
    procedure TFrmSend.BtnSendClick(Sender: TObject);
    var
    _vMsg : string;
    i, _vLen : Integer;
    _vBuf : array of Char;
    _vCopyData : TCopyDataStruct;
    _vHandle: THandle;
    begin
    _vMsg := '我是来自另外一个进程的消息!';
    _vLen := Length(_vMsg);
    SetLength(_vBuf, _vLen);
    for i := 0 to _vLen - 1 do
    _vBuf[i] := _vMsg[i + 1];
    _vCopyData.dwData := 100;
    _vCopyData.cbData := _vLen;
    _vCopyData.lpData := _vBuf;
    _vHandle := FindWindow('TFrmRecv', '接收程序');
    if _vHandle <> 0 then
    SendMessage(_vHandle, WM_COPYDATA, 0, longint(@_vCopyData));
    end;
    end.

    接收程序(RecvData.exe):

    unit RecvUnit;
    interface
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;
    type
    TFrmRecv = class(TForm)
    private
    { Private declarations }
    procedure RecvMessage(var aMsg: TWMCOPYDATA); message WM_COPYDATA;
    public
    { Public declarations }
    end;
    var
    FrmRecv: TFrmRecv;
    implementation
    {$R *.dfm}
    { TFrmSend }
    procedure TFrmRecv.RecvMessage(var aMsg: TWMCOPYDATA);
    var
    _vBufLen : Integer;
    _vBuf : array of Char;
    i : Integer;
    _vStr : string;
    begin
    if aMsg.CopyDataStruct^.dwData = 100 then
    begin
    _vBufLen := aMsg.CopyDataStruct^.cbData;
    System.SetLength(_vBuf, _vBufLen);
    Move(aMsg.CopyDataStruct^.lpData^, _vBuf[0], _vBufLen);
    _vStr := '';
    for i := 0 to _vBufLen - 1 do
    _vStr := _vStr + _vBuf[i];
    ShowMessage('Len: ' + IntToStr(_vBufLen) + ' ' + _vStr);
    end;
    end;
    end. 
    delphi lazarus opengl 网页操作自动化, 图像分析破解,游戏开发
  • 相关阅读:
    CSS盒子模型
    getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
    MYSQL中的CASE WHEN END AS
    单点登录的精华总结
    git&github
    June 21st 2017 Week 25th Wednesday
    June 20th 2017 Week 25th Tuesday
    June 19th 2017 Week 25th Monday
    June 18th 2017 Week 25th Sunday
    June 17th 2017 Week 24th Saturday
  • 原文地址:https://www.cnblogs.com/delphi-xe5/p/9499549.html
Copyright © 2011-2022 走看看