Results 1 to 4 of 4

Thread: Sendmessage

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    62
    Is it possible to intercept a program's messages and alter them to trick the program into thinking it is getting a return when it is not really communicating with the other program?

  2. #2
    Member
    Join Date
    Oct 2000
    Posts
    35
    You can intercept the messages to a certain windowhandle.
    You need either a subclasscontrol like SubClass from desaware or you can install it by yourself, using 'VB.AddressOf'.

    This is a quite advanced topic, you can crash almost anything ...
    rfo

  3. #3
    Guest
    Here is an example of SubClassing. It will intercept the Right-click of a TextBox, hence disabling the context menu.

    Add the following 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_RBUTTONDOWN = &H204
    Const MK_RBUTTON = &H2
    Public 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_RBUTTONDOWN And wParam = MK_RBUTTON Then
            Exit Function
        End If
        
        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 the following to a Form with a TextBox.
    Code:
    Private Sub Form_Load()
        SubClassWnd Text1.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd Text1.hwnd
    End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    62
    Thanks Megatron and rfo. One more question about this...
    Say I have a window that I know is going to recieve a kill sendmessage. How would I implement this to intercept the message (thus keeping the window from closing) if the hwnd of the window is something like "121232"

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