“托盘”程序问题?(100分)

  • 主题发起人 主题发起人 zheng
  • 开始时间 开始时间
Z

zheng

Unregistered / Unconfirmed
GUEST, unregistred user!
我用Delphi3做的“托盘”程序当缩小到状态栏是响应右键事件,弹出菜单,<br>但除了第一次之外,都需要单击两次右键才能弹出菜单,并且弹出菜单后,<br>将鼠标移到屏幕的其他地方(“托盘”程序响应事件的区域之外)单击左键,<br>“托盘”的弹出菜单并不会马上消失,这与其他托盘程序不相符合,随能帮<br>我解决?附下原代码:<br>procedure TrayIcon(var Msg: TMessage); Message WM_IconMessage;<br>procedure TMainForm.MyShellNotifyIcon; //实现托盘<br>begin<br>&nbsp;with Nid do<br>&nbsp;begin<br>&nbsp; cbSize := SizeOf(Nid);<br>&nbsp; Wnd := Handle;<br>&nbsp; Uid := 1;<br>&nbsp; uFlags := Nif_Message or Nif_Icon or Nif_Tip;<br>&nbsp; // 以下函数获取“wm_IconMessage”消息<br>&nbsp; uCallbackMessage := WM_IconMessage;<br>&nbsp; HIcon := Application.Icon.Handle; //原来是HIcon := Icon.Handle;<br>&nbsp; szTip := '拨号精灵V1.0';<br>&nbsp;end;<br>&nbsp;Shell_NIcoV := Shell_NotifyIcon(Nim_Add, @Nid);<br>end;<br><br>procedure TMainForm.TrayIcon(var Msg: TMessage);<br>var PT: TPoint;<br>begin<br>&nbsp;if (Msg.LParam = WM_RBUTTONDOWN) then<br>&nbsp;begin<br>&nbsp; GetCursorPos(PT);<br>&nbsp; PopupEx(Self, PopupMenu1, PT.x, PT.y);<br>&nbsp;end<br>&nbsp;else<br>&nbsp; if (Msg.LParam = WM_LBUTTONDBLCLK) then<br>&nbsp; &nbsp;if not(Self.Visible) then<br>&nbsp; &nbsp; Self.Show;<br>end;<br>
 
if (Msg.LParam = WM_RBUTTONDOWN) then begin &nbsp;<br>&nbsp; GetCursorPos(PT);<br>&nbsp; 在这里加入:SetForegroundWindow(Handle);能解决你的第二个问题(我用的是C++)<br>&nbsp; PopupEx(Self, PopupMenu1, PT.x, PT.y); end else<br>&nbsp; if (Msg.LParam = WM_LBUTTONDBLCLK) then &nbsp; if not(Self.Visible) then<br>&nbsp; &nbsp; Self.Show;end;
 
怎样才能取得我自己编的程序中的图标等的资源编号?
 
用控件多简单!不用写代码。<br>如需要请 Email:xxz007@yeah.net(请注明什么控件)
 
给你一段我的程序<br>procedure TrayMsg(var Msg: TMessage); message WM_NOTIFYICON;<br>procedure TForm1.TrayMsg(var Msg: TMessage);<br>var<br>&nbsp; &nbsp; pt:TPoint;<br>begin<br>&nbsp; &nbsp; if msg.LParam =WM_LBUTTONDOWN then form1.Show;<br>&nbsp; &nbsp; if msg.LParam =WM_RBUTTONDOWN then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getcursorpos(pt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(form1.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if TrackPopupMenu(popupmenu1.Handle,tpm_BottomAlign or tpm_RightAlign,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pt.x,pt.y,0,form1.Handle,Nil) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(form1.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end;<br>end;<br>
 
我在编程时也有这个问题.<br>如果,from1在一般情况下,SetForegroundWindow(form1.Handle)可行.<br>但是在form1极小化时,鼠标响应出现问题.需要多次按键.<br>我试过把form1.visible=false,也是可行的,我想SetForegroundWindow(form1.Handle)<br>是激活响应消息的窗口,但不知为何在最小化时就不行!<br>
 
xlf:<br>我要SPY++和取得程序中的图标等的资源编号的控件
 
快点上你的163信箱收我寄给你的东西。——————————颖
 
好象没什么问题!把我做的贴给你看看吧!<br>implementation<br>function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external 'KERNEL32.DLL';<br><br><br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Var IconData : TNotifyIconData;<br><br>Begin<br>&nbsp; With IconData do Begin<br>&nbsp; &nbsp; cbSize := SizeOf(IconData);<br>&nbsp; &nbsp; Wnd := handle;<br>&nbsp; &nbsp; uID := 0;<br>&nbsp; &nbsp; uFlags := nif_Icon Or nif_Message Or nif_Tip;<br>&nbsp; &nbsp; uCallBackMessage := wm_MyCallback;<br>&nbsp; &nbsp; hIcon := Application.Icon.Handle;<br>&nbsp; &nbsp; StrCopy(szTip,'MyTrayApp');<br>&nbsp; End;<br>&nbsp; Shell_NotifyIcon(nim_Add,@IconData);<br>&nbsp; RegisterServiceProcess(GetCurrentProcessID, 1);//隐藏<br>&nbsp; <br>//RegisterServiceProcess(GetCurrentProcessID, 0);//显示<br>End;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>Var IconData : TNotifyIconData;<br>Begin<br>&nbsp; With IconData do Begin<br>&nbsp; &nbsp; cbSize := SizeOf(IconData);<br>&nbsp; &nbsp; Wnd := handle;<br>&nbsp; &nbsp; uID := 0;<br>&nbsp; &nbsp; uFlags := nif_Icon Or nif_Message Or nif_Tip;<br>&nbsp; &nbsp; uCallBackMessage := wm_MyCallback;<br>&nbsp; &nbsp; hIcon := Application.Icon.Handle ;<br>&nbsp; &nbsp; StrCopy(szTip,'MyTrayApp');<br>&nbsp; End;<br>&nbsp; Shell_NotifyIcon(nim_Delete,@IconData);<br>End;<br><br><br>procedure TForm1.WndProc1(var Msg: TMessage);<br>var<br>&nbsp; //IconID:integer;<br>&nbsp; Pos:TPOINT;<br>begin<br>&nbsp; &nbsp;if msg.Msg = wm_MyCallback then<br>&nbsp; &nbsp;begin<br>&nbsp; // &nbsp; &nbsp;iconID := msg.WParam;<br>&nbsp; &nbsp; &nbsp; //通知消息的处理的基本框架结构如下:<br>&nbsp; &nbsp; &nbsp; if msg.lParam =WM_LBUTTONDOWN then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Form1.Visible then Form1.Visible := False<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else Form1.Visible := True;<br>&nbsp; &nbsp; &nbsp; if msg.LParam = WM_RBUTTONDOWN<br>&nbsp; &nbsp; &nbsp; &nbsp;then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(Pos);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Form1.PopupMenu := PopupMenu1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TrackPopupMenu(Form1.PopupMenu1.Handle,tpm_LeftAlign Or tpm_LeftButton,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Pos.X,Pos.Y,0,handle,nil);<br>&nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Form1.PopupMenu1.Popup(Pos.X,Pos.Y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostMessage(handle,wm_MyCallBack,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Form1.PopupMenu := nil;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp;inherited;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; //调用父类的WndProc方法处理其它消息<br>&nbsp;end;
 
procedure TMainForm.TrayIcon(var Msg: TMessage);<br>var PT: TPoint;<br>begin<br>&nbsp;if (Msg.LParam = WM_RBUTTONDOWN) then<br>&nbsp;begin<br>&nbsp; GetCursorPos(PT);<br>&nbsp; // ******************** &nbsp; 加上一句 ***************************<br>&nbsp; Self.BringToFront; &nbsp; // 关键的一句<br>&nbsp; PopupEx(Self, PopupMenu1, PT.x, PT.y);<br>&nbsp;end<br>&nbsp;else<br>&nbsp; if (Msg.LParam = WM_LBUTTONDBLCLK) then<br>&nbsp; &nbsp;if not(Self.Visible) then<br>&nbsp; &nbsp; Self.Show;<br>end<br><br><br>就差这一句!!!
 
多人接受答案了。
 
后退
顶部