Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How to] Hook on to Shell to receive its messages?


  • Please log in to reply
73 replies to this topic
Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Works on my XP SP2 UK English, Although I did have a strange occurance of having 32772 instead of 17 for hshell_rudeactivated or whatever it is.
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

0inprogram
  • Members
  • 21 posts
  • Last active: Aug 11 2008 04:51 AM
  • Joined: 06 Dec 2007
using code of experiment 1, how can i check whether a site is accessed thru the browser and run a set of commands based on it....
like filling the id and password ,etc....

i tried putting the name of the website in the "title" field, but it didnt work,...

0inprogram
  • Members
  • 21 posts
  • Last active: Aug 11 2008 04:51 AM
  • Joined: 06 Dec 2007
this is the code i was talking abt ,

#Persistent
SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam ) {
  If ( wParam = 1 ) ;  HSHELL_WINDOWCREATED := 1
     {
       WinGetTitle, Title, ahk_id %lParam%
       If  ( Title = "Windows Task Manager" ) 
         {
           WinClose, ahk_id %lParam%
         ; Run, Calc.exe              ; instead
         }
     }
}


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

i tried putting the name of the website in the "title" field, but it didnt work,...


This SHELLHOOK method will at most can alert you when a IEFrame ( or mozilla or opera ) becomes active.

You have to check the titlebar / address bar if want to conditionally execute code.

:)

0inprogram
  • Members
  • 21 posts
  • Last active: Aug 11 2008 04:51 AM
  • Joined: 06 Dec 2007
how can i get the titlebar and conditionaly execute code, in tht same script

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

how can i get the titlebar and conditionaly execute code, in tht same script


Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )

Return ;                                                 // End of Auto-Execute Section //

ShellMessage( wParam,lParam ) {
if ( wParam = 4 or wParam = 1 ) ; HSHELL_WINDOWACTIVATED / CREATED
  {
    WinGetClass, Class, ahk_id %lParam%
    If Class in IEFrame,MozillaWindowClass,OpWindow
         SetTimer, CheckWinTitle, 100
    Else SetTimer, CheckWinTitle, OFF           
  }
}

CheckWinTitle:
   WinGetTitle, Title, A
   If InStr( Title, "youtube" )
   or InStr( Title, "orkut" )
   or InStr( Title, "autoit" ) ;)
      WinClose, A
Return

Somebody wrote a stupid prank with autohotkey, the above imitates it.

:)

0inprogram
  • Members
  • 21 posts
  • Last active: Aug 11 2008 04:51 AM
  • Joined: 06 Dec 2007
it works fine with IE, but doesnt respond with firefox

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

doesnt respond with firefox


I have used the wrong window class.
It should have been MozillaUIWindowClass.

Also, I do not know the correct class name for opera.
I retrieved both of them from our forum's search.

:)

0inprogram
  • Members
  • 21 posts
  • Last active: Aug 11 2008 04:51 AM
  • Joined: 06 Dec 2007
thank u ........ :)

thewer
  • Members
  • 13 posts
  • Last active: Mar 12 2010 08:16 AM
  • Joined: 12 Feb 2008
Hi there -

I was experimenting with Skan's Example Nr. 5 as I wanted to do a script that - every time a window is maximized - maximizes the window to a certain size only.

Unfortunately I've got the same problems as shader (XP Prof. SP2, German version, one monitor only).

Took me some time to understand the script, but even now I can't get the HSHELL_GETMINRECT message:
I monitored the parameters

OnMessage( MsgNum, "ShellMessage" )

with

ShellMessages (Msg,hWnd,wParam,lParam)
Msgbox...
(I think the last two parameters only state what kind of message it is...)

While Msg monitors the creating and destroying etc. of any window correctly, max- and minimizing doesn't trigger the OnMessage with me.
(tried Skan's Example Nr. 4 - in this script, these actions don't show up, too)
Anyone got an idea why?

Thanks for your help! :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Took me some time to understand the script, but even now I can't get the HSHELL_GETMINRECT message:


HSHELL_GETMINRECT used to show up in my ShellSpy in Win98, 2K and XP, but it did not when I checked now. :shock:

I was late to suspect my nVidia display in which I had enabled fast minimize / maximize. It had been injecting a DLL proc into every window and was monitoring HSHELL_GETMINRECT !

My code works only if I disable it :(

I even tried SetWindowsHookEx to inject a Dll proc, but in vain.
My best guess is that nVidia is is not using CallNextHookEx, so no other app can receive that particular Shell notification.

Sorry for the delay in reply as it took me time for research.

:)

thewer
  • Members
  • 13 posts
  • Last active: Mar 12 2010 08:16 AM
  • Joined: 12 Feb 2008
Hi -
thanks for your reply! :)

Yes, I've got an Nvidia card as well - disabled the fast min-/maximize and now it at least shows the HSHELL_GETMINRECT, every time I minimize a window, not on maximize or restore...
It really seems to be an interaction with the Nvidia Desktop Manager (I don't have a clue how you found out this one... :O ), interesting thing is, that you can't really disable the wretched thing (I had it disabled actually, still the fast minimize was set).

What I also did: After disabling the fast minimize, I switched off the "menu blending in" effects in the Windows desktop settings, so minimizing windows was fast again - Now the GETMINRECT doesn't show up anymore, too, but on minimizing a window the window is destroyed...

And - suddenly the HSHELL_WINDOWACTIVATED seems to have the code "32772" instead of "4"...

Maybe I should give up coding... :shock:

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
I don't have a clue how you found out this one... :o

It used to work flawlessly before I upgraded the display, and hence it should have been obvious. :)

BTW, may I know what you are exactly upto.
There is a ahkhook.dll by JGR with which we can monitor window activities.

:)

thewer
  • Members
  • 13 posts
  • Last active: Mar 12 2010 08:16 AM
  • Joined: 12 Feb 2008
Hi -

what I'm trying to do is very similar to your example nr. 5, but maybe it's better to go into detail:

I normally use AveDesk for creating desklets/widgets and recently discovered the power of AHK, which can be nicely integrated.

So I got a kind of system information bar made with AveDesk on top of my screen (Landvermesser did similar stuff with AHK I think) and I don't want maximized windows to overlap it or vize versa the bar overlapping the window/ the window buttons.

Now I'm trying to create a script, that amongst others - every time a window is maximized - maximizes it to a certain size only (leaving a free space for the bar).

I thought the Shell hook would be the smoothest and fastest solution for it and probably the one eating the minimum resources (as the script would run all the time).

Guess the dll would be a solution, too, but so far I haven't understand anything about using it (moreover, there seem to be 3 dlls: a cbthook, a wineventhook a callbackhook, all mentioned in this thread...)

Last thing is of course - the hook should be fast, resizing the window best before maximizing it... Maybe a hook would be better watching the maximize/restore button press??
I thought about using WinMove() for resizing, not sure so as this makes a WinRestore() impossible, if I don't store the old x,y,w,h in a variable...

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

So I got a kind of system information bar made with AveDesk on top of my screen (Landvermesser did similar stuff with AHK I think) and I don't want maximized windows to overlap it or vize versa the bar overlapping the window/ the window buttons.

Detecting window maximize is probably the hard way. I think what you're describing can be done with "AppBars." SKAN posted a working example for creating an AppBar (see his second post), and there is also an example by Microsoft.