Jump to content



Photo

Subclassing windows in other processes


  • Please log in to reply
4 replies to this topic

#1 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 05 May 2009 - 04:46 PM

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:

AutoIt         
#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
  • qsek likes this







#2 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 05 May 2009 - 07:46 PM

Looks really good  ^_^

#3 Creator

Creator

    Adventurer

  • Active Members
  • PipPip
  • 129 posts

Posted 05 May 2009 - 07:59 PM

Running Vista here and it works fine!

Nicely done. ^_^

#4 sandin

sandin

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 569 posts

Posted 05 May 2009 - 08:30 PM

tnx again for this tool, it's amazing! ^_^

#5 ziggery

ziggery

    Seeker

  • Normal Members
  • 5 posts

Posted 14 September 2012 - 04:38 PM

awesome tool




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users