SetWindowLong 怎么就是用不上去。
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(24, 24)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedBoth
Me.RichTextBox1.Size = New System.Drawing.Size(240, 224)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "aaa" & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & "b" & Microsoft.VisualBasic.ChrW(10) & "b" & Microsoft.VisualBasic.ChrW(10) & "b" & Microsoft.VisualBasic.ChrW(10) & "b" & Microsoft.VisualBasic.ChrW(10) & "f" & Microsoft.VisualBasic.ChrW(10) & "sd" & Microsoft.VisualBasic.ChrW(10) & "fs" & Microsoft.VisualBasic.ChrW(10) & "gd" & Microsoft.VisualBasic.ChrW(10) & "g" & Microsoft.VisualBasic.ChrW(10) & "d" & Microsoft.VisualBasic.ChrW(10) & "fs" & Microsoft.VisualBasic.ChrW(10) & "r" & Microsoft.VisualBasic.ChrW(10) & "weg" & Microsoft.VisualBasic.ChrW(10) & "er" & Microsoft.VisualBasic.ChrW(10) & "5" & Microsoft.VisualBasic.ChrW(10) & "43r" & Microsoft.VisualBasic.ChrW(10) & "ge" & Microsoft.VisualBasic.ChrW(10) & "r5" & Microsoft.VisualBasic.ChrW(10) & "4" & Microsoft.VisualBasic.ChrW(10) & "tgr" & Microsoft.VisualBasic.ChrW(10) & "6y" & Microsoft.VisualBasic.ChrW(10) & "tr" & Microsoft.VisualBasic.ChrW(10) & "t" & Microsoft.VisualBasic.ChrW(10) & "34y" & Microsoft.VisualBasic.ChrW(10) & Microsoft.VisualBasic.ChrW(10) & "y" & Microsoft.VisualBasic.ChrW(10) & "4r" & Microsoft.VisualBasic.ChrW(10) & "5" & Microsoft.VisualBasic.ChrW(10) & "g" & Microsoft.VisualBasic.ChrW(10) & "y" & _
"" & Microsoft.VisualBasic.ChrW(10) & "rt" & Microsoft.VisualBasic.ChrW(10) & "y34" & Microsoft.VisualBasic.ChrW(10) & "56t" & Microsoft.VisualBasic.ChrW(10) & "tr" & Microsoft.VisualBasic.ChrW(10) & "gr" & Microsoft.VisualBasic.ChrW(10) & "y" & Microsoft.VisualBasic.ChrW(10) & "rt" & Microsoft.VisualBasic.ChrW(10) & "63" & Microsoft.VisualBasic.ChrW(10) & "6y" & Microsoft.VisualBasic.ChrW(10) & "thgv"
Me.RichTextBox1.WordWrap = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(56, 280)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(176, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(296, 326)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
MsgBox("开始勾住")
PrevWndProc = SetWindowLong(RichTextBox1.Handle, -4, AddressOf SubWndProc)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
SetWindowLong(RichTextBox1.Handle, GWL_WNDPROC, PrevWndProc)
End Sub
Public Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Long, ByVal dwNewLong As Type) As Type
Public Declare Function CallWindowProc Lib "USER32" Alias "CallWindowProcA" (ByVal OldwndProc As Type, ByVal hWnd As IntPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public PrevWndProc As Type
Public Delegate Function Type(ByVal hWnd As IntPtr, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function SubWndProc(ByVal hWnd As IntPtr, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Call Dada(CStr(MSG))
SubWndProc = CallWindowProc(PrevWndProc, hWnd, MSG, wParam, lParam)
End Function
Public Function Dada(ByVal DataText As String)
Button1.Text = DataText
End Function
End Class