Jump to content

Window Hooks?


Recommended Posts

lod3n suggested at one point making an autoit script to allow windows to snap together, similar to this: http://www.cs.utoronto.ca/~iheckman/allsnap/

Additionally, being able to catch the "maximize window" event and reinterpret it would be sweet... I'd like to try to get both implemented into splitmon script I'm working on (sig).

so basically... is this possible, and if so, how do you do it? Or even better, has someone already done it?

Searching around did not yield much...

Link to comment
Share on other sites

I'm making progress Larry, thanks for the suggestions. One question though: where do you get these values?

Const $HCBT_SETFOCUS = 0x1400 + 0x1A30
Const $HCBT_ACTIVATE = 0x1400 + 0x1A31
Const $HCBT_CREATEWND = 0x1400 + 0x1A32
Const $HCBT_DESTROYWND = 0x1400 + 0x1A33
Const $HCBT_MINMAX = 0x1400 + 0x1A34

They don't seem to match up with the winuser header... and more to the point, what would $HCBT_MOVESIZE be?

Link to comment
Share on other sites

Hello again! Man, I hope it's warmer than 10 below wherever you guys live. With windchill it hit -40 this morning!

Anyway, question for you Larry: The CBT is indeed returning info that I want (specifically, Maximize Window events), however, it's also returning a bunch of stuff I don't want. Is there some way to tell whether a window is about to be minimized, restored, or maximized... because I can't seem to do that using your CBT hook.

I've posted your code modified below to only return CBT MINMAX info. run it and you'll see that it returns the same message whether being minimzed, restored, or maximized.

One thought I had was to check the mouse position in relation to the window to determine which button was clicked... but that just seems clunky and prone to error.

Any ideas on how to get this to work?

Const $WH_CBT = 5
Const $HCBT_MINMAX = 0x1400 + 0x1A34

Global $n,$msg,$buffer = ""


$gui = GUICreate("test")

Global $DLLinst = DLLCall("kernel32.dll","hwnd","LoadLibrary","str",".\hook.dll")
Global $cbtHOOKproc = DLLCall("kernel32.dll","hwnd","GetProcAddress","hwnd",$DLLInst[0],"str","CBTProc")

Global $hhCBT = DLLCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_CBT, "hwnd",$cbtHOOKproc[0],"hwnd",$DLLinst[0],"int",0)



While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then ExitLoop

Func MyCBTFunc($hWndGUI, $MsgID, $WParam, $LParam)
    $n += 1
    If $n > 25 Then
        $n = 25
        $buffer = StringTrimLeft($buffer,StringInStr($buffer,@LF))
    $buffer &= "CBT: " & $MsgID & "," &  $WParam & "," &  $LParam & @LF
    ToolTip($buffer, 0, 0)

Func GoAway()

Func OnAutoItExit()

Edit: it would appear that I probably won't be able to block whatever operation the CBT is reporting (correct me if I'm wrong). That being the case, perhaps I'll just check window position info after a CBT message to determine what happened and then reinterpret it as I see fit.

Messy though, I would still appreciate any other ideas someone might have.

Edited by fisofo
Link to comment
Share on other sites

Sounds good... yep, it looks like lParam always returns 0, so that's probably the missing link. Thanks for continuing to look at this with me, have a great superbowl Sunday!

Link to comment
Share on other sites

Sweetness, that's perfect Larry.

For those interested, here's the CBT LParam returns:

; LParam = 3 = maximize
; LParam = 6 = minimize
; LParam = 9 = restore

which, of course, are equivalent to our good friends @SW_MAXIMIZE, etc...

Edited by fisofo
Link to comment
Share on other sites

  • 5 months later...

I need to intercept creation of a window so I can move and resize it before it appears. Using the code in this thread and in mousehook allows me to receive notification of the window opening, but I can't find a way to block it opening or change it's parameters. All I can do is resize/move it afterwards causing an annoying flash as the window opens in it's original position and then gets moved.

According to the info I've read cbt hooks allow you to block and change the hooked action but I can't figure out how to do it with hook.dll, it just seems to pass the messages on.

Could someone please help me on this?

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

  • Recently Browsing   0 members

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