如何得到系统盒中小图标的位置? (100分)

S

sxzqcyj

Unregistered / Unconfirmed
GUEST, unregistred user!
在没有点击的情况下如何得到系统盒中小图标的位置?
 
为什么没有帮我呢,我没说明的吗<br>就是在没有任何鼠标事件情况下,<br>应用程序内部得到图标的位置,<br>然后在这个位置弹出一个菜单。<br>分少我可以再加。
 
大家要多少分就帮我呀![?]
 
试试这个控件吧,应该有你想要的功能<br><br><br>unit TrayIcon;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, Forms, SysUtils, ImgList, Controls, Menus, ExtCtrls, Dialogs,<br>&nbsp; ScktComp, ComCtrls,StdCtrls, Buttons, Classes, Shellapi, Graphics;//, DesignEditors,<br>// &nbsp;DesignIntf; //, DsgnIntf;<br>{ &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Forms, Menus,<br>&nbsp; shellAPI, StdCtrls, ExtCtrls, Controls, ComCtrls, Buttons;<br>&nbsp;}<br>type<br>&nbsp; ENotifyIconError = class(Exception);<br><br>{ &nbsp;TAboutTrayIcon = class(TPropertyEditor)<br>&nbsp; public<br>&nbsp; &nbsp; procedure Edit; override;<br>&nbsp; &nbsp; function GetAttributes: TPropertyAttributes; override;<br>&nbsp; &nbsp; function GetValue: string; override;<br>&nbsp; end; }<br><br>&nbsp; TTrayIcon = class(TComponent)<br>&nbsp; private<br>// &nbsp; &nbsp;FAbout: TAboutTrayIcon;<br>&nbsp; &nbsp; FDefaultIcon: THandle;<br>&nbsp; &nbsp; FIcon: TIcon;<br>&nbsp; &nbsp; FHideTask: boolean;<br>&nbsp; &nbsp; FHint: string;<br>&nbsp; &nbsp; FIconVisible: boolean;<br>&nbsp; &nbsp; FPopupMenu: TPopupMenu;<br>&nbsp; &nbsp; FOnClick: TNotifyEvent;<br>&nbsp; &nbsp; FOnDblClick: TNotifyEvent;<br>&nbsp; &nbsp; FNoShowClick: boolean;<br>&nbsp; &nbsp; FTimer: TTimer;<br>&nbsp; &nbsp; Tnd: TNotifyIconData;<br>&nbsp; &nbsp; procedure SetIcon(Value: TIcon);<br>&nbsp; &nbsp; procedure SetHideTask(value: boolean);<br>&nbsp; &nbsp; procedure SetHint(Value: string);<br>&nbsp; &nbsp; procedure SetIconVisible(Value: boolean);<br>&nbsp; &nbsp; procedure SetPopupMenu(Value: TPopupMenu);<br>&nbsp; &nbsp; procedure SendTrayMessage(Msg: DWORD; Flags: UINT);<br>&nbsp; &nbsp; function ActiveIconhandle: THandle;<br>&nbsp; &nbsp; procedure OnButtonTimer(Sender: TObject);<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Loaded; override;<br>&nbsp; &nbsp; procedure LoadDefaultIcon; virtual;<br>&nbsp; &nbsp; procedure Notification(AComponent: TComponent;<br>&nbsp; &nbsp; &nbsp; Operation: TOperation); override;<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; published<br>// &nbsp; &nbsp;property About: TAboutTrayIcon read FAbout write FAbout;<br>&nbsp; &nbsp; property Icon: TIcon read FIcon write SetIcon;<br>&nbsp; &nbsp; property HideTask: boolean read FHideTask write SethideTask default false;<br>&nbsp; &nbsp; property Hint: string read FHint write SetHint;<br>&nbsp; &nbsp; property IconVisible: boolean read FIconVisible write SetIconVisible<br>&nbsp; &nbsp; &nbsp; default false;<br>&nbsp; &nbsp; property PopupMenu: TPOpupMenu read FPopupMenu write SetPopupMenu;<br>&nbsp; &nbsp; property OnClick: TNotifyEvent read FOnClick write FOnClick;<br>&nbsp; &nbsp; property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;<br>&nbsp; end;<br><br>procedure Register;<br><br>implementation<br><br>// TIconmanager -----------------------------------------------<br>// This class creates a hiden window which handles and routes<br>// tray icon messages.<br>type<br>&nbsp; TIconManager = class<br>&nbsp; private<br>&nbsp; &nbsp; FHWindow: HWnd;<br>&nbsp; &nbsp; procedure TrayWndProc(var Message: TMessage);<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; property HWindow: HWnd read FHWindow write FHWindow;<br>&nbsp; end;<br><br>var<br>&nbsp; IconMgr: TIconManager;<br>&nbsp; DDGM_TRAYICON: Cardinal;<br><br>constructor TIconManager.Create;<br>begin<br>&nbsp; FHWindow:=AllocateHWnd(TrayWndProc);<br>end;<br><br>destructor TIconManager.Destroy;<br>begin<br>&nbsp; if FHWindow &lt;&gt; 0 then DeallocateHWnd(FHWindow);<br>&nbsp; inherited Destroy;<br>end;<br><br>// This allows us to handle all tray callback messages<br>// form within the context of the component<br>procedure TIconManager.TrayWndProc(var Message: TMessage);<br>var<br>&nbsp; pt: TPoint;<br>&nbsp; TheIcon: TTrayIcon;<br>begin<br>&nbsp; with Message do begin<br>&nbsp; &nbsp; // if it's the tray callback message<br>&nbsp; &nbsp; if Msg = DDGM_TRAYICON then begin<br>&nbsp; &nbsp; &nbsp; TheIcon:=TTrayIcon(WParam);<br>&nbsp; &nbsp; &nbsp; case lParam of<br>&nbsp; &nbsp; &nbsp; &nbsp; // Enable timer on first mouse down.<br>&nbsp; &nbsp; &nbsp; &nbsp; // OnClick will be fired by OnTimer method, provided<br>&nbsp; &nbsp; &nbsp; &nbsp; // double Click had not occured<br>&nbsp; &nbsp; &nbsp; &nbsp; WM_LBUTTONDOWN: TheIcon.FTimer.Enabled:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; // Set no click flag on double click. This will supress<br>&nbsp; &nbsp; &nbsp; &nbsp; // the single click.<br>&nbsp; &nbsp; &nbsp; &nbsp; WM_LBUTTONDBLCLK: begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TheIcon.FNoShowClick:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Assigned(TheIcon.FOnDblClick) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TheIcon.FOnDblClick(self);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; WM_RBUTTONDOWN: begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Assigned(TheIcon.FPopupMenu) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Call to SetForeGroundWindow is required by API<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForeGroundWindow(IconMgr.HWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Popup local menu at the cursor position<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetCursorPos(pt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TheIcon.FPopupMenu.Popup(pt.x, pt.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Message post required by API for force task switch<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PostMessage(IconMgr.HWindow, WM_USER, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; // If isn't a tray callback message, then call DefWindowProc<br>&nbsp; &nbsp; &nbsp; result:=DefWindowProc(FHWindow, Msg, wParam, lParam);<br>&nbsp; end;<br>end;<br><br><br>// TTrayIcon --------------------------------------------------<br>constructor TTrayIcon.Create(AOwner: TComponent);<br>begin<br>&nbsp; inherited Create(AOwner);<br>&nbsp; FIcon:=TIcon.Create;<br>&nbsp; FTimer:=TTimer.Create(self);<br>&nbsp; with FTimer do begin<br>&nbsp; &nbsp; Enabled:=false;<br>&nbsp; &nbsp; Interval:=GetDoubleClickTime;<br>&nbsp; &nbsp; OnTimer:=OnButtonTimer;<br>&nbsp; end;<br>&nbsp; // Keep default windows icon handy...<br>&nbsp; LoadDefaultIcon;<br>end;<br><br>destructor TTrayIcon.Destroy;<br>begin<br>&nbsp; if FIconVisible then SetIconVisible(false); // Destroy icon<br>&nbsp; FIcon.Free;<br>&nbsp; FTimer.Free;<br>&nbsp; inherited Destroy;<br>end;<br><br>// Return handle of active icon<br>function TTrayIcon.ActiveIconhandle: THandle;<br>begin<br>&nbsp; // if no icon is loaded, then return default icon.<br>&nbsp; if FIcon.Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; result:=FIcon.Handle<br>&nbsp; else<br>&nbsp; &nbsp; result:=FDefaultIcon;<br>end;<br><br>// Loads default windows icon to keep it handy.<br>// This will allow the component to use the windows logo icon<br>// as the default when no icon is selected in the icon property.<br>procedure TTrayIcon.LoadDefaultIcon;<br>begin<br>&nbsp; FDefaultIcon:=LoadIcon(0, IDI_WINLOGO);<br>end;<br><br>// Called after component is loaded from stream<br>procedure TTrayIcon.Loaded;<br>begin<br>&nbsp; inherited Loaded;<br>&nbsp; // If icon is supposed to be visible, create it.<br>&nbsp; if FIconVisible then<br>&nbsp; &nbsp; SendTrayMessage(NIM_ADD, NIF_MESSAGE or NIF_ICON or NIF_TIP);<br>end;<br><br>procedure TTrayIcon.Notification(AComponent: TComponent;<br>&nbsp; Operation: TOperation);<br>begin<br>&nbsp; inherited Notification(AComponent, Operation);<br>&nbsp; if (Operation = opRemove) and (AComponent = PopupMenu) then<br>&nbsp; &nbsp; PopupMenu := nil;<br>end;<br><br>// Timer used to keep track of time between two clicks of a<br>// double click. This delays the first click long enough to<br>// ensure that a double click hasn't occured. The whole<br>// point of these gymnastics is to allow the component to<br>// recieve OnClicks and OnDblClicks independently. <br>procedure TTrayIcon.OnButtonTimer(Sender: TObject);<br>begin<br>&nbsp; // disable timer because we only want it to fire once.<br>&nbsp; FTimer.Enabled:=false;<br>&nbsp; // If double click has not occured, then fire single click.<br>&nbsp; if (not FNoShowClick) and Assigned(FOnClick) then<br>&nbsp; &nbsp; FOnClick(self);<br>&nbsp; FNoShowclick:=false; // Reset flag<br>end;<br><br>// This method wraps up the call to the API's Shell_NotifyIcon<br>procedure TTrayIcon.SendTrayMessage(Msg: DWORD; Flags: UINT);<br>begin<br>&nbsp; // Fill up record with appropriate values<br>&nbsp; with Tnd do begin<br>&nbsp; &nbsp; cbSize:=SizeOf(Tnd);<br>&nbsp; &nbsp; StrPLCopy(szTip, PChar(FHint), SizeOf(szTip));<br>&nbsp; &nbsp; uFlags:=Flags;<br>&nbsp; &nbsp; uID:=UINT(self);<br>&nbsp; &nbsp; Wnd:=IconMgr.HWindow;<br>&nbsp; &nbsp; uCallbackMessage:=DDGM_TRAYICON;<br>&nbsp; &nbsp; hIcon:=ActiveIconHandle;<br>&nbsp; end;<br>&nbsp; Shell_NotifyIcon(Msg, @Tnd);<br>end;<br><br>// Write method for HideTask property<br>procedure TTrayIcon.SetHideTask(Value: boolean);<br>const<br>&nbsp; // Flags to show application normal or hide it<br>&nbsp; ShowArray: array [boolean] of integer = (sw_ShowNormal, sw_Hide);<br>begin<br>&nbsp; if FHideTask &lt;&gt; Value then begin<br>&nbsp; &nbsp; FHideTask:=Value;<br>&nbsp; &nbsp; // Don't do anything in design mode<br>&nbsp; &nbsp; if not (csDesigning in ComponentState) then<br>&nbsp; &nbsp; &nbsp; ShowWindow(Application.Handle, ShowArray[FHideTask]);<br>&nbsp; end;<br>end;<br><br>// Set method for Hint property<br>procedure TTrayIcon.SetHint(Value: string);<br>begin<br>&nbsp; if FHint &lt;&gt; Value then begin<br>&nbsp; &nbsp; FHint:=Value;<br>&nbsp; &nbsp; if FIconVisible then // Change hint on iocn on notification tray<br>&nbsp; &nbsp; &nbsp; SendTrayMessage(NIM_MODIFY, NIF_TIP);<br>&nbsp; end;<br>end;<br><br>// Set method for Icon property<br>procedure TTrayIcon.SetIcon(Value: TIcon);<br>begin<br>&nbsp; FIcon.Assign(Value); // Set new icon<br>&nbsp; if FIconVisible then // Change icon on notification tray<br>&nbsp; &nbsp; SendTrayMessage(NIM_MODIFY, NIF_ICON);<br>end;<br><br>// write method fo IconVisible property<br>procedure TTrayIcon.SetIconVisible(Value: boolean);<br>const<br>&nbsp; // Flags to add or delete a tray-notification icon<br>&nbsp; MsgArray: array[boolean] of DWORD = (NIM_DELETE, NIM_ADD);<br>begin<br>&nbsp; if FIconVisible &lt;&gt; Value then begin<br>&nbsp; &nbsp; FIconVisible:=Value;<br>&nbsp; &nbsp; // Set Icon as appropriate<br>&nbsp; &nbsp; SendTrayMessage(MsgArray[Value], NIF_MESSAGE or NIF_ICON or NIF_TIP);<br>&nbsp; end;<br>end;<br><br>// Write method for PopupMenu property<br>procedure TTrayIcon.SetPopupMenu(Value: TPopupMenu);<br>begin<br>&nbsp; FPopupMenu:=Value;<br>&nbsp; if Value &lt;&gt; nil then<br>&nbsp; &nbsp; Value.FreeNotification(self);<br>end;<br><br>// TAboutTrayIcon ---------------------------------------------<br>{<br>procedure TAboutTrayIcon.Edit;<br>begin<br>&nbsp; Application.MessageBox('Tray Notification Component V1.0'+#13#10#13#10+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;' This Component is Freeware'+#13#10#13#10+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;' &nbsp; &nbsp;By &nbsp;Lee James 2000',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'About TrayIcon...',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MB_ICONINFORMATION+MB_OK);<br>end;<br><br>function TAboutTrayIcon.GetAttributes: TPropertyAttributes;<br>begin<br>&nbsp; Result := [paMultiSelect, paDialog, paReadOnly];<br>end;<br><br>function TAboutTrayIcon.GetValue: string;<br>begin<br>&nbsp; Result := '(about)';<br>end;<br>}<br><br>// register component --------------------------------<br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('Samples', [TTrayIcon]);<br>// &nbsp;RegisterPropertyEditor(TypeInfo(TAboutTrayIcon), TTrayIcon,<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'About', TAboutTrayIcon);<br>end;<br><br>const<br>&nbsp; // String to indentify registered window message<br>&nbsp; TrayMsgStr = 'DDG.TrayNotifyIconMsg';<br><br>initialization<br>&nbsp; // Get a unique windows message ID for tray callback<br>&nbsp; DDGM_TRAYICON:=RegisterWindowMessage(TrayMsgStr);<br>&nbsp; IconMgr:=TIconManager.Create;<br><br>finalization<br>&nbsp; IconMgr.Free;<br><br>end.<br>
 
TO:leejames <br>TPropertyEditor、TPropertyAttributes是这些吗?<br>能具体说说吗?<br>或者发E_MAIL给我,SXZQCYJ@SOHU.COM<br>多谢了!<br>
 
写这么多代码做什么?<br><br>
 
to: sxzqcyj<br>不好意思,我理解错了。我研究了一个晚上,也找不出什么办法解决你的问题,继续中。。<br>TPropertyEditor、TPropertyAttributes是控件的属性编辑器用的,和你的问题无关,因<br>D6的属性编辑器和D5的实现不同,所以我注释掉了。<br><br>to: PENGS<br>你如果认为两三行代码可以解决的话,写出来看看,我也想知道怎么做<br>
 
谁能帮我![:(]
 
期待中!
 
我用了那个控件,但是有个问题,就是在任务栏上仍然有图标。有没有办法不让它出现在任务栏上,<br>只显示在系统栏里呢?
 
Application.ShowMainForm := False;<br>
 
var pt:Tpoint;<br>GetCursorPos(pt);<br>pt.x,pt.y就是
 
没有鼠标事件发生
 
我没说明白吗
 
to: xcode<br>&nbsp; TrayIcon.HideTask:=false; 即可隐藏任务栏图标<br><br>to: sxzqcyj<br>&nbsp; 系统栏图标其实是由Windows本身创建的,没有鼠标事件我觉得不太可能
 
sxzqcyj,你是想知道SYSTRAY中其它程序的图标的位置吧:)<br>我当初有提过类似的问题:http://www.delphibbs.com/delphibbs/dispq.asp?lid=336167<br>后来是收到了一份VC的源码,现在可能要找下才知道放在哪了。。。
 
wm_nclmoustdown<br><br>message.wparam<br>=hisysmenu
 
to:iamfly<br>我看过你的问题了,找到后能给我发一份吗,最好像你说的哪样,用DELPHI写的、带中<br>文注释。<br>顺便问一下, 它能知道每个图标的具体位置吗?<br>SXZQCYJ@SOHU.COM<br>先谢了!<br><br><br>
 
顶部