Click here to Skip to main content
15,902,189 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionWebcam Capture and print A5 Paper, Codes (Two Cameras) Pin
Uğur Şirin1-Jul-13 22:57
Uğur Şirin1-Jul-13 22:57 
AnswerRe: Webcam Capture and print A5 Paper, Codes (Two Cameras) Pin
Eddy Vluggen2-Jul-13 0:32
professionalEddy Vluggen2-Jul-13 0:32 
Questionvb6 to vb.net Pin
Smith00530-Jun-13 19:13
Smith00530-Jun-13 19:13 
AnswerRe: vb6 to vb.net Pin
Dave Kreskowiak1-Jul-13 2:21
mveDave Kreskowiak1-Jul-13 2:21 
QuestionHow to get address of a function or method Pin
treddie30-Jun-13 11:05
treddie30-Jun-13 11:05 
AnswerRe: How to get address of a function or method Pin
TnTinMn30-Jun-13 16:46
TnTinMn30-Jun-13 16:46 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 12:17
treddie1-Jul-13 12:17 
GeneralRe: How to get address of a function or method Pin
TnTinMn1-Jul-13 14:28
TnTinMn1-Jul-13 14:28 
What is that you want to accomplish? The code I referenced will work, but is restricted to re-assigning windows owned by the process that invokes it. This is a restriction imposed by the SetWindowLong function (see: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx[^]; for the doc on GWL_WNDPROC).

Here is a version that works for a TextBox on the form.

Imports System.Runtime.InteropServices

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      SubclassHWnd(TextBox1.Handle)
   End Sub

   ' Win32 API needed
   <DllImport("user32")> _
   Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal newProc As Win32WndProc) As IntPtr
   End Function
   <DllImport("user32")> _
   Private Shared Function CallWindowProc(ByVal lpPrevWndFunc As IntPtr, ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
   End Function

   ' A delegate that matches Win32 WNDPROC:
   Private Delegate Function Win32WndProc(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

   ' from winuser.h:
   Private Const GWL_WNDPROC As Integer = -4
   Private Const WM_LBUTTONDOWN As Integer = &H201

   ' program variables
   Private oldWndProc As IntPtr = IntPtr.Zero
   Private newWndProc As Win32WndProc = Nothing

   Private Sub SubclassHWnd(ByVal hWnd As IntPtr)
      ' hWnd is the window you want to subclass..., create a new 
      ' delegate for the new wndproc
      newWndProc = New Win32WndProc(AddressOf MyWndProc)
      ' subclass
      oldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, newWndProc)
   End Sub

   ' this is the new wndproc, just show a messagebox on left button down:
   Private Function MyWndProc(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
      Select Case Msg
         Case WM_LBUTTONDOWN
            MessageBox.Show("Clicked")
            Return 0
         Case Else

            Exit Select
      End Select

      Return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam)
   End Function

   '=======================================================
   'Service provided by Telerik (www.telerik.com)
   'Conversion powered by NRefactory.
   'Twitter: @telerik, @toddanglin
   'Facebook: facebook.com/telerik
   '=======================================================

End Class
This is pointless to do as there are other mechanisms to gain access to a textbox's WndProc method. The simplest would be to create custom textbox control and override it's WndProc method.

Public Class mtTB
   Inherits TextBox
   Private Const WM_LBUTTONDOWN As Integer = &H201

   Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
      MyBase.WndProc(m)
      Select Case m.Msg
         Case WM_LBUTTONDOWN
          ' do something

      End Select
   End Sub
End Class
Or you could create a native window listener as shown here.[^]
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 20:43
treddie1-Jul-13 20:43 
GeneralRe: How to get address of a function or method Pin
TnTinMn2-Jul-13 7:32
TnTinMn2-Jul-13 7:32 
GeneralRe: How to get address of a function or method Pin
treddie2-Jul-13 9:35
treddie2-Jul-13 9:35 
AnswerRe: How to get address of a function or method Pin
Bernhard Hiller1-Jul-13 0:57
Bernhard Hiller1-Jul-13 0:57 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 12:18
treddie1-Jul-13 12:18 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 20:30
treddie1-Jul-13 20:30 
AnswerRe: How to get address of a function or method Pin
Richard Deeming1-Jul-13 1:54
mveRichard Deeming1-Jul-13 1:54 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 12:20
treddie1-Jul-13 12:20 
GeneralRe: How to get address of a function or method Pin
treddie1-Jul-13 19:29
treddie1-Jul-13 19:29 
GeneralRe: How to get address of a function or method Pin
Richard Deeming2-Jul-13 1:25
mveRichard Deeming2-Jul-13 1:25 
GeneralRe: How to get address of a function or method Pin
treddie2-Jul-13 9:41
treddie2-Jul-13 9:41 
QuestionHow to express this in a Regex? Pin
Sonhospa28-Jun-13 0:50
Sonhospa28-Jun-13 0:50 
AnswerRe: How to express this in a Regex? Pin
thanh_bkhn28-Jun-13 2:50
professionalthanh_bkhn28-Jun-13 2:50 
News[RESOLVED] Re: How to express this in a Regex? Pin
Sonhospa28-Jun-13 2:59
Sonhospa28-Jun-13 2:59 
QuestionMS at it again Pin
treddie26-Jun-13 19:57
treddie26-Jun-13 19:57 
AnswerRe: MS at it again Pin
Eddy Vluggen27-Jun-13 0:23
professionalEddy Vluggen27-Jun-13 0:23 
GeneralRe: MS at it again Pin
treddie28-Jun-13 11:20
treddie28-Jun-13 11:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.