系统粉 > 电脑问答 > win7系统问答

已解决WM_LBUTTONDOWN在W7上用不了

提问者:鮟尐  |  浏览次  |  提问时间:2017-01-23  |  回答数量:9

WM_LBUTTONDOWN在W7上用不了 Const WM_LBUTTONDOWN = &H201Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim L L = X \\ 15 If L = WM_LBUTTONDOWN Then ....End Sub不能执行then后面的语句,公司有三台W7,只有一台没问题,在XP上测试过是没有问题的.

已有9条答案
紫色水晶夏爱梦

紫色水晶夏爱梦

回答数:47  |  被采纳数:137

Button =1表示左键,2表示右键 ,不需要用到WM_LBUTTONDOWN
2017-01-23 22:37:44
赞 4
gzh20065

gzh20065

回答数:86  |  被采纳数:120

类代码
Public Const DefaultIconIndex = 1 '图标缺省索引
Public Const WM_LBUTTONDOWN = &H201 '按鼠标左键
Public Const WM_RBUTTONDOWN = &H204 '按鼠标右键
Public Const NIM_ADD = 0 '添加图标
Public Const NIM_MODIFY = 1 '修改图标
Public Const NIM_DELETE = 2 '删除图标
Public Const NIF_MESSAGE = 1 'message 有效
Public Const NIF_ICON = 2 '图标操作(添加、修改、删除)有效
Public Const NIF_TIP = 4 'ToolTip(提示)有效

'API函数声明
'图标操作
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'判断窗口是否最小化
Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
'
'设置窗口位置和状态(position)的功能
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) 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



'函数定义
'添加图标至通知栏
Public Function Icon_Add(iHwnd As Long, sTips As String, hIcon As Long, IconID As Long) As Long
'参数说明:iHwnd:窗口句柄,sTips:当鼠标移到通知栏图标上时显示的提示内容
'hIcon:图标句柄,IconID:图标Id号
Dim IconVa As NOTIFYICONDATA
With IconVa
.hwnd = iHwnd
.szTip = sTips + Chr$(0)
.hIcon = hIcon
.uID = IconID
.uCallbackMessage = WM_LBUTTONDOWN
.cbSize = Len(IconVa)
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Icon_Add = Shell_NotifyIcon(NIM_ADD, IconVa)
End With
End Function

'删除通知栏图标(参数说明同Icon_Add)
Function Icon_Del(iHwnd As Long, lIndex As Long) As Long
Dim IconVa As NOTIFYICONDATA
Dim L As Long
With IconVa
.hwnd = iHwnd
.uID = lIndex
.cbSize = Len(IconVa)
End With
Icon_Del = Shell_NotifyIcon(NIM_DELETE, IconVa)
End Function

'修改通知栏图标(参数说明同Icon_Add)
Public Function Icon_Modify(iHwnd As Long, sTips As String, hIcon As Long, IconID As Long) As Long
Dim IconVa As NOTIFYICONDATA
With IconVa
.hwnd = iHwnd
.szTip = sTips + Chr$(0)
.hIcon = hIcon
.uID = IconID
.uCallbackMessage = WM_LBUTTONDOWN
.cbSize = Len(IconVa)
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Icon_Modify = Shell_NotifyIcon(NIM_MODIFY, IconVa)
End With
End Function

窗口代码
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim L
L = X \ 15
'点击通知栏图标,用鼠标右键时调出弹出菜单
If L = WM_RBUTTONDOWN Then
Me.PopupMenu main
'点击通知栏图标,用鼠标左键时,将通知栏图标改为另外的图标
ElseIf L = WM_LBUTTONDOWN Then
Call Icon_Del(Me.hwnd, 0) '删除通知栏图标
Me.WindowState = 0
Me.Show '调出窗口
End If

End Sub

Private Sub Form_Resize()
If Me.WindowState = 1 Then
'MinFlag = True
Me.Visible = False '隐藏窗口
'将窗口图标加入通知栏
Call Icon_Add(Me.hwnd, Me.Caption, Me.Icon, 0)
End If

End Sub


Private Sub Exit_Click(Index As Integer)
Call Icon_Del(Me.hwnd, 0) '删除通知栏图标
End '退出程序

End Sub

Private Sub Show_Click(Index As Integer)
Call Icon_Del(Me.hwnd, 0) '删除通知栏图标
Me.WindowState = 0
Me.Show '调出窗口

End Sub

我试过用BUTTON代替,但是光标一到那个图标的位置就已经反应了,我还没按,不知道为什么,因为这些代码都是从网上找的,麻烦版大帮忙看看,主要是实现窗口图标在托盘显示而且图标没有走样,谢谢。
2017-01-24 00:13:53
赞 8
雨宫曦

雨宫曦

回答数:143  |  被采纳数:147

.uCallbackMessage = WM_LBUTTONDOWN表示托盘消息都用WM_LBUTTONDOWN发送,应该用自定义消息
2017-01-24 05:49:27
赞 14
浅陌gg丶

浅陌gg丶

回答数:2  |  被采纳数:134

(1) 版大我没看懂你在说什么啊,是不是把.uCallbackMessage = WM_LBUTTONDOWN里的WM_LBUTTONDOWN改成我自己定义的东西就行了?
2017-01-23 23:02:45
赞 0
死三舅舅

死三舅舅

回答数:186  |  被采纳数:53

MSDN的说明
uCallbackMessage
Application-defined message identifier. The system uses this identifier for notification messages that it sends to the window identified in hWnd. These notifications are sent when a mouse event occurs in the bounding rectangle of the icon.
意思是只要对托盘图标有任何动作都会向窗口发送uCallbackMessage消息,这个消息由用户指定,VC里只要在WindowProc函数中case这个消息
你设置uCallbackMessage = WM_LBUTTONDOWN跟系统的左键消息冲突,所以图标一动就会触发Form_MouseDown
VB里处理自定义消息需要自己实现WindowProc http://www.b181/bianchen/bianchen-105536.html
2017-01-23 23:08:34
赞 18
guzhanchao

guzhanchao

回答数:49  |  被采纳数:88

只是部分的W7系统不行,这个不知道是为什么,其它都好正常的,响应到左右键的按下动作,而部份的就是不行,咋按也没反应,这又是为什么?我测试过,正常的机子 L = X \ 15 是等于513,而就刚好与WM_LBUTTONDOWN的值一样,所以能就触发那个过程,而不正常的机子就是409,可是我修改那值后就会不管我按不按键它都会反应。不知道版大有没有看懂我在写什么了
2017-01-24 13:56:21
赞 4
紫裳云

紫裳云

回答数:143  |  被采纳数:3

跟鼠标相关消息没搜索到409的,因为你的代码不是规范写法,所以正常应该是都不能用的,能用也是巧合,跟系统有关
2017-01-24 07:39:12
赞 14
嫌我心腥

嫌我心腥

回答数:209  |  被采纳数:134

原来是这样,版大能不能推荐一下关于这方面知识的书本,我这方面基本不懂,现在我用另一个控件顶上了,感谢版大。
2017-01-23 22:35:45
赞 20
韵事有趣

韵事有趣

回答数:7  |  被采纳数:65

windows程序设计,不过是C++的
2017-01-24 16:04:24
赞 0
相关问答
最新win7系统问答
解决方法