Jump to content

How to intercept new window ?


EjnarH
 Share

Recommended Posts

You can take this code as basic to hook window creation

#include <GUIConstantsEx.au3>
#include "DllCallBack.au3"

Global Const $WH_MOUSE = 0x7

Global $hMouseHook, $pStub_MouseProc, $hWnd_ui

$dwThread = DllCall("kernel32.dll", "dword", "GetCurrentThreadId")
$dwThread = $dwThread[0]
$pStub_MouseProc = _DllCallBack ("_MouseProc", "int;ptr;ptr")
$hMouseHook = DllCall("user32.dll", "ptr", "SetWindowsHookEx", "int", $WH_MOUSE, "ptr", $pStub_MouseProc, "ptr", 0, "dword", $dwThread)
$hMouseHook = $hMouseHook[0]

$hWnd_ui = GUICreate("")
GUISetState()

While 1
    If $GUI_EVENT_CLOSE = GUIGetMsg() Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "ptr", $hMouseHook)
        _DllCallBack_Free ($pStub_MouseProc)
        Exit
    EndIf
    Sleep(10)
WEnd

Func _MouseProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
    $vMHS = DllStructCreate("long;long;hwnd;uint;dword;dword", $lParam)
    WinSetTitle($hWnd_ui, "", "X: " & DllStructGetData($vMHS, 1) & " Y: " & DllStructGetData($vMHS, 2) & " HitTest: " & DllStructGetData($vMHS, 4))
    Return 0
EndFunc  ;==>_MouseProc

Func _CallNextHookEx($hhk, $nCode, $wParam, $lParam)
    Local $aTmp = DllCall("user32.dll", "long", "CallNextHookEx", "ptr", $hhk, "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $aTmp[0]
EndFunc  ;==>_CallNextHookEx

However you need $WH_CBT = 5 instead of $WH_MOUSE. And your hook procedure have to have the filter for HCBT_CREATEWND = 3 code.

The point of world view

Link to comment
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
 Share

  • Recently Browsing   0 members

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