iczelion tut23[5]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

        .endif

we use this opportunity to fill notifyicondata structure. idi_tray is just a constant defined at the beginning of the source code. you can set it to any value you like. it's not important because you have only one tray icon. but if you will put several icons into the system tray, you need unique ids for each tray icon. we specify all flags in uflags member because we specify an icon (nif_icon), we specify a custom message (nif_message) and we specify the tooltip text (nif_tip). wm_shellnotify is just a custom message defined as wm_user+5. the actual value is not important so long as it's unique. i use the winlogo icon as the tray icon here but you can use any icon in your program. just load it from the resource with loadicon and put the returned handle in hicon member. lastly, we fill the sztip with the text we want the shell to display when the mouse is over the icon.
we hide the main window to give the illusion of "minimizing-to-tray-icon" appearance.
next we call shell_notifyicon  with nim_add message to add the icon to the system tray.

now our main window is hidden and the icon is in the system tray. if you move the mouse over it, you will see a tooltip that displays the text we put into sztip member. next, if you double-click at the icon, the main window will reappear and the tray icon is gone.

    .elseif umsg==wm_shellnotify
        .if wparam==idi_tray
            .if lparam==wm_rbuttondown
                invoke getcursorpos,addr pt
                invoke setforegroundwindow,hwnd
                invoke trackpopupmenu,hpopupmenu,tpm_rightalign,pt.x,pt.y,null,hwnd,null
                invoke postmessage,hwnd,wm_null,0,0
            .elseif lparam==wm_lbuttondblclk
                invoke sendmessage,hwnd,wm_command,idm_restore,0
            .endif
        .endif

when a mouse event occurs over the tray icon, your window receives wm_shellnotify message which is the custom message you specified in ucallbackmessage member. recall that on receiving this message, wparam contains the tray icon's id and lparam contains the actual mouse message. in the code above, we check first if this message comes from the tray icon we are interested in. if it does, we check the actual mouse message. since we are only interested in right mouse click and double-left-click, we process only wm_rbuttondown and wm_lbuttondblclk messages.
if the mouse message is wm_rbuttondown, we call getcursorpos to obtain the current screen coordinate of the mouse cursor. when the function returns, the point structure is filled with the screen coordinate of the mouse cursor. by screen coordinate, i mean the coordinate of the entire screen without regarding to any window boundary. for example, if the screen resolution is 640*480, the right-lower corner of the screen is x==639 and y==479. if you want to convert the screen coordinate to window coordinate, use screentoclient function.
however, for our purpose, we want to display the popup menu at the current mouse cursor position with trackpopupmenu call and it requires screen coordinates, we can use the coordinates filled by getcursorpos directly.
trackpopupmenu has the following syntax:
 

    trackpopupmenu proto hmenu:dword, uflags:dword,  x:dword,  y:dword, nreserved:dword, hwnd:dword, prcrect:dword

本文关键:iczelion asm
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top