Public Class Form1
Declare Function SendMessageW Lib "user32" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
If e.Button = MouseButtons.Left Then
Capture = False
SendMessageW(Me.Handle, &HA1, 2, 0)
End If
End Sub
End Class
如果在窗体里有个Panel控件,我在Panel按下鼠标拖动,想窗体跟着移动,应该怎么搞。
3 个解决方案
#2
老大,能用我的代码实现吗?
#3
Public Class Form1
Declare Function SendMessageW Lib "user32" (ByVal hwnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Integer, ByVal ndx As Integer, ByVal newValue As callbacktype) As Integer
Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Integer, ByVal ndx As Integer, ByVal newValue As Integer) As Integer
Private Declare Function CallWindowProcW Lib "user32" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Const GWL_WNDPROC As Integer = -4
Const WM_LBUTTONDOWN As Integer = &H201
Private oldProcAddr As Integer
Delegate Function callbacktype(ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
SetWindowLongW(Panel1.Handle, GWL_WNDPROC, oldProcAddr)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
oldProcAddr = SetWindowLongW(Panel1.Handle, GWL_WNDPROC, AddressOf callback)
End Sub
Function callback(ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Select Case uMsg
Case WM_LBUTTONDOWN
SendMessageW(Me.Handle, &HA1, 2, 0)
Case Else
Return CallWindowProcW(oldProcAddr, hWnd, uMsg, wParam, lParam)
End Select
Return 0
End Function
End Class
演示下SubClass
#1
#2
老大,能用我的代码实现吗?
#3
Public Class Form1
Declare Function SendMessageW Lib "user32" (ByVal hwnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Integer, ByVal ndx As Integer, ByVal newValue As callbacktype) As Integer
Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Integer, ByVal ndx As Integer, ByVal newValue As Integer) As Integer
Private Declare Function CallWindowProcW Lib "user32" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Const GWL_WNDPROC As Integer = -4
Const WM_LBUTTONDOWN As Integer = &H201
Private oldProcAddr As Integer
Delegate Function callbacktype(ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
SetWindowLongW(Panel1.Handle, GWL_WNDPROC, oldProcAddr)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
oldProcAddr = SetWindowLongW(Panel1.Handle, GWL_WNDPROC, AddressOf callback)
End Sub
Function callback(ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Select Case uMsg
Case WM_LBUTTONDOWN
SendMessageW(Me.Handle, &HA1, 2, 0)
Case Else
Return CallWindowProcW(oldProcAddr, hWnd, uMsg, wParam, lParam)
End Select
Return 0
End Function
End Class
演示下SubClass