unit U_Main;
interface
uses
// Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
// Dialogs, Menus, ImgList;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Gauges, StdCtrls, Menus,shellapi, ExtCtrls, Buttons,
mmsystem, ImgList, ComCtrls, RzEdit, ToolWin,inifiles;
type
//------------------定义托盘图标的数据类型 ---------------------------
PNotifyIconData = ^TNotifyIconDataA;
TNotifyIconDataA = record
cbSize : DWORD;
Wnd : HWND;
uID : UINT;
uFlags : UINT;
uCallbackMessage : UINT;
hIcon : HICON;
szTip : array [0..63] of AnsiChar;
end;
//----------------------------------------------------------------------
type
TFr_Client = class(TForm)
PopupMenu1: TPopupMenu;
Nmain: TMenuItem;
Nabout: TMenuItem;
Nexit: TMenuItem;
ImageList1: TImageList;
Panel1: TPanel;
RzRichEdit1: TRzRichEdit;
Panel2: TPanel;
Splitter1: TSplitter;
Panel3: TPanel;
RzRichEdit2: TRzRichEdit;
Panel4: TPanel;
PopupMenu2: TPopupMenu;
Enter1: TMenuItem;
Enter2: TMenuItem;
FontDialog1: TFontDialog;
ToolBar1: TToolBar;
Tfont: TToolButton;
Tbold: TToolButton;
Tita: TToolButton;
Tunder: TToolButton;
Tface: TToolButton;
Tie: TToolButton;
Tmess: TToolButton;
PopupMenu3: TPopupMenu;
N1: TMenuItem;
Panel5: TPanel;
Bsend: TButton;
Bdown: TButton;
Label1: TLabel;
Button1: TButton;
N2: TMenuItem;
N3: TMenuItem;
function CurrText: TTextAttributes;
procedure NexitClick(Sender: TObject);
procedure NaboutClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure NmainClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BdownClick(Sender: TObject);
procedure Enter1Click(Sender: TObject);
procedure Enter2Click(Sender: TObject);
procedure TfontClick(Sender: TObject);
procedure TboldClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure TitaClick(Sender: TObject);
procedure TunderClick(Sender: TObject);
procedure N3Click(Sender: TObject);
private
{ Private declarations }
//-------------------------------------------------------------
IconData: TNotifyIconData;
procedure ShowIcon;
procedure IconOnClick(var message:TMessage); message WM_USER+1;
Procedure WMSysCommand(Var message : TMessage) ; Message WM_SYSCOMMAND ;
//-------------------------------------------------------------
public
{ Public declarations }
end;
var
Fr_Client: TFr_Client;
//全程变量
Tray:integer;
ini:Tinifile;
app:string;
implementation
uses Uabout, USM;
{$R *.dfm}
function TFr_Client.CurrText: TTextAttributes;
begin
if RzRichEdit2.SelLength > 0 then
Result := RzRichEdit2.SelAttributes
else
Result := RzRichEdit2.DefAttributes;
end;
//托盘图标事件
procedure TFr_Client.IconOnClick(var message: Tmessage);
var p : TPoint;
begin
if (message.lParam = WM_LBUTTONDOWN) then
begin
ShowWindow(Handle, SW_Show )
end;
if (message.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
SetForegroundWindow (Application.Handle); //avoid a little bug.
Application.ProcessMessages;
popupmenu1.Popup( p.x ,p.y );
end;
end;
Procedure TFr_Client.WMSysCommand(Var Message : TMessage) ;
begin
//最小化显示托盘图标
if (Message.WParam = SC_MINIMIZE) or (Message.WParam =SC_CLOSE) then
begin
if Tray=0 then begin
ShowIcon;
Tray:=1
end else
begin
Shell_NotifyIcon( NIM_DELETE, @IconData );
ShowIcon;
end;
end
else
Inherited;
end;
procedure TFr_Client.ShowIcon;
begin
IconData.cbSize := SizeOf( IconData );
IconData.Wnd := Handle;
IconData.uID :=1;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallBackMessage :=WM_USER+1;
IconData.hIcon := application.Icon.Handle;
IconData.szTip := '信息接收系统';
Shell_NotifyIcon( NIM_ADD, @IconData );
ShowWindow(Handle, SW_HIDE);
hide;
end;
procedure TFr_Client.NexitClick(Sender: TObject);
begin
close;
end;
procedure TFr_Client.NaboutClick(Sender: TObject);
begin
Fr_about.show;
end;
procedure TFr_Client.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=cafree;
Shell_NotifyIcon( NIM_DELETE, @IconData ); //清除托盘图标
end;
procedure TFr_Client.FormShow(Sender: TObject);
begin
Tray:=0;
end;
procedure TFr_Client.NmainClick(Sender: TObject);
begin
ShowWindow(Handle, SW_SHOW );
end;
procedure TFr_Client.FormCreate(Sender: TObject);
begin
showwindow(application.Handle,sw_hide);
setwindowlong(application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //隐藏
//SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW);不隐藏
ShowIcon;
end;
procedure TFr_Client.FormActivate(Sender: TObject);
begin
showwindow(application.Handle,sw_hide);
end;
end.