向窗体上添加两个TLabel组件、两个TEdit组件和一个TButton组件
首先声明NetMessageBufferSend函数,该函数在netapi32.dll库中:
type NET_API_STATUS = LongInt; function NetMessageBufferSend(servername: LPCWSTR; msgname: LPCWSTR; fromname: LPCWSTR; buf: Pointer; buflen: DWORD): NET_API_STATUS; stdcall;external ’netapi32.dll’;
在程序运行过程中,单击Send按钮,就会向Computer文本框指定的计算机发送Content文本框中输入的消息,响应代码如下:
procedure TForm1.Button1Click(Sender: TObject); var WideMsg:PWideChar; DestName:PWideChar; begin DestName:=PWideChar(WideString(Edit1.Text)); WideMsg:=PWideChar(WideString(Edit2.Text)); NetMessageBufferSend(nil,DestName,nil,WideMsg,Length(Edit2.Text)*2); end;
程序代码如下:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type NET_API_STATUS = LongInt; function NetMessageBufferSend(servername: LPCWSTR; msgname: LPCWSTR; fromname: LPCWSTR; buf: Pointer; buflen: DWORD): NET_API_STATUS; stdcall;external ’netapi32.dll’; type TForm1 = class(TForm) Edit1: TEdit; Label1: TLabel; Label2: TLabel; Edit2: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var WideMsg:PWideChar; DestName:PWideChar; begin DestName:=PWideChar(WideString(Edit1.Text)); WideMsg:=PWideChar(WideString(Edit2.Text)); NetMessageBufferSend(nil,DestName,nil,WideMsg,Length(Edit2.Text)*2); end; end.
保存文件,然后按F9键运行程序,在Computer对应的文本框中输入目的计算机名,在Content对应的文本框中输入消息内容。
单击Send按钮,就会向指定的计算机发送消息,在接收消息的计算机上就会显示一个对话框。
(T127)
上一篇: 提供一个基于C 的加密/解密算法
下一篇: 用Delphi编程实现清空回收站功能
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




