//窗体最小化时用来显示托盘图标的操作,应该就是这些函数了,以前作了个demo找不到了
function AddIcon(hwnd:HWND):Boolean;
procedure minimize(sender: Tobject);
function RemoveIcon(hwnd: HWND): Boolean;
procedure RestoreRequest(var message: TMessage);
message CM_RESTORE;
procedure Notify(var Msg: TMessage);
message vg_Mdi_APP_NAME;
var
vg_nid: NOTIFYICONDATA;
function TfrmMdiMainMenuEntry.AddIcon(hwnd: HWND): Boolean;
begin
vg_nid.cbSize := sizeof(NOTIFYICONDATA);
//加载托盘图标
vg_nid.Wnd := hwnd;
vg_nid.uID := vg_ID_MAIN;
vg_nid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
vg_nid.uCallbackMessage := vg_Mdi_APP_NAME;
vg_nid.hIcon := LoadIcon(hInstance, 'MAINICON');
strCopy(vg_nid.szTip, vg_strNotifyTip);
AddIcon := Shell_NotifyIcon(NIM_ADD, @vg_nid);
end;
procedure TfrmMdiMainMenuEntry.minimize(sender: Tobject);
begin
AddIcon(handle);
//托盘图标
ShowWindow(Application.handle, sw_hide)
end;
function TfrmMdiMainMenuEntry.RemoveIcon(hwnd: HWND): Boolean;
begin
vg_nid.cbSize := sizeof(NOTIFYICONDATA);
//取消托盘图标
vg_nid.Wnd := hwnd;
vg_nid.uID := vg_ID_MAIN;
vg_nid.uFlags := 0;
RemoveIcon := Shell_NotifyIcon(NIM_DELETE, @vg_nid);
end;
procedure TfrmMdiMainMenuEntry.FormDestroy(Sender: TObject);
begin
RemoveIcon(handle);
end;
procedure TfrmMdiMainMenuEntry.RestoreRequest(var message: TMessage);
begin
if IsIconic(Application.Handle) = True then
Application.Restore
else
Application.BringToFront;
end;
procedure TfrmMdiMainMenuEntry.Notify(var Msg: TMessage);//右击托盘图标触发弹出式菜单
var
Pt: TPoint;
begin
case msg.LParam of
WM_RBUTTONDOWN:
begin
SetForeGroundWindow(vg_nid.wnd);
GetCursorPos(Pt);
Popupmenu.Popup(pt.x, pt.y);
end;
WM_LBUTTONDOWN:
begin
RemoveIcon(handle);
ShowWindow(Application.handle, SW_SHOWNORMAL);
end;
end;
end;
procedure TfrmMdiMainMenuEntry.NShowFormClick(Sender: TObject);//弹出式菜单showform单击事件
begin
RemoveIcon(handle);
ShowWindow(Application.handle, SW_SHOWNORMAL);
end;