一个图象问题??(我都不晓得标题应该囊个写了!)

ukm7895123 2006-01-23 11:04:17
主要想解决的问题是象QQ那样显示一个图标在右下脚,点反键出来一个菜单,请问这种应该怎么实现呀??
...全文
33 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kmlxk0 2006-01-23
...图像问题。。。
回复
sakurako 2006-01-23
'在frmMain中还要这样做
Private Sub Form_Load()
prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
'其中prevWndProc 是定义在模块中的全局变量
'在最小化的时候插入如下代码
frmMain.Hide
AddNotifyIcon PicIcon, Me.Caption
'其中PicIcon是一个PictureBox
回复
faysky2 2006-01-23
就是做托盘,你可以照着1楼的代码做
回复
sakurako 2006-01-23
Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_USER = &H400
Private Const WM_NOTIFYICON = WM_USER + 1 ' 自定义消息
Private Const GWL_WNDPROC = (-4)
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONDOWN = &H204

Private Type NOTIFYICONDATA
cbSize As Long ' 结构大小(字节)
hwnd As Long ' 处理消息的窗口的句柄
uId As Long ' 唯一的标识符
uFlags As Long ' Flags
uCallBackMessage As Long ' 处理消息的窗口接收的消息
hIcon As Long ' 托盘图标句柄
szTip As String * 128 ' Tooltip 提示文本
dwState As Long ' 托盘图标状态
dwStateMask As Long ' 状态掩码
szInfo As String * 256 ' 气球提示文本
uTimeoutOrVersion As Long ' 气球提示消失时间或版本
' uTimeout - 气球提示消失时间(单位:ms, 10000 -- 30000)
' uVersion - 版本(0 for V4, 3 for V5)
szInfoTitle As String * 64 ' 气球提示标题
dwInfoFlags As Long ' 气球提示图标
End Type


' dwState to NOTIFYICONDATA structure
Private Const NIS_HIDDEN = &H1 ' 隐藏图标
Private Const NIS_SHAREDICON = &H2 ' 共享图标

' uFlags to NOTIFYICONDATA structure
Private Const NIF_ICON As Long = &H2
Private Const NIF_INFO As Long = &H10
Private Const NIF_MESSAGE As Long = &H1
Private Const NIF_STATE As Long = &H8
Private Const NIF_TIP As Long = &H4
' dwMessage to Shell_NotifyIcon
Private Const NIM_ADD As Long = &H0
Private Const NIM_DELETE As Long = &H2
Private Const NIM_MODIFY As Long = &H1
Private Const NIM_SETFOCUS As Long = &H3
Private Const lngNIM_SETVERSION As Long = &H4

Private Const WM_MOUSEMOVE = &H200

Private HaveSet As Boolean '标记是否放了图标
Private preHwnd As Long '保存句柄

Public Sub AddNotifyIcon(PicBox As PictureBox, TipString As String)

' 向托盘区添加图标
Dim IconData As NOTIFYICONDATA

With IconData
.cbSize = Len(IconData)
.hwnd = PicBox.hwnd
.uId = 0
.uFlags = NIF_TIP Or NIF_ICON Or NIF_MESSAGE
.uCallBackMessage = WM_NOTIFYICON
.szTip = TipString & vbNullChar
.hIcon = PicBox.Picture
End With

If HaveSet = False Then
Shell_NotifyIcon NIM_ADD, IconData
preHwnd = SetWindowLong(PicBox.hwnd, GWL_WNDPROC, AddressOf WindowProc)
HaveSet = True
ElseIf HaveSet = True Then
Shell_NotifyIcon NIM_MODIFY, IconData
HaveSet = True
End If
End Sub

Public Sub DelNotifyIcon(PicBox As PictureBox)
If HaveSet = False Then Exit Sub
Dim IconData As NOTIFYICONDATA
With IconData
.cbSize = Len(IconData)
.hwnd = PicBox.hwnd
.uId = 0
End With
Shell_NotifyIcon NIM_DELETE, IconData
SetWindowLong PicBox.hwnd, GWL_WNDPROC, preHwnd
HaveSet = False
End Sub

Private Function WindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' 拦截 WM_NOTIFYICON 消息
If msg = WM_NOTIFYICON Then
Select Case lParam
Case WM_LBUTTONDOWN '左键按下
frmMain.Show
DelNotifyIcon frmMain.PicIcon
Case WM_RBUTTONDOWN '右键按下
frmMain.PopupMenu frmMain.mnuMain
End Select
End If
WindowProc = CallWindowProc(preHwnd, hwnd, msg, wParam, lParam)
End Function

'别人的代码,我修改过。注意WindowProc中的frmMain是一个窗体,它里面还要有菜单
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告