Results 1 to 5 of 5

Thread: [RESOLVED] CallWindowProc

  1. #1

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Resolved [RESOLVED] CallWindowProc

    Hello,

    I am trying to get my head around subclassing at the moment using SetWindowLong and CallWindowProc. So far it is a disaster. I am just trying to make a simple example.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function CallWindowProc _
    4.     Lib "user32" _
    5.     Alias "CallWindowProcA" ( _
    6.         ByVal lpPrevWndFunc As Long, _
    7.         ByVal hWnd As Long, _
    8.         ByVal Msg As Long, _
    9.         ByVal wParam As Long, _
    10.         ByVal lParam As Long) _
    11.         As Long
    12.        
    13. Private Declare Function SetWindowLong _
    14.     Lib "user32" _
    15.     Alias "SetWindowLongA" ( _
    16.         ByVal hWnd As Long, _
    17.         ByVal nIndex As Long, _
    18.         ByVal dwNewLong As Long) _
    19.         As Long
    20.  
    21. Private Const GWL_WNDPROC = (-4)
    22.  
    23. Private Const WM_MOUSEMOVE = &H200
    24.  
    25. Private OldWindowProc       As Long
    26.  
    27. Public Sub SubClass(frm As Form)
    28.  
    29.     OldWindowProc = SetWindowLong(frm.hWnd, GWL_WNDPROC, AddressOf NewWindowProc)
    30.  
    31. End Sub
    32.  
    33. Public Sub UnSubClass(frm As Form)
    34.  
    35.     Call SetWindowLong(frm.hWnd, GWL_WNDPROC, OldWindowProc)
    36.    
    37. End Sub
    38.  
    39. Public Function NewWindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Long) As Long
    40.    
    41.     If Msg = WM_MOUSEMOVE Then
    42.        
    43.         Form1.Caption = "Mouse is moving..."
    44.    
    45.     End If
    46.    
    47.     NewWindowProc = CallWindowProc(OldWindowProc, hWnd, Msg, wParam, lParam)
    48.    
    49. End Function

    The idea behind it is that i am trying to process the WM_MOUSEMOVE message once the mouse moves on the form, then it will display a message in the form caption to say that the mouse is being moved.

    The best that it does at the moment is force VB to close and i get a GPF.

    Any ideas on how i can make this work?

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: CallWindowProc

    VB Code:
    1. Public Function NewWindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, [B]ByVal [/B]lParam As Long) As Long

  3. #3

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: CallWindowProc

    Wow, that was embarrasing, i can't believe i missed it

    Thanks BushMobile

  4. #4

  5. #5

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: [RESOLVED] CallWindowProc

    You are correct. This is a in a code module because i didn't pass lParam by value caused me to get a GPF. As far as i am a aware you would not be able to use NewWindowProc in conjuction with AddressOf in a form, i don't think it would compile.

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