係統粉 > 電腦問答 > 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係統問答
解決方法