⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.pas

📁 Mailserver Source code - Delphi. Simple Mail server source code. SMTP and POP3 protocols.
💻 PAS
字号:
unit FrmMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Menus,shellapi,inifiles;

const
  WM_TRAYICON = WM_APP + 134;                                    //定义系统托盘常量

type
  TFrmMain1 = class(TForm)
    TrayIconPopupMenu: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
    procedure WMTrayIcon(var message: TMessage); message WM_TRAYICON;
    procedure ModifyTrayIcon(Action: DWORD);

  public
    { Public declarations }
  end;

var
  FrmMain1: TFrmMain1;

implementation

uses UnitMailServer, FrmAboutBox;


{$R *.dfm}

procedure TFrmMain1.FormCreate(Sender: TObject);
begin
  ModifyTrayIcon(NIM_ADD);
  FrmMain1.Left:=screen.Width+1000;
  setwindowlong(application.handle, gwl_exstyle,getwindowlong(application.handle, gwl_exstyle)
     or ws_ex_toolwindow and not ws_ex_appwindow);
end;

//系统托盘菜单------------------------------------------------------------------
procedure TFrmMain1.WMTrayIcon(var message: TMessage);
var
  MousePos: TPoint;
begin
  try
    if message.LPARAM = WM_RBUTTONDOWN then         //处理单击事件
    begin
      GetCursorPos(MousePos);
      TrayIconPopupMenu.Popup(MousePos.X, MousePos.Y);
    end;
  finally
  end;
end;
//------------------------------------------------------------------------------

//系统托盘图标------------------------------------------------------------------
procedure TFrmMain1.ModifyTrayIcon(Action: DWORD);
var
  NIData: TNotifyIconData;
begin
  try
    with NIData do
    begin
      cbSize := sizeof(TNotifyIconData);
      UID := 0;
      uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      Wnd := Handle;
      uCallBackMessage := WM_TRAYICON;
      HICON:=Application.Icon.Handle;
      StrPCopy(szTip, Application.Title);
    end;
    Shell_NotifyIcon(Action, @NIData);
  finally
  end;
end;
//------------------------------------------------------------------------------

procedure TFrmMain1.N1Click(Sender: TObject);
begin
  ModifyTrayIcon(NIM_DELETE);
  application.Terminate;
end;

procedure TFrmMain1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ModifyTrayIcon(NIM_DELETE);
end;

procedure TFrmMain1.FormDestroy(Sender: TObject);
begin
  ModifyTrayIcon(NIM_DELETE);
end;

procedure TFrmMain1.N2Click(Sender: TObject);
begin
  FrmAboutBox1.show;  
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -