📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, DBCtrls, Buttons,unit2, ExtCtrls, ComCtrls,shellapi,
Menus;
const
mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件
iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
GroupBox1: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
DBText1: TDBText;
DBText2: TDBText;
DBMemo1: TDBMemo;
DBMemo2: TDBMemo;
SpeedButton1: TSpeedButton;
StatusBar1: TStatusBar;
PopupMenu1: TPopupMenu;
exit: TMenuItem;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
// procedure exitClickClick(Sender: TObject);
procedure exitClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
procedure mousemessage(var message: tmessage); message mousemsg;
public
{ Public declarations }
end;
var
Form1: TForm1;
ntida:TNotifyIcondataA; //用于增加和删除系统状态图标
function strtosql(text1:string):string;
implementation
{$R *.dfm}
procedure TForm1.mousemessage(var message: tmessage);
var
mousept: TPoint; //鼠标点击位置
begin
inherited;
if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标
getcursorpos(mousept); //获取光标位置
popupmenu1.popup(mousept.x, mousept.y);
//在光标位置弹出选单
end;
if message.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;
message.Result := 0;
end;
function strtosql(text1:string):string;
var
s:string;
n:integer;
begin
for n:= 1 to length(text1) do
begin
if text1[n] <> '''' then
s:=s+text1[n]
else
s:=s+'''''';
end;
result:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Clear;
form1.ADOQuery1.SQL.Add('select * from error_table');
form1.ADOQuery1.sql.Add('where error_id like');
form1.ADOQuery1.sql.Add('''%'+strtosql(edit1.text)+'%''');
form1.ADOQuery1.Open;
if form1.ADOQuery1.RecordCount>=1 then
begin
SpeedButton1.Enabled:= true;
// SpeedButton1.Caption:='>>>';
SpeedButton1.font.Color:=clred;
end
else
begin
form1.Label6.Visible :=true;
form2.Hide ;
SpeedButton1.Caption:='>>>';
SpeedButton1.Enabled:= false;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if SpeedButton1.Caption='>>>' then
begin
SpeedButton1.Caption:='<<<';
form2.show;
end
else
begin
SpeedButton1.Caption:='>>>';
form2.Hide ;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
form1.StatusBar1.SimpleText:=copy(form1.StatusBar1.SimpleText,2,length(form1.StatusBar1.SimpleText));
if form1.StatusBar1.SimpleText='' then
form1.StatusBar1.SimpleText:=' 作者:佘文刚 QQ:44512974 E-mail:swgweb.126.com 我也是个新手,希望多多关照!'
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度
ntida.Wnd := handle; //取应用程序主窗体的句柄
ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使
ntida.uFlags := nif_icon + nif_tip +
nif_message; //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效
ntida.uCallbackMessage := mousemsg;
//指定的窗口消息
ntida.hIcon := Application.Icon.handle;
//指定系统状态栏显示应用程序的图标句柄
ntida.szTip := 'Icon';
//当鼠标停留在系统状态栏该图标上时,出现该提示信息
shell_notifyicona(NIM_ADD, @ntida);
//在系统状态栏增加一个新图标
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if SpeedButton1.Caption='<<<' then
begin
SpeedButton1.Caption:='>>>';
form2.Hide;
end;
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.exitClick(Sender: TObject);
begin
//为ntida赋值,指定各项参数
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @ntida);
//删除已有的应用程序图标
Application.Terminate;
//中断应用程序运行,退出应用程序
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
form1.Label6.Visible :=false;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -