打印本文 打印本文 关闭窗口 关闭窗口
How can I create a tray icon
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4145  更新时间:2009/4/23 18:27:19  文章录入:mintao  责任编辑:mintao
nbsp;    DblClick;
        WM_MBUTTONDOWN:
          begin
            Shift := ShiftState + [ssMiddle];
            GetCursorPos(Pt);
            DoMouseDown(mbMiddle, Shift, Pt.X, Pt.Y);
          end;
        WM_MBUTTONUP:
          begin
            Shift := ShiftState + [ssMiddle];
            GetCursorPos(Pt);
            DoMouseUp(mbMiddle, Shift, Pt.X, Pt.Y);
          end;
        WM_MBUTTONDBLCLK:
          DblClick;
      end;
  end;
end;

{ Set a new hint, which is the tool tip for the shell icon. }
procedure TTrayIcon.SetHint(const Hint: string);
begin
  if fHint <> Hint then
  begin
    fHint := Hint;
    StrPLCopy(fData.szTip, Hint, SizeOf(fData.szTip) - 1);
    if Hint <> '''''''' then
      fData.uFlags := fData.uFlags or Nif_Tip
    else
      fData.uFlags := fData.uFlags and not Nif_Tip;
    Changed;
  end;
end;

{ Set a new icon. Update the system tray. }
procedure TTrayIcon.SetIcon(Icon: TIcon);
begin
  if fIcon <> Icon then
  begin
    fIcon.Assign(Icon);
    fData.hIcon := Icon.Handle;
    Changed;
  end;
end;

{
  When the user right clicks the icon, call DoMenu.
  If there is a popup menu, and if the window is minimized,
  then popup the menu.
}

procedure TTrayIcon.DoMenu;
var
  Pt: TPoint;
begin
  if (fPopupMenu <> niland not IsWindowVisible(Application.Handle) then
  begin
    GetCursorPos(Pt);
    fPopupMenu.Popup(Pt.X, Pt.Y);
  end;
end;

procedure TTrayIcon.Click;
begin
  if Assigned(fOnClick) then
    fOnClick(Self);
end;

procedure TTrayIcon.DblClick;
begin
  if Assigned(fOnDblClick) then
    fOnDblClick(Self);
end;

procedure TTrayIcon.DoMouseMove(Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(fOnMouseMove) then
    fOnMouseMove(Self, Shift, X, Y);
end;

procedure TTrayIcon.DoMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(fOnMouseDown) then
    fOnMouseDown(Self, Button, Shift, X, Y);
end;

procedure TTrayIcon.DoMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(fOnMouseUp) then
    fOnMouseUp(Self, Button, Shift, X, Y);
end;

{
  When the application minimizes, hide it, so only the icon
  in the system tray is visible.
}
procedure TTrayIcon.Minimize;
begin
  ShowWindow(Application.Handle, SW_HIDE);
  if Assigned(fOnMinimize) then
    fOnMinimize(Self);
end;

{
  Restore the application by making its window visible again,
  which is a little weird since its window is invisible, having
  no height or width, but that''''s what determines whether the button
  appears on the taskbar.
}

procedure TTrayIcon.Restore;
begin
  ShowWindow(Application.Handle, SW_RESTORE);
  if Assigned(fOnRestore) then
    fOnRestore(Self);
end;

{ Allow Windows to exit by deleting the shell notify icon. }
procedure TTrayIcon.EndSession;
begin
  Shell_NotifyIcon(Nim_Delete, @fData);
end;

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口