DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: eyang11
今日帖子: 1
在线用户: 9
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 08ms (WingKernel) ★☆☆☆☆ -
盒子活跃会员
2004/4/14 13:19:33
标题:
系统托盘问题 浏览:1150
加入我的收藏
楼主: 怎么样才能在系统托盘的图标上点出菜单?
----------------------------------------------
按此在新窗口浏览图片
I want a click, a click to your heart
A hyperlink into you.
A sexual browser from here to the end
A newsgroup one on one
Don't need a modem to connect to your mind 
No search engine to find you
作者:
男 08ms (WingKernel) ★☆☆☆☆ -
盒子活跃会员
2004/4/14 15:25:53
1楼: 自己顶
----------------------------------------------
按此在新窗口浏览图片
I want a click, a click to your heart
A hyperlink into you.
A sexual browser from here to the end
A newsgroup one on one
Don't need a modem to connect to your mind 
No search engine to find you
作者:
男 08ms (WingKernel) ★☆☆☆☆ -
盒子活跃会员
2004/4/14 16:04:37
2楼: 自己顶
~!!
----------------------------------------------
按此在新窗口浏览图片
I want a click, a click to your heart
A hyperlink into you.
A sexual browser from here to the end
A newsgroup one on one
Don't need a modem to connect to your mind 
No search engine to find you
作者:
女 shyh (沐曦) ★☆☆☆☆ -
盒子活跃会员
2004/4/14 16:15:56
3楼: 加一个popmenu
----------------------------------------------
-
作者:
男 willing (willing) ★☆☆☆☆ -
禁用账号
2004/4/14 17:15:43
4楼: ……
被禁用帐号,帖子内容自动屏蔽!
……

----------------------------------------------
按此在新窗口浏览图片
作者:
男 08ms (WingKernel) ★☆☆☆☆ -
盒子活跃会员
2004/4/14 22:30:52
5楼: 在图标点 左右键 可以弹出菜单
----------------------------------------------
按此在新窗口浏览图片
I want a click, a click to your heart
A hyperlink into you.
A sexual browser from here to the end
A newsgroup one on one
Don't need a modem to connect to your mind 
No search engine to find you
作者:
男 hbqckzj (醉里寻欢) ★☆☆☆☆ -
盒子活跃会员
2004/4/15 7:38:53
6楼: 最简单的办法是找个控件,这样的控件满地都是!

如果想复杂点呢,就看看下面这段代码,绝对可以通过。

1、首先要在uses中加上shellapi
2、再定义一个常量,名字可任意起,本例中是ghy_tray
3、然后还要自定义一个过程procedure mytray(var Msg: TMessage); message ghy_tray;,用于托盘接收鼠标事件(如果不需要这个功能,第2、3步可以省了)
4、定义变量  tray1:TNotifyIconData;
             ico1:ticon;
5、然后在form_creat事件中加上一些变量和常量的赋值即可,详见下程;
6、需要添加托盘图标时用Shell_NotifyIcon(NIM_ADD,@tray1);
7、需要移去托盘图标时用Shell_NotifyIcon(NIM_delete,@tray1);

unit Unit1;

interface

uses
  shellapi,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AppEvnts, ImgList, StdCtrls, Menus;
const
  ghy_tray=wm_user+2;
type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    Button1: TButton;
    Button2: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure mytray(var Msg: TMessage); message ghy_tray;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  tray1:TNotifyIconData;
  ico1:ticon;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ico1:=ticon.Create;
imagelist1.GetIcon(0,ico1);
tray1.cbSize:=sizeof(tray1);
tray1.Wnd:=form1.Handle;
tray1.uID:=0;
tray1.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
tray1.uCallbackMessage:=ghy_tray;
tray1.hIcon:=ico1.Handle;
tray1.szTip:='我的托盘程序';

Shell_NotifyIcon(NIM_ADD,@tray1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Shell_NotifyIcon(NIM_delete,@tray1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Shell_NotifyIcon(NIM_add,@tray1);
end;

procedure tform1.mytray(var Msg: TMessage);
var
pt:tpoint;
begin
GetCursorPos(pt);
if msg.lParam=WM_LBUTTONDOWN then  {鼠标左键被按下时,执行下面语句}
   begin
     if form1.Visible ={wsMinimized}true then
        begin
           application.Minimize;
           form1.Hide;
        end
     else
        begin
           form1.Show;
           form1.WindowState:=wsnormal;
        end
   end
else if msg.lParam=WM_LBUTTONUP then {左键被放起时,释放鼠标左键}
   begin
   end
else if msg.lParam=wm_rbuttondown then  {鼠标右键被按下,执行下面语句}
   begin
      SetForegroundWindow(Form1.Handle);
      form1.PopupMenu1.Popup(pt.x,pt.y);
   end
else      {调用父类的WndProc方法处理其它消息}
   inherited;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_delete,@tray1);
end;


procedure TForm1.N1Click(Sender: TObject);
begin
showmessage('谢谢你使用这个托盘演示程序');
end;

procedure TForm1.N2Click(Sender: TObject);
begin
application.Terminate;
end;

end.

上述例程运行时,自动在托盘区加载了一个图标,当你点击主窗体中的按钮1时,图标可以移去,点击按钮2时,图标可以添加;当你在托盘图标上单击时,主窗体在隐藏与显示之间切换,当你在托盘图标上右击时,弹出一个菜单,选择第一项时,弹出对话框“谢谢你使用这个托盘演示程序”,选择第二项时,程序退出。

上面例程在winxp和delphi 7.0中运行通过!
----------------------------------------------
秋风清 秋月明,几上闲琴黯生尘。
夜来忽忆少年事,陌上柳绿草青青。
相逢一笑言未语,携手相看自倾心。
二十二载云烟里,云含风韵烟含情。
风尘渺落风霜浸,但闻长空雁长鸣。
姿容如花颜如玉,只在平生梦里寻。
秋风清 秋月明,秋灯秋雨愁煞人。
天涯路远人何在,午夜梦回空扰惊。
作者:
男 08ms (WingKernel) ★☆☆☆☆ -
盒子活跃会员
2004/4/15 11:59:17
7楼: 多谢了,调试通过
不过还有一个问题

在执行WM_LBUTTONDOWN
怎么判断程序为当前窗口???????????
?????????????????????????????????
----------------------------------------------
按此在新窗口浏览图片
I want a click, a click to your heart
A hyperlink into you.
A sexual browser from here to the end
A newsgroup one on one
Don't need a modem to connect to your mind 
No search engine to find you
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行76.17188毫秒 RSS