只用一个窗体能否实现托盘?(6分)

  • 主题发起人 主题发起人 delnus
  • 开始时间 开始时间
D

delnus

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; 我写了一个小程序,想实现托盘图标,程序运行时,图标出现了,但是不响应鼠标事件。<br>我定义的消息事件为TNotifyIconData的回调消息。<br>&nbsp; &nbsp; uCallBackMessage:=myMessage;<br>我在别的书上看到了一个程序,不过它是用两个窗体实现的,并且一个为隐藏窗体。<br>&nbsp;<br>
 
procedure tform1.installicon;<br>var<br>icondata:tnotifyicondata;<br>apppath:string;<br>begin<br>yesicon:=ticon.create;<br>AppPath:=ExtractFileDir(Application.ExeName);<br>yesicon.loadfromfile(AppPath+'/normal.ico');<br>icondata.cbsize:=sizeof(icondata);<br>icondata.wnd:=handle;<br>icondata.uid:=icon_id;<br>icondata.uflags:=nif_icon or nif_message or nif_tip;<br>icondata.ucallbackmessage:=mi_iconevent;<br>icondata.hicon:=yesicon.handle;<br>icondata.sztip:='提示';<br>shell_notifyicon(nim_add,@icondata);<br>end;<br>form1create()<br>begin<br>installicon;<br>end;
 
不响应鼠标事件?那你在你的mymessage里是怎么定义的?你应该这样:<br>自定义如下过程 <br>当然在这里我不知道你的消息是属于那类的,一般是WM_USER或WM_APP<br>procedure icononclick(var message:tmessage);message myMessage;<br>............<br>实现代码<br>procedure TForm1.icononclick(var message: tmessage);<br>var<br>&nbsp; &nbsp; &nbsp;p:tpoint;<br>begin<br>&nbsp; &nbsp; &nbsp;//如果按下的是左键<br>&nbsp; &nbsp; &nbsp;if(message.lParam =wm_lbuttondown) then<br>&nbsp; &nbsp; &nbsp;................<br>&nbsp; &nbsp; &nbsp;//如果是按下的右键,则显示弹出菜单<br>&nbsp; &nbsp; &nbsp;if(message.lparam=wm_rbuttondown)then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getcursorpos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; popupmenu1.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>end;<br><br>
 
后退
顶部