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
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

the OSD triggers for every wParam=12 event


Thank you. I will correct it.

similar topic. sound alert whenver a network cable is unplugged. any idea?


Sorry! I do not know of a solution for it.

( Wake up forum! Wake up! )

howardb1
  • Guests
  • Last active:
  • Joined: --
I don't know if you're still working on this AutoHotKey trick or not, but if you are ...

You say "The shell receives HSHELL_GETMINRECT ( with a shellhook structure ) whenever a window is being Minimised/Maximised. A script may monitor it to Minimize a window to the tray." In the code I'm writing based on your techique I just need the hWnd member, but it isn't clear how you access it?

My script hides the taskbar before opening a program, but I want to restore the taskbar when the program exits, or when it is minimized or looses focus. In the last two cases I'll then hide the taskbar when the program becomes active again.

I've written the exit part, and am now working on the minimize part, but I don't see an event message that tells me when the window is loosing focus, only when it gets it back.

Thank you.

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

You say "The shell receives HSHELL_GETMINRECT ( with a shellhook structure ) whenever a window is being Minimised/Maximised. A script may monitor it to Minimize a window to the tray."


I was using Window 98 while I was experimenting.. and then I shifted My OS to 2k and currently using XP.
I can safely say HSHELL_GETMINRECT is very unpredictable in different OSes.
( If it works at all and ) If you are to use it only on your system, you are lucky. Otherwise, I do not recommend SHELLHOOK to monitor Maximize/Minimize events.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Does anybody have problems with Shell hook and activation ?

I don't receive notifications on Vista. For instance, here is the output of SKANs utuility where different windows were activated:



UNKNOWN  [32772]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x3f0184
Title	: EditPlus [_Taskbar] - [D]
Class	: Afx:400000:8:10003:0:58044f

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x1e0118
Title	: Total Commander 7.04a
Class	: TTOTAL_CMD

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x3f0184
Title	: EditPlus [_Taskbar] - [D]
Class	: Afx:400000:8:10003:0:58044f

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x3f0184
Title	: EditPlus [_Taskbar] - [D]
Class	: Afx:400000:8:10003:0:58044f

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x1e0118
Title	: Total Commander 7.04a 
Class	: TTOTAL_CMD

UNKNOWN  [32772]

hWnd	: 0x2a8051e
Title	: Tips N Tricks - Opera
Class	: OpWindow

UNKNOWN  [32772]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x2a8051e
Title	: Tips N Tricks - Opera
Class	: OpWindow

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x1e0118
Title	: Total Commander 7.04a 
Class	: TTOTAL_CMD

HSHELL_SYSMENU  [9]

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_WINDOWDESTROYED  [2]

hWnd	: 0x0
Title	: 
Class	: 

HSHELL_REDRAW  [6]

hWnd	: 0x0
Title	: 
Class	: 

UNKNOWN  [32772]

hWnd	: 0x0
Title	: 
Class	:

Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Activation definitely doesn't work correctly. The same code works on XP and doesn't work on VISTA, and sometimes it even stops working in XP.
Posted Image

zhuluobin
  • Members
  • 28 posts
  • Last active: Aug 07 2010 12:53 PM
  • Joined: 11 May 2009
i used shellhook code but while i right clicked 'my computer' on start menu to open 'system properties' i received nothing.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

Does anybody have problems with Shell hook and activation ?

Yes here!

I'm glad its not just me thats having shell notification problems.
I thought I wasnt feeding the proper hWnd or something.

In some cases even normal Windows Messages are not detected with OnMessage.
I think there has to be a more robust method for using a given handle :? ..


here is the output of SKANs utuility

Where to find it plz?
Oh, its Shell Spy.. Got it :)

Ok so it looks like the hook method only works on toplevel windows.

There must be a way to hook all window and even control handles!

Posted Image

don't duplicate, iterate!


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

i used shellhook code but while i right clicked 'my computer' on start menu to open 'system properties' i received nothing.


it looks like the hook method only works on toplevel windows.


SHELLHOOK works only on toplevel windows. The OS messages the Shell whenever a window is created/destroyed so that taskbar can update its buttons.
For windows which do not have a taskbar button, the messages will not be sent, which makes sense.

With SHELLHOOK method, we merely intercept the messages without much load on the system resources.

There must be a way to hook all window and even control handles!


Try WinEventHook Messages by Serenity

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

For windows which do not have a taskbar button, the messages will not be sent, which makes sense.

Explained that way, it absolutly does make sense!

thnx for the WinEventHook link :mrgreen:

Posted Image

don't duplicate, iterate!


dotslashc
  • Members
  • 9 posts
  • Last active: Nov 04 2010 10:51 AM
  • Joined: 28 Oct 2010

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 ) {
; Execute a command based on wParam and lParam
}


Hi,
THanks for this. I have a question regarding this? How do I add this code to default Autohotkey script that I use (the one with my regular hotkey /hotstrings etc?)

I tried adding this code as it is at end of the file , it doesn't work however.

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

I tried adding this code as it is at end of the file , it doesn't work however.


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

Please refer AHK Documentation for 'auto-execute section'.
Revert back if you have a problem in understanding the concept.

:)

dotslashc
  • Members
  • 9 posts
  • Last active: Nov 04 2010 10:51 AM
  • Joined: 28 Oct 2010

I tried adding this code as it is at end of the file , it doesn't work however.


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

Please refer AHK Documentation for 'auto-execute section'.
Revert back if you have a problem in understanding the concept.

:)


Silly me. :oops:
Thanks for the pointer.

dotslashc
  • Members
  • 9 posts
  • Last active: Nov 04 2010 10:51 AM
  • Joined: 28 Oct 2010
Unfortunately not working for me still.
I am trying to include some other scripts i found here.
#include %A_ScriptDir%\My Scripts\notifylockunlock.ahk
#include %A_ScriptDir%\My Scripts\iSwitcher.ahk

notify_lock_unlock()
; Calls function "on_lock()" when computer is locked and "on_unlock()" when computer is unlocked

Does location of these lines make difference? My understanding is that #include directive execute the script in included AHK file immediately. Will the return command in included file affect what I am trying to do?

If I put above code before the following code
Gui +LastFound
hWnd := WinExist()

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

Then only iSwitcher and notifyunlocklock works. If I put it later only the "RegisterShellHookWindow" code works. :(

I really want to keep my include files seperate. Any workaround?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
It is preferable that you use #include at the end of the script.

dotslashc
  • Members
  • 9 posts
  • Last active: Nov 04 2010 10:51 AM
  • Joined: 28 Oct 2010

It is preferable that you use #include at the end of the script.


Yup, tried this. Now my iSwitcher script is causing issue. The pretty UI of this script doesn't show up.

Edit: I guess I have no choice but to run iSwitcher in seperate script.