托盘图标的问题?怎么让弹出式菜单消失 ( 积分: 100 )

  • 主题发起人 主题发起人 ls2000
  • 开始时间 开始时间
L

ls2000

Unregistered / Unconfirmed
GUEST, unregistred user!
增加到托盘<br> &nbsp;with nid do<br> &nbsp; begin<br> &nbsp; &nbsp;cbSize:=sizeof(TNOTIFYICONDATA);<br> &nbsp; &nbsp;Wnd:=handle;<br> &nbsp; &nbsp;uID:=0;<br> &nbsp; &nbsp;uFlags:=NIF_ICON +NIF_TIP +NIF_MESSAGE;<br> &nbsp; &nbsp;uCallbackMessage:=MsgICON;<br> &nbsp; &nbsp;hIcon:=application.Icon.Handle ;<br> &nbsp; &nbsp;strpcopy(szTip,'日程安排');<br> &nbsp; End;<br> &nbsp;Shell_NotifyIcon(NIM_ADD, @nid);<br><br>消息处理函数<br>procedure TfrmMain.dealmsg(var msg: Tmessage); &nbsp;//Deal user message<br>begin<br> case msg.LParam of<br> &nbsp; WM_LBUTTONDOWN:<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; end;<br> &nbsp; WM_RBUTTONDOWN:<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;getCursorpos(Curpos);<br> &nbsp; &nbsp; &nbsp; &nbsp;mnupop.Popup(curpos.x,curpos.y);<br> &nbsp; &nbsp; end;<br> end;<br>end;<br>现在很烦人的是,弹出菜单后,除非你选择了其中的一项,否则在失去焦点后,那个弹出式菜单不能自动消失?我看一般的程序在失去焦点后,弹出式菜单能自动消失的!不知那位能帮我解决这个问题!<br>急呀!送100分!
 
增加到托盘<br> &nbsp;with nid do<br> &nbsp; begin<br> &nbsp; &nbsp;cbSize:=sizeof(TNOTIFYICONDATA);<br> &nbsp; &nbsp;Wnd:=handle;<br> &nbsp; &nbsp;uID:=0;<br> &nbsp; &nbsp;uFlags:=NIF_ICON +NIF_TIP +NIF_MESSAGE;<br> &nbsp; &nbsp;uCallbackMessage:=MsgICON;<br> &nbsp; &nbsp;hIcon:=application.Icon.Handle ;<br> &nbsp; &nbsp;strpcopy(szTip,'日程安排');<br> &nbsp; End;<br> &nbsp;Shell_NotifyIcon(NIM_ADD, @nid);<br><br>消息处理函数<br>procedure TfrmMain.dealmsg(var msg: Tmessage); &nbsp;//Deal user message<br>begin<br> case msg.LParam of<br> &nbsp; WM_LBUTTONDOWN:<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; end;<br> &nbsp; WM_RBUTTONDOWN:<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;getCursorpos(Curpos);<br> &nbsp; &nbsp; &nbsp; &nbsp;mnupop.Popup(curpos.x,curpos.y);<br> &nbsp; &nbsp; end;<br> end;<br>end;<br>现在很烦人的是,弹出菜单后,除非你选择了其中的一项,否则在失去焦点后,那个弹出式菜单不能自动消失?我看一般的程序在失去焦点后,弹出式菜单能自动消失的!不知那位能帮我解决这个问题!<br>急呀!送100分!
 
弹出之前先 SetForegroundWindow(自己窗口句柄); 试试 <br><br>http://vipdown1.axdisk.cn/liumazi/Demo/ShuRuFa.rar
 
同意,我的程序开始一样的问题<br>加SetForegroundWindow之后好很多(还是会有一些情况不消失)
 
procedure TfmMain.WMSysCommand(var Msg: TMessage);<br>begin<br> &nbsp;if Msg.WParam = SC_ICON then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Visible := False;<br> &nbsp; &nbsp; &nbsp;Shell_NotifyIcon(NIM_ADD, @Nid);<br> &nbsp; &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;inherited;<br>end;<br><br>procedure TfmMain.WMTrayMessage(var Msg: TMessage);<br>var<br> &nbsp;p: TPoint;<br>begin<br> &nbsp;if Msg.LParam = WM_LBUTTONDOWN then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Visible := True;<br> &nbsp; &nbsp; &nbsp;Shell_NotifyIcon(NIM_DELETE, @Nid);<br> &nbsp; end<br> &nbsp;else if Msg.LParam = WM_RBUTTONDOWN then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;SetForegroundWindow(Handle);<br> &nbsp; &nbsp; &nbsp;GetCursorPos(p);<br> &nbsp; &nbsp; &nbsp;pmTray.Popup(p.X, p.Y);<br> &nbsp; &nbsp;end;<br>end;
 
找个小控件自己研究一下吧,很常见的。
 
谢谢刘麻子,呵呵!<br>你的方法可行!
 
另外你们能把主窗体隐藏吗?设置visible:=false;根本不行的,我是设置frmMain.top=19999;当今后显示器屏幕到达20000*X的时候才会出现问题吧
 
frmMain.hide
 
后退
顶部