本程序介绍如何在局域网内安装了信使服务的Windows 2000计算机之间传递消息。
向窗体上添加两个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. |
保存文件,然后按F9键运行程序,程序运行的初始画面如图2所示。
![]() 图2 程序运行的初始画面 |
在Computer对应的文本框中输入目的计算机名,在Content对应的文本框中输入消息内容,如图3所示。
单击Send按钮,就会向指定的计算机发送消息,在接收消息的计算机上就会显示一个对话框,如图4所示。
图3 指定计算机名和消息内容 ![]() 图4 程序运行结果 |
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- 熊猫烧香核心源码(Delphi模仿版-仅供学习 (11349次浏览)
- 用Delphi开发视频聊天软件 (4953次浏览)
- Delphi控制Excel自动生成报表 (4001次浏览)
- 动态语言崛起 Delphi For PHP能否挽救Borla (2976次浏览)
- Delphi 中串口通讯的实现 (2889次浏览)
- 用Delphi + DirectX开发简单RPG游戏 (2551次浏览)
- 用Delphi和Web Services开发短信应用程序 (2043次浏览)
- 使用TCP/IP协议实现聊天程序 (1827次浏览)
- 用DELPHI实现文件加密压缩 (1721次浏览)
- 利用Delphi编程控制摄像头 (1391次浏览)






