Results 1 to 2 of 2

Thread: WindowsProc Samples

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    I was wondering if anybody has any samples on how to use the WindowsProc API.

    Many thanks,
    Desire

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's a quick example which disables the ability to Paste within a Textbox:
    Code:
    'In a Module..
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Const GWL_WNDPROC = (-4)
    Private Const WM_PASTE = &H302
    
    Private lPrevWndFunc As Long
    
    Private Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If Msg <> WM_PASTE Then
            'Prevent the Paste Message from Being Processed by the Textbox
            WindowProc = CallWindowProc(lPrevWndFunc, hWnd, Msg, wParam, lParam)
        End If
    End Function
    
    Public Sub SubClassWnd(ByVal hWnd As Long)
        'Start Subclassing the Specified Window
        lPrevWndFunc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    
    Public Sub EndSubClass(ByVal hWnd As Long)
        'End Subclassing of the Specified Window
        Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWndFunc)
    End Sub
    Code:
    'In a Form with a Textbox..
    Private Sub Form_Load()
        'Subclass the Textbox
        SubClassWnd Text1.hWnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Remove the Subclassing on the Textbox
        'MUST be done, do NOT close the App using the End Button
        'Close the Form Normally First, or VB WILL CRASH!!
        EndSubClass Text1.hWnd
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width