各位,大哥大姐.我有个问题想请教大家!在VB中怎样编才可以把窗体缩小到托盘中呢?
这个问题牵扯到windows API
参考一下下面的例子。
Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
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
' commands & flags for NotifyIcons
Global Const NIM_ADD = &H0&
Global Const NIM_MODIFY = &H1
Global Const NIM_DELETE = &H2
Global Const NIF_MESSAGE = &H1
Global Const NIF_ICON = &H2
Global Const NIF_TIP = &H4
Global Const WM_MOUSEMOVE = &H200
Global NI as NOTIFYICONDATA
创建提示图标
将下面的代码放在Form_Load事件中以产生一个提示图标。所有的鼠标事件都将会传递到PictureBox的MouseMove事件中。
' stock NOTIFYICONDATA structure
NI.cbSize = Len(NI) 'length of this structure
NI.hWnd =Picture1.hwnd 'control to receive messages
NI.uID = 0 ' uniqueID
NI.uFlags = NIF_MESSAGE or NIF_ICON or NIF_TIP ' Operation Flags
NI.uCallbackMessage = WM_MOUSEMOVE ' message to send to control
NI.hIcon = Picture1.DragIcon ' handle to Icon
NI.szTip = "My Tool Tip" + Chr$(0) ' Tool Tip
' 必须给提示图标分配一个唯一的ID号
' so increment until creation is successful
Do
NI.uID = NI.uID + 1
result = Shell_NotifyIconA(NIM_ADD, NI)
Loop While result = 0
修改提示图标Modifying NOTIFYICON
下面的例子可以修改图标
NI.hIcon = Picture2.DragIcon
NI.szTip = "Different Tool Tip" + Chr$(0)
' modifies an existing NotifyIcon
result = Shell_NotifyIconA(NIM_MODIFY, NI)
删除提示图标Deleting NOTIFYICON
将下面的代码放在Form_Unload事件中
' 删除已有的提示图标
result = Shell_NotifyIconA(NIM_DELETE, NI)
下面的代码放在 PictureBox的MouseMove事件中
' 从提示图标接收消息
' 消息通过X参数传递
Dim Msg as Long
Msg = (X And &HFF) * &H100
Select Case Msg
Case 0 ' 鼠标移动
' 在此输入你的代码
Case &HF00 ' 鼠标左键被按下
' 在此输入你的代码
Case &H1E00 '
' 在此输入你的代码
Case &H2D00 ' 双击鼠标左键
' 在此输入你的代码
Case &H3C00 ' 鼠标右键被按下
' 在此输入你的代码
Case &H4B00 ' 鼠标右键弹起
' 在此输入你的代码
Case &H5A00 ' 双击鼠标右键
' 在此输入你的代码
End Select