📄 1.txt
字号:
unit fsdx;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, OoMisc, AdPort,ShellApi, Menus;
const
wm_iconclick = wm_user + 100;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Ed_hm: TEdit;
Panel1: TPanel;
Panel2: TPanel;
M_nr: TMemo;
BitBtn1: TBitBtn;
ApdComPort: TApdComPort;
BitBtn2: TBitBtn;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure N1Click(Sender: TObject);
private
icdata : Tnotifyicondata;
procedure InstallIcon;
procedure Trayiconmessage(var msg :Tmessage);message wm_iconclick;
{ Private declarations }
public
function SEncodeMobNO(SmobNO: string): string;
function EncodeChinese(Input: WideString): string;//将信息内容进行PDU编码
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.EncodeChinese(Input: WideString): string;
var
i: Integer;
begin
Result := '';
for i := 1 to Length(Input) do
Result := Result + Format('%4.4X', [ord(Input[i])]);
end;
function TForm1.SEncodeMobNO(SmobNO: string): string;
//要想发送中文短信必须使用Modem的PDU方式。这个函数是将手机号码进行PDU编码。
var
TempPchar: Pchar;
i: integer;
Str: string;
begin
if (copy(smobno, 1, 1) = '+') then //判断是否包含国家编码
SmobNO := copy(smobno, 2, length(smobno) - 1); //去掉手机号码中的’+’
if ((length(SmobNO) mod 2) = 1) then
SmobNO := SmobNO + 'F';
TempPchar := Pchar(SmobNO); //将字符串 Char数组化
i := 0;
Str := '';
while i < length(TempPchar) do begin
Str := Str + TempPchar[i + 1] + TempPchar[i];
i := i + 2;
end;
result := Str;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Icdata.cbSize := sizeof(tnotifyicondataa);
Icdata.wnd := handle;
Icdata.uID := 100;
Icdata.uFlags := nif_icon + nif_tip + nif_message;
Icdata.uCallbackMessage := wm_iconclick;
Icdata.hIcon := Application.Icon.handle;
Icdata.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @Icdata);
Application.Terminate;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
Var
apdcomport:Tapdcomport;
r,s,s2,s3,s4,s5:string;
cmdlong,tmp:integer;
//msgs:WideString;
begin
if (ed_hm.Text = '') then
begin
Application.MessageBox('发送对象不能为空,请填写!','提示',mb_ok+mb_iconinformation);
Exit;
end;
try
ApdComPort := Tapdcomport.Create(nil); //创建串口通信对象
ApdComPort.AutoOpen := false;
apdcomport.ComNumber:=1;//设置串行通信口
apdcomport.Baud:=9600;//设置串口波特率
//msgs:=msg;
s:='0031000D9168';
//PDU编码属性,这种方法是不需要设置短信中心号码的,因为现的手机SIM卡已经写好了
s2:=SEncodeMobNO(ed_hm.Text);//对手机号码进行PDU编码
s3:='0008A7';
s4:='';
s5:=EnCodeChinese(M_nr.Text);
tmp:=length(s5)div 2;
s4:=format('%X',[tmp]);
if length(s4)<2 then
s4:='0'+s4;
//计算PDU编码长度
r:=s+s2+s3+s4+s5+^Z;
cmdlong:=(length(r)-2) div 2;
apdcomport.Open:=true;//打开串行口
apdcomport.Output:='AT+CMGF=0'#13;//设置Modem为PDU模式
delayticks(7,true);//延时
apdcomport.Output:='AT+CMGS='+inttostr(cmdlong)+#13;//设置信息长度,这里应为PDU编码长度的1/2.
delayticks(7,true);
apdcomport.Output:=r;//发送短信。
delayticks(9,true);
apdcomport.Open:=false;
apdcomport.Free;
Application.MessageBox('发送成功!','提示',mb_ok+mb_iconinformation);
except
Application.MessageBox('发送失败!','提示',mb_ok+mb_iconinformation);
end;
end;
procedure TForm1.InstallIcon;
begin
icdata.cbSize := sizeof(Tnotifyicondata);
icdata.Wnd := Handle;
icdata.uID:= 1;
icdata.uFlags := nif_icon or nif_message or nif_tip;
icdata.uCallbackMessage := wm_iconclick;
icdata.hIcon := Loadicon(Hinstance,'Mainicon');
icdata.szTip := '短信收发程序';
shell_notifyicon(nim_add,@icdata);
form1.Visible := false;
end;
procedure TForm1.Trayiconmessage(var msg: Tmessage);
var
mousept : Tpoint;
begin
{ if msg.LParam = wm_lbuttondown then begin
ShowWindow(Handle, SW_SHOW);
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
Application.Restore;
end;
if msg.WParam = sc_icon then
begin
form1.Visible := false;
//showwindow(handle,sw_hide);
//showwindow(Application.handle, SW_hide);
end;}
inherited;
if msg.LParam = wm_rbuttonup then begin //用鼠标右键点击图标
getcursorpos(mousept); //获取光标位置
popupmenu1.popup(mousept.x, mousept.y);
//在光标位置弹出选单
end;
if msg.LParam = wm_lbuttonup then
begin //用鼠标左键点击图标
//显示应用程序窗口
ShowWindow(Handle, SW_SHOW);
//在任务栏上显示应用程序窗口
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
end;
msg.Result := 0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InstallIcon;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
icdata.uFlags := 0;
shell_notifyicon(NiM_delete,@icdata);
//form1.Visible := false;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{Action := cafree;
Showwindow(Handle,sw_hide);
Shell_notifyicon(Nim_Delete,@icdata);
{SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
// form1.Visible := false; }
Action := caNone; //不对窗体进行任何操作
ShowWindow(Handle, SW_HIDE); //隐藏主窗体
//隐藏应用程序窗口在任务栏上的显示
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
end;
procedure TForm1.N1Click(Sender: TObject);
begin
Icdata.cbSize := sizeof(tnotifyicondataa);
Icdata.wnd := handle;
Icdata.uID := 100;
Icdata.uFlags := nif_icon + nif_tip + nif_message;
Icdata.uCallbackMessage := wm_iconclick;
Icdata.hIcon := Application.Icon.handle;
Icdata.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @Icdata);
Application.Terminate;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -