CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Posts
    1

    How to write a message handler for WM_USER


    I want to write a message handler
    for user defined message(WM_USER + N) in Visual Basic.
    The message is sent to my visual basic application from DLL.
    I wrote the DLL in Visual C++.
    Anyone help me?

    Thanks in advance!




  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How to write a message handler for WM_USER

    MSDN article Q170570 has all the details for doing what you want.

    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

    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (byval hWnd as Long, _
    byval nIndex as Long, _
    byval dwNewLong as Long) as Long

    public Const GWL_WNDPROC = -4

    public Const WM_USER = &H400
    public Const MY_MSG = &H400 +1

    Global lpPrevWndProc as Long
    Global gHW as Long

    public Sub Hook()
    lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    AddressOf WindowProc)
    End Sub

    public Sub UnHook()
    Dim lngReturnValue as Long
    lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    End Sub

    Function WindowProc(byval hw as Long, _
    byval uMsg as Long, _
    byval wParam as Long, _
    byval lParam as Long) as Long

    Select Case uMsg
    Case MY_MSG
    'your code goes here
    Case else
    WindowProc = CallWindowProc(lpPrevWndProc, hw, _
    uMsg, wParam, lParam)
    End Select
    End Function








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

Featured