📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
shellapi, StdCtrls, ExtCtrls, ImgList, Menus, AppEvnts, XPMan, OleCtrls,
Chartfx3;
const
WM_MYNOTIFY = WM_USER + 1000 ;//消息
strNotifyTip='菜单栏图标';//提示
ID_MAIN = 100 ; // 定义图标的ID
type
TForm1 = class(TForm)
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
N1231: TMenuItem;
N4561: TMenuItem;
XPManifest1: TXPManifest;
Button1: TButton;
Button2: TButton;
N1: TMenuItem;
N2: TMenuItem;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure N4561Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Function AddIcon(hwnd : HWND):Boolean ;
Function RemoveIcon(hwnd:HWND):Boolean ;
Procedure MyNotify(var Msg:TMessage);message WM_MYNOTIFY;
end;
var
Form1: TForm1;
ico1,ico2:ticon;
tags:boolean;
implementation
uses main;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
AddIcon(handle);
end;
//以下函数加入图标,可在程序初始化时加入。
Function TForm1.AddIcon(hwnd : HWND):Boolean ;
var
nid : NOTIFYICONDATA ;
begin
nid.cbSize := sizeof(NOTIFYICONDATA);
nid.Wnd := hwnd;
nid.uID := ID_MAIN;
nid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage := WM_MYNOTIFY;
ico1:=ticon.Create;
//ico2:=ticon.create;
imagelist1.GetIcon(0,ico1);
//imagelist1.geticon(1,ico2);
nid.hIcon :=ico1.Handle ;
//nid.hIcon := LoadIcon(hInstance,'D:\Delphi7\johu\c菜单图标\图标2.ico');
strCopy(nid.szTip,strNotifyTip);
AddIcon := Shell_NotifyIcon(NIM_ADD, @nid);
end ;
Function TForm1.RemoveIcon(hwnd:HWND):Boolean ;
var
nid : NOTIFYICONDATA;
begin
nid.cbSize := sizeof(NOTIFYICONDATA);
nid.Wnd := hwnd;
nid.uID := ID_MAIN;
nid.uFlags := 0;
RemoveIcon := Shell_NotifyIcon(NIM_Delete, @nid);
end ;
procedure TForm1.FormDestroy(Sender: TObject);
begin
RemoveIcon(handle);
end;
Procedure TForm1.MyNotify(var Msg:TMessage);
var
pt:tpoint;
begin
GetCursorPos(pt);
case msg.lParam of
WM_LBUTTONDOWN:
begin
//鼠标左键被按下
if tags=true then
begin //不执行
end
else //执行
begin
application.Minimize;
//Application.MessageBox('Left button click' ,'My Notify',MB_OK);
Form1.Hide;
application.Restore;
end;
end;
WM_LBUTTONUP:
begin
//释放鼠标左键
end;
wm_rbuttondown:
begin
//鼠标右键被按下
//SetForegroundWindow(FormMail.Handle);
Form1.PopupMenu1.Popup(pt.x,pt.y);
end
else//调用父类的WndProc方法处理其它消息
inherited;
end;
END;
procedure TForm1.N4561Click(Sender: TObject);
begin
//退出记录本菜单按钮
//退出整个程序(带有询问)
if application.MessageBox('确定要退出本系统吗?','johu@yeah.net',mb_yesno+mb_iconquestion)=mryes then
application.Terminate
else
abort;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
frmmain.Show;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
PostMessage(frmmain.Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
end;
procedure TForm1.N1Click(Sender: TObject);
begin
postmessage(frmmain.Handle,WM_SYSCOMMAND,SC_MAXIMIZE,0);
end;
END.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -