Jump to content
Sign in to follow this  
sandin

RegisterMsg from other windows

Recommended Posts

sandin
Yashied
sandin

yup, I've tried several things, this is what I've got so far:

#Include <WinAPI.au3>
HotKeySet("{ESC}","close")

$callback=DllCallbackRegister("_Intercept","lresult","int;wparam;lparam")

Run("winmine.exe")
WinWait("Minesweeper")
WinActivate("Minesweeper")

$module=_WinAPI_GetModuleHandle(0);WinGetHandle("Minesweeper")) ;<--- dunno what to set here
$hook=_WinAPI_SetWindowsHookEx($WH_GETMESSAGE,DllCallbackGetPtr($callback),$module)

TrayTip("", "I should be able to hook msges now", 10)

While 1
    Sleep(10)
WEnd

Func _Intercept($nCode,$wParam,$lParam)
    TrayTip("message!", $nCode & @CRLF & $wParam & @CRLF & $lParam, 10)
EndFunc

Func close()
    _WinAPI_UnhookWindowsHookEx($hook)
    DllCallbackFree($callback)
EndFunc

NOT working yet ^_^

Share this post


Link to post
Share on other sites
WideBoyDixon

Something in the back of mind is niggling me. I seem to recall that your hook procedure has to be in a separate DLL and that's not something that can be achieved through AutoIt. However, I might be wrong. It's been known.

Share this post


Link to post
Share on other sites
Yashied

Something in the back of mind is niggling me. I seem to recall that your hook procedure has to be in a separate DLL and that's not something that can be achieved through AutoIt. However, I might be wrong. It's been known.

What do you think why there is a DllCallbackRegister()?

Share this post


Link to post
Share on other sites
ProgAndy

To install a hook in an external application, you need a DLL with the hook-procedure.

DLLCallbackREgister registers a function that can be called from a DLL loaded into the AutoIt-porcess. This functions can not be called from external processes.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Yashied

To install a hook in an external application, you need a DLL with the hook-procedure.

DLLCallbackREgister registers a function that can be called from a DLL loaded into the AutoIt-porcess. This functions can not be called from external processes.

You're right, but $WH_KEYBOARD_LL works fine.

Share this post


Link to post
Share on other sites
Yashied
sandin

I'm making a script that will be able to control my PC over my remote control, so when I press a key on my remote control, my PC will perform certain command. (I already linked those two, and that's fully working)

I would like my script to be able to send msges to other windows, like winamp for example, and send certain msg,wparam,lparam for switching the track, changing volume etc... (I know there is already winamp UDF, but I want this option to be available for all applications, not only winamp) (sending msges is also working, and I have no issues with this)

in order to find out which msg does what in desired window I need to hook window and all his msges, but I dunno how to do so.

Share this post


Link to post
Share on other sites
Yashied

I'm making a script that will be able to control my PC over my remote control, so when I press a key on my remote control, my PC will perform certain command. (I already linked those two, and that's fully working)

I would like my script to be able to send msges to other windows, like winamp for example, and send certain msg,wparam,lparam for switching the track, changing volume etc... (I know there is already winamp UDF, but I want this option to be available for all applications, not only winamp) (sending msges is also working, and I have no issues with this)

in order to find out which msg does what in desired window I need to hook window and all his msges, but I dunno how to do so.

Thank you. Excellent idea. But I think that the analysis of messages by means of hook hardly a difficult task and it is unlikely that this will be justified. I am sure that your idea can be realized without using a hook. I think better to use the emulation of key presses, because most players support hot keys. But in any case, you know what to do.

Thanks again.

Share this post


Link to post
Share on other sites
sandin

ya, that is true, about hotkeys in players, but there's one issue, the player window must be active one for those hotkeys to work, and if I'm for example running some audio player, and have game running in fullscreen on my PC then the hotkey wouldn't work.

It would be great if someone could show me an example of receiving other window msges without hooking them.

anyway, I tried this:

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>
#include <_RegisterClassEx.au3>

Run("winmine.exe")
WinWait("Minesweeper")
WinActivate("Minesweeper")

$win_handle = WinGetHandle("Minesweeper")

$class = _WinAPI_GetClassName($win_handle)
ConsoleWrite("win title: " & WinGetTitle($win_handle) & @CRLF & _
            "win handle: " & $win_handle & @CRLF & _
            "win class: " & $class & @CRLF)

_WinAPI_RegisterClassEx($class, "WindowCallback", 0, 0, 0xFF0000, $CS_DEFAULTSTYLE)

;~ $hWnd = _WinAPI_CreateWindowEx(0, $class, "title", $WS_OVERLAPPEDWINDOW, 100, 100, 400, 300, 0)
;~ _WinAPI_ShowWindow($hWnd)

While 1
    Sleep(10)
WEnd

Func WindowCallback($hWnd, $iMsg, $wParam, $lParam)
    TrayTip("", $iMsg & @CRLF & $wParam & @CRLF & $lParam, 10)
;~  Sleep(1000)
    Switch $iMsg
        Case $WM_CLOSE
            _WinAPI_UnregisterClass($class)
            Exit
    EndSwitch
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

tried to hook win's class, but u'll need this: RegisterClass

Share this post


Link to post
Share on other sites
WideBoyDixon

I you want to be able to peek at windows messages being sent to other applications/windows then you need to install a global hook. However, this hook procedure *must* reside in a DLL so that it can be injected in to the application's process space (I believe). I could write a C++ DLL that allows you to hook windows messages but I would need to know which messages you want to receive information on. There's plenty of code on CodeProject and CodeGuru about doing it as well so perhaps you could take a look there.

WBD

Share this post


Link to post
Share on other sites
sandin

You would do that for me? I would like that very much ^_^ (since I have no skills in other prog. languages)

ok here's what I need. For example I hook winamp, and when I press "play" button on winamp, the hook program retrieves code: 40045 ,which stands for "play" function in winamp which I can use with:

DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle("[CLASS:Winamp v1.x]"), "int", $WM_COMMAND, "int", 40045, "int", 0) ;PLAY func. in winamp

Those are general messages (which you can get on au3 windows with GUIGetMsg() func.), but for WinFast PVR (my TV card application), it's always the same message, but different wparam, so I guess I need a hook window that can retrieve all 3, message, wparam and lparam from other windows.

I would like to be able to find out which message stands for play/pause/stop etc.. for VLC player, maybe BSPlayer, Windows Media Player, or even Media Player Clasic, etc...

Edited by sandin

Share this post


Link to post
Share on other sites
sandin
rover

sry to bring this topc up, but I found something useful.

this is something I need:

something like that "Microsoft Spy++" which can log WM_COMMAND messages.

however I don't have Visual studio C++, therefore I don't have that tool on my PC.

Winspector - hooks messages

http://www.windows-spy.com/

WinSpy++

http://www.catch22.net/software/winspy

Edit: removed quoted images

Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
WideBoyDixon

OK. I think I've 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.

Hope this helps.

WBD

Share this post


Link to post
Share on other sites
sandin
wolf9228

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
HotKeySet("{ESC}","close")
Opt("OnExitFunc", "endscript")
Global $typedefstruct = "hwnd HWND;int message;int wParam;int lParam;int time;ptr pt"
$hWnd = GUICreate("")
$nCtrlID = GUICtrlCreateButton("",2,2,100,100)
GUISetState()

$iPID = Run("winmine.exe")
WinWait("Minesweeper")
WinActivate("Minesweeper")
$ThreadID = _WinAPI_GetWindowThreadProcessId(_WinAPI_GetForegroundWindow(),  $iPID) ; @error ------ _WinAPI_SetWindowsHookEx

$hStub_KeyProc = DllCallbackRegister("GetMsgProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_GETMESSAGE , DllCallbackGetPtr($hStub_KeyProc), $hmod,_WinAPI_GetCurrentThreadId())
TrayTip("", "I should be able to hook msges now", 10)
dim $M , $W , $L , $T , $X , $Y,$H
While 1
    Sleep(10)
    TrayTip("","HWND ==>" & $H & @CRLF & "message ==>" & $M & @CRLF & "wParam ==>" & $W & @CRLF & "lParam ==>" & $L & @CRLF _
    & "time ==>" & $T & @CRLF , 10)
WEnd

Func GetMsgProc($nCode,$wParam,$lParam)
$PMSG = DllStructCreate($typedefstruct, $lParam)
$H = DllStructGetData($PMSG,"HWND")
$M = DllStructGetData($PMSG,"message")
$W = DllStructGetData($PMSG,"wParam")
$L = DllStructGetData($PMSG,"lParam")
$T = DllStructGetData($PMSG,"time")
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Func close()
Exit
EndFunc

Func endscript()
  _WinAPI_UnhookWindowsHookEx($hHook )
    DllCallbackFree($hStub_KeyProc)
EndFunc


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
WideBoyDixon

That's great if you want to hook windows in the current thread. Not much use for peeking at messages in other processes though ^_^

WBD

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.