vb显示托盘图标问题

DeclareFunctionShell_NotifyIconLib"shell32.dll"Alias"Shell_NotifyIconA"(ByValdwMessag... Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Type NOTIFYICONDATA
cbSize As Long
HWnd As Long
Uid As Long
UFlags As Long
UCallbackMessage As Long
HIcon As Long
SzTip As String * 64
End Type
sub form_click()
dim TheData As NOTIFYICONDATA
With TheData
.Uid = 0
.HWnd = form1.HWnd 'frm.HWnd是程序主窗体的句柄
.cbSize = Len(TheData)
.HIcon = form1.Icon.Handle 'frm.Icon.Handle指向主窗体的图标
.UFlags = NIF_ICON
.UCallbackMessage = TRAY_CALLBACK
'作用是允许返回消息
.UFlags = .UFlags Or NIF_MESSAGE
.cbSize = Len(TheData)
End With
Shell_NotifyIcon NIM_ADD, TheData
end sub
这样运行,点击窗体,托盘上有位置,但是是空的,没有图标,为什么啊,请教高手。。。
展开
 我来答
shaoyedh
2011-04-26 · TA获得超过102个赞
知道小有建树答主
回答量:150
采纳率:0%
帮助的人:104万
展开全部
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

'Private Const WM_LBUTTONDBLCLK = &H203
'Private Const WM_LBUTTONDOWN = &H201
'Private Const WM_RBUTTONUP = &H205
Dim TrayI As NOTIFYICONDATA

Sub form_click()
Dim TheData As NOTIFYICONDATA
With TheData
.hwnd = Me.hwnd
'Application-defined identifier of the taskbar icon
.uId = 1&
'Set the flags
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
'Set the callback message
.ucallbackMessage = WM_LBUTTONDOWN
'Set the picture (must be an icon!)
.hIcon = Me.Icon
'Set the tooltiptext
.szTip = "Recent" & Chr$(0)
'Create the icon
Shell_NotifyIcon NIM_ADD, TheData
End With
End Sub
直接在窗体里面加入上代码 单机窗体实现托盘图标
追问
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2,像这些常数必须要赋值吗,还有您帮我看看我的程序哪里有问题啊,非常迷惑,多谢。。。。
追答
这些赋值是为了方便编程人员能分清楚 这个代号是干什么的 
其实你不用前面的英文 直接使用后面的十六进制数字 效果是一样的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
两瓶维41
2011-04-26 · 超过11用户采纳过TA的回答
知道答主
回答量:74
采纳率:0%
帮助的人:39.3万
展开全部
With theData
.hwnd = Form1.hwnd
.cbSize = Len(theData)
.uID = vbNull
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP

.hIcon = Form1.Icon
.uCallbackMessage = WM_MOUSEMOVE '可以用TRAY_CALLBACK
.szTip = Msg & vbNullChar

End With
Shell_NotifyIcon Nim, theData
这样就可以了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友bdb9803
2011-04-26 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:1亿
展开全部
你没定义常量啊。
模块前面加上:
Public Const WM_USER = &H400
Public Const WM_LBUTTONUP = &H202
Public Const WM_MBUTTONUP = &H208
Public Const WM_RBUTTONUP = &H205
Public Const TRAY_CALLBACK = (WM_USER + 1001&)
Public Const GWL_WNDPROC = (-4)
Public Const GWL_USERDATA = (-21)
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIF_MESSAGE = &H1
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式