Results 1 to 7 of 7

Thread: Capturing Messages

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    51

    Unhappy

    I need to capture the wm_paint event from a window other than a visual basic window, anyone got any idea's how to do it???

  2. #2
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Talking I've wondered to.

    I've wondered that to, and I know it's definatley possible, but maybe not with VB as such, cause all them Spy Utilities do it.

    Anyway, anyone with info please share
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  3. #3
    Guest
    SubClass your window.

    Add to a Module
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    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
    Const GWL_WNDPROC = (-4)
    Const WM_PAINT = &HF
    
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
        If wMsg = WM_PAINT Then Debug.Print "PRINT MESSAGE SENT"
      
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
        
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Add to a Form
    Code:
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Subclassing works with everything right, as long as you have the hWnd?

    That is cool, I could subclass games to stop redrawing, that would be creepy
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Guest
    Yes, Subclassingworks as long as you have the hWnd, and as long as it has it's in the same thread as yours.

    To subclass windows that are not in your thread, you need to place you routine in a standard DLL.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    51
    yeah cheers for all your help, I found out it can only be placed in a dll, but I also found out you can't wrtie the dll in vb, you have to do it in c++. Oh well better get me C++ manual out...lol

  7. #7
    Guest
    Well, it doesn't really have to be written in C++. C++ is just the idle language to do it in. The DLL can be written in any environment that can create standard DLLs, e.g: Delphi.

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