Public Delegate Function WindowProc_delegate(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As WindowProc_delegate) As Integer
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim moto As Integer
Public Function WindowProc(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Select Case uMsg
Case &H7B '右クリック禁止
Exit Function
End Select
CallWindowProc(moto, hWnd, uMsg, wParam, lParam)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dd As WindowProc_delegate dd = AddressOf WindowProc moto = SetWindowLong(Me.TextBox1.Handle, -4, dd)
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click > > Dim dd As WindowProc_delegate > dd = AddressOf WindowProc > moto = SetWindowLong(Me.TextBox1.Handle, -4, dd) > > End Sub
分類:[.NET]
ユーザフォーム内にtextboxとbuttonを配置して、buttonを押すとtextboxの右クリックができないようするコードを書きました。
buttonを押すと、右クリックしない状態になるのですが、しばらくすると、
[System.NullReferenceException' のハンドルされていない例外が 不明なモジュールです。 で発生しました。
追加情報 : オブジェクト参照がオブジェクト インスタンスに設定されていません。]とエラーがでてしまうのです。なぜこうなるのか見当がつかないのですが
もしわかる人がいれば教えていただきたいのですが・・・
'-----form内-------
Public Delegate Function WindowProc_delegate(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As WindowProc_delegate) As Integer
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim moto As Integer
Public Function WindowProc(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Select Case uMsg
Case &H7B '右クリック禁止
Exit Function
End Select
CallWindowProc(moto, hWnd, uMsg, wParam, lParam)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dd As WindowProc_delegate
dd = AddressOf WindowProc
moto = SetWindowLong(Me.TextBox1.Handle, -4, dd)
End Sub