Beranda > Delphi > How to send a popup message

How to send a popup message

unit SendPopupMsg;
{only WinNT4.0, Win2000, XP....}
interface

{NetMessageBufferSend sends a buffer of information to a registered message alias. Security Requirements No special group membership is required to execute NetMessage buffer send locally. Admin, accounts, print,or serv.operator group membership is required to successfully execute NetMessageBufferSend on a remote server.


NET_API_STATUS NetMessageBufferSend( LPTSTR servername,LPTSTR msgname, LPTSTR fromname, LPBYTE buf, DWORD buflen );

Parameters

servername - A pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.

msgname - A pointer to a Unicode string containing the message name to which the message buffer should be sent.

(Broadcasts message to every machine logged into the
domain/computer name set WMsgName := DomainName + '*'; )

fromname - A pointer to a Unicode string containing the message name sending the information. fromname is a new parameter for Windows networking. This parameter is needed for sending alerts from the computer name rather than the logged on user. If a NULL is specified the message is send from the logged on user as with LAN Manager 2.x.

buf - A pointer to a buffer of message text.

buflen - The length in bytes of the message text in buf.}

uses Windows;

function NetMessageBufferSend(ServerName: LPCWSTR; MsgName: LPCWSTR; FromName: LPCWSTR; Buf: LPCWSTR;
BufLen: DWORD): DWORD; stdcall; external 'netapi32.dll' name 'NetMessageBufferSend';

function NetMsgSend(const Recipient, MessageText : string) : integer;

procedure SendTextMessage(const Recipient, MessageText : string);

implementation

uses SysUtils, Classes;

type
TNetMsgSender = class(TThread)
private
{ Private declarations }
procedure Execute; override;
protected
{ Protected declarations }
ResultSend : integer;
SendTo     : string;
MsgText    : string;
published
constructor SendNetMSgTo(const Recipient, MessageText : string); virtual;
end;

procedure SendTextMessage(const Recipient,
MessageText : string);
begin
TNetMsgSender.SendNetMSgTo( Recipient , MessageText);
end;

constructor TNetMsgSender.SendNetMSgTo(const Recipient, MessageText : string);
begin
SendTo := Recipient;
MsgText := MessageText;
inherited Create(false);
FreeOnTerminate := true;
Priority := tpLower;
end;

procedure TNetMsgSender.Execute;
begin
ResultSend := NetMsgSend( SendTo, MsgText );
end;

function NetMsgSend(const Recipient, MessageText : string) : integer;
var
WMsgName : WideString;
WMsg : WideString;
MsgLen : integer;
begin
Result := -1;
try
WMsg := MessageText;
MsgLen := Length(WMsg) * 2; // Unicode is 2-byte.
WMsgName := Recipient;
Result := NetMessageBufferSend(nil,
PWideChar(WMsgName), nil,
PWideChar(WMsg), MsgLen);
except
end;
end;

initialization

finalization

end.

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: