读书人

caozhy进来帮下忙多谢

发布时间: 2013-11-25 13:22:27 作者: rapoo

caozhy进来帮下忙,谢谢
VB代码
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按下鼠标拖动,想窗体跟着移动,应该怎么搞。
[解决办法]
http://www.pconline.com.cn/pcedu/empolder/net/0409/452601.html
[解决办法]

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

读书人网 >C#

热点推荐