Jump to content

Subclassing windows in other processes


Recommended Posts

This arose from a topic in the help forum and I'm just cross-posting here at Sandin's suggestion. The problem was how to monitor messages going to another window not controlled by AutoIt. After much searching I found a suitable workaround. First of all you need to download this package: http://allapi.mentalis.org/vbexamples/vbex...xample=DSSUBCLS

Unzip dssubcls.dll in to the same folder as your script. You can then use it to "subclass" any other window. My example in Notepad:

#include <WindowsConstants.au3>
#include <GuiListbox.au3>

Global $hList

_Main()

Exit

Func _Main()
    Local $hGUI = GUICreate("Subclass", 400, 400)
    Local $cList = GUICtrlCreateList("", 8, 8, 384, 384, BitOR($WS_BORDER, $WS_VSCROLL))
    GUISetState()
    $hList = GUICtrlGetHandle($cList)

    Local $hDSSUBCLS = DllOpen("dssubcls.dll")
    Run("Notepad.exe")
    WinWait("[CLASS:Notepad]")
    Local $hNotepad = WinGetHandle("[CLASS:Notepad]")
    Local $hCallback = DllCallbackRegister("_MyCallback", "long", "long;long;long")
    Local $aRet = DllCall($hDSSUBCLS, "long", "SubClass", "hwnd", $hNotepad, "ptr", DllCallbackGetPtr($hCallback), "long", 0, "long", 0, "long", 0, "long", 1)
    $aRet = DllCall($hDSSUBCLS, "long", "UseSendMessage", "long", 1)

    While GUIGetMsg() <> -3
        Sleep(100)
    WEnd

    DllClose($hDSSUBCLS)
    GUIDelete()
EndFunc   ;==>_Main

Func _MyCallback($uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_COMMAND
            If $lParam = 0 Then
                _GUICtrlListBox_AddString($hList, "WM_COMMAND(" & $wParam & "," & $lParam & ")")
            EndIf
    EndSwitch
    Return 0
EndFunc   ;==>_MyCallback

Selecting a menu item from Notepad puts a message in to the list box. Should work for other windows and applications too although I'm not sure what will happen under Vista/Windows7 and whether you're allowed to do this. Note that the "hooked" application does tend to run a little slower and I suspect that's because it's firing messages at _MyCallback() which is taking too long to respond. However, I'm not certain about this.

More information about the "SubClass" function can be found in the TXT file that's also in the package.

Hope this helps. Have fun.

WBD

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...