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
这样运行,点击窗体,托盘上有位置,但是是空的,没有图标,为什么啊,请教高手。。。 展开
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
这样运行,点击窗体,托盘上有位置,但是是空的,没有图标,为什么啊,请教高手。。。 展开
3个回答
展开全部
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
直接在窗体里面加入上代码 单机窗体实现托盘图标
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,像这些常数必须要赋值吗,还有您帮我看看我的程序哪里有问题啊,非常迷惑,多谢。。。。
追答
这些赋值是为了方便编程人员能分清楚 这个代号是干什么的
其实你不用前面的英文 直接使用后面的十六进制数字 效果是一样的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
这样就可以了
.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
这样就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你没定义常量啊。
模块前面加上:
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
模块前面加上:
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询