当前位置: 代码迷 >> PB >> pb托盘+菜单+热键呼出,该怎么处理
  详细解决方案

pb托盘+菜单+热键呼出,该怎么处理

热度:503   发布时间:2016-04-29 07:42:43.0
pb托盘+菜单+热键呼出
谁给个完整的代码?200分
注意,是要托盘,和托盘上面显示的菜单,还有显示成托盘用热键可以呼出来的,最好是可以自定义热键的

[email protected]
------解决方案--------------------
api定义:
Public Function Integer Shell_NotifyIcon (Long dwMessage, Any lpData) Library "shell32" Alias For "Shell_NotifyIconA"

Public Function Long LoadImage (Long hInst, String lpsz, Long un1, Long n1, Long n2, Long un2) Library "user32" Alias  For "LoadImageA" 
Public Function Long DestroyIcon (Long hIcon) Library "user32" Alias For "DestroyIcon"

Public Function Long SetForegroundWindow  (Long hwnd) Library "user32" Alias For "SetForegroundWindow"

Public Function Long OpenIcon  (Long hwnd) Library "user32" Alias For "OpenIcon"

自定义函数  :
// Boolean AddToTray ()

Any nid

if hIcon = 0 then
// the icon has not been loaded yet
hIcon = LoadImage(0, "RED.ICO", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
end if

if hIcon = 0 then
// MessageBox ("Error", "Can't load icon!")
//
// Return False
else
nid = SetNotifyIconData (Handle (This), 0, NIF_MESSAGEorNIF_ICONorNIF_TIP, WM_MOUSEMOVE, hIcon, "南京**数据采集程序")
Shell_NotifyIcon (NIM_ADD, nid)
Return True
end if



// RemoveFromTray ()

Any nid

nid = SetNotifyIconData (Handle (This), 0, NIF_MESSAGEorNIF_ICONorNIF_TIP, 0, hIcon, "")
Shell_NotifyIcon (NIM_DELETE, nid)

if hIcon <> 0 then DestroyIcon (hIcon)
hIcon = 0


// NotifyIconData SetNotifyIconData (Long hWnd, Long ID, Long Flags, Long CallbackMessage, Long Icon, String Tip)

Char MyTip [64]

NotifyIconData NidTemp
 
NidTemp.cbSize = 88 // Len (NidTemp)
NidTemp.hWnd = hWnd
NidTemp.uID = ID
NidTemp.uFlags = Flags
NidTemp.uCallbackMessage = CallbackMessage
NidTemp.hIcon = Icon1
MyTip = Tip + Char (0)
NidTemp.szTip = MyTip
 
return NidTemp



事件  :

open:
if AddToTray () then Visible = False
MouseMove:

// Long MouseMove (UnsignedLong Flags, Int xPos, Int yPos)

if yPos <> 0 And Visible then
// This event has been triggered by really moving the
// mouse over the window. Note that we can't trace a
// first graphic line (yPos = 0) of mouse movements any
// more since tray events always set yPos to 0 but that
// won't be a problem in most of the cases anyway.
// TODO: place your own code here to handle then MouseMove event
//       if you want.
  相关解决方案