向窗体上添加两个TLabel组件、两个TEdit组件和一个TButton组件,设计完成的主界面如图1所示。
图1 主界面
首先声明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.
【Delphi实现在局域网内传递消息程序】相关文章:
上海市军人随军家属就业安置实施办法细则02-07
2022军转干考试申论热点:为网络直播筑牢制度篱笆02-07
2025年宁夏卫生资格考试报名网站:https://www.21wecan.com/02-07
2020四川成都民政局军人公开招聘15名工作人员公告(退役大学生士兵政策加分)02-07
2023广东阳江市机关事务管理局考试录用公务员拟录用人员公示名单02-07
2014加拿大留学本科规划流程02-07
