在delphi中如何使用netsend发送消息,点击按钮就发送消息

wxjh 2002-09-30 07:58:02
如题
...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
无为 2002-10-23
  • 打赏
  • 举报
回复
其实你可以调用netaip32.dll里的函数,这样你能获得更多的功能
请先声明
function NetMessageBufferSend(ServerName: PWideChar;
MsgName: PWideChar; FromName: PWideChar;
Buf: PWideChar; BufLen: integer): dword; stdcall;
external 'netapi32.dll' name 'NetMessageBufferSend';
然后你就可以用了:
function SendMsg(Proxy,Target,FromName, Msg: string): integer;
var Size: integer;
ProxyU: array[0..127] of widechar;
TargetU: array[0..127] of widechar;
FromNameU:array[0..127] of widechar;
MsgU: array[0..4091] of widechar;
begin

Proxy:='\\'+Proxy;
StringToWideChar(Proxy,@ProxyU,sizeof(ProxyU));
StringToWideChar(Target,@TargetU,SizeOf(TargetU));
StringToWideChar(FromName,@FromNameU,sizeof(FromName));
StringToWideChar(Msg,@MsgU,SizeOf(MsgU));
Size:=(length(Msg)+1)*2;
Result:=NetMessageBufferSend(NIL,@TargetU,NIL,@MsgU,Size);
end;
我有一点搞不明白,fromname只能是nil,如果不这样写对方就收不到信息,如果你找到原因了也希望能回复一下
王集鹄 2002-09-30
  • 打赏
  • 举报
回复
(*//
声明:
本人保证所提供的方法是所知的最好方法
解答问题纯属公益性质
所以请不要向我追问
如果有时间自会关注后续问题
分析:<NULL>
问题:如何使用netsend发送消息?
设计:Zswang
日期:2002-09-30
附言:自己看吧我没有时间
//*)

(*//
标题:网络消息
说明:利用WINNT的NET程序发送消息
设计:Zswang
日期:2002-07-25
支持:wjhu111@21cn.com
注意:系统必须是WinNT
//*)

unit NetSendMessageUnit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TFormNetSendMessage = class(TForm)
ButtonSend: TButton;
ComboBoxHost: TComboBox;
ComboBoxNote: TComboBox;
LabelHost: TLabel;
LabelNote: TLabel;
procedure ButtonSendClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ComboBoxNoteKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;

var
FormNetSendMessage: TFormNetSendMessage;

implementation

{$R *.DFM}

uses FuncUnit;

const
cFileNameHost = 'HostList.txt';
cFileNameNote = 'NoteList.txt';

procedure TFormNetSendMessage.ButtonSendClick(Sender: TObject);
var
I: Integer;
begin
if Trim(ComboBoxHost.Text) = '' then Exit;
WinExec(PChar(Format('net send %s "%s"',
[ComboBoxHost.Text, ComboBoxNote.Text])), SW_HIDE);
I := ComboBoxHost.Items.IndexOf(ComboBoxHost.Text);
if I < 0 then
ComboBoxHost.Items.Add(ComboBoxHost.Text)
else ComboBoxHost.Items.Move(I, 0);
I := ComboBoxNote.Items.IndexOf(ComboBoxNote.Text);
if I < 0 then
ComboBoxNote.Items.Add(ComboBoxNote.Text)
else ComboBoxNote.Items.Move(I, 0);
end;

procedure TFormNetSendMessage.FormCreate(Sender: TObject);
begin
Application.Title := 'Net Send Message 1.0';
Caption := Application.Title;
if FileExists(ExePath + cFileNameHost) then
ComboBoxHost.Items.LoadFromFile(ExePath + cFileNameHost);
if FileExists(ExePath + cFileNameNote) then
ComboBoxNote.Items.LoadFromFile(ExePath + cFileNameNote);
ComboBoxHost.ItemIndex := 0;
ComboBoxNote.ItemIndex := 0;
end;

procedure TFormNetSendMessage.FormDestroy(Sender: TObject);
begin
ComboBoxHost.Items.SaveToFile(ExePath + cFileNameHost);
ComboBoxNote.Items.SaveToFile(ExePath + cFileNameNote);
end;

procedure TFormNetSendMessage.ComboBoxNoteKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
case Key of
VK_BACK, VK_DELETE, VK_LEFT, VK_RIGHT, VK_DOWN, VK_UP: ;
else ComboBoxComplete(TComboBox(Sender), False);
end;
end;

end.


object FormNetSendMessage: TFormNetSendMessage
Left = 167
Top = 180
Width = 538
Height = 88
Caption = 'FormNetSendMessage'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
DesignSize = (
530
61)
PixelsPerInch = 96
TextHeight = 13
object LabelHost: TLabel
Left = 0
Top = 8
Width = 22
Height = 13
Caption = '&Host'
FocusControl = ComboBoxHost
end
object LabelNote: TLabel
Left = 167
Top = 8
Width = 23
Height = 13
Caption = '¬e'
FocusControl = ComboBoxNote
end
object ButtonSend: TButton
Left = 451
Top = 32
Width = 75
Height = 25
Anchors = [akTop, akRight]
Caption = '&Send'
TabOrder = 0
OnClick = ButtonSendClick
end
object ComboBoxHost: TComboBox
Left = 24
Top = 3
Width = 137
Height = 21
ItemHeight = 13
TabOrder = 1
Text = 'ComboBoxHost'
OnKeyUp = ComboBoxNoteKeyUp
end
object ComboBoxNote: TComboBox
Left = 192
Top = 3
Width = 335
Height = 21
Anchors = [akLeft, akTop, akRight]
ItemHeight = 13
TabOrder = 2
Text = 'ComboBoxNote'
OnKeyUp = ComboBoxNoteKeyUp
end
end
上海老李 2002-09-30
  • 打赏
  • 举报
回复
我没用过,帮你UP下!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧