AutoHotkey Community

It is currently May 26th, 2012, 7:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: February 22nd, 2008, 9:12 pm 
Offline

Joined: January 6th, 2008, 8:09 pm
Posts: 39
Location: Gdi+ v1.1
Hi.
I've done a small script using Your RegisterHookShellWindow function, SKAN. It creates a vista-like fading when a new window is created. Maybe it can be an example? :)

Code:
Gui +LastFound
DllCall("RegisterShellHookWindow",UInt,WinExist())
ShellHook:=DllCall("RegisterWindowMessage",Str,"SHELLHOOK")
OnMessage(ShellHook,"Message")
Return

Message(wParam,lParam)
{
    exclude=#32770   ;If you don’t want to fade certain windows (don’t forget to use a separator)
    if(wParam=1)  ;HSHELL_WINDOWCREATED is 1
    {
        IfWinExist, ahk_id %lParam%
        {
            WinGetClass, class, ahk_id %lParam%
            If(InStr(exclude, class)>0)
                Return
            WinSet, Transparent, 0, ahk_id %lParam%
            Loop 8
            {
                Sleep, 1
                Trans:=A_Index*32-1
                WinSet, Transparent, %Trans%, ahk_id %lParam%
            }
            WinSet, Transparent, OFF, ahk_id %lParam%
        }
    }
}


Hope you like it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2008, 9:52 pm 
Offline

Joined: January 6th, 2008, 8:09 pm
Posts: 39
Location: Gdi+ v1.1
thewer, you can also try to change the work area:

Code:
SysGet, WorkArea, MonitorWorkArea

left := 0
right := A_ScreenWidth-0
top := 0
bottom := A_ScreenHeight-30-WorkAreaBottom ;WorkAreaBottom is needed to don't remove the place occupied by taskbar

VarSetCapacity( area, 16, 0 )
EncodeInteger( left, 4, &area, 0 )  ;Stores the region coordinates to memory
EncodeInteger( top, 4, &area, 4 )
EncodeInteger( right, 4, &area, 8 )
EncodeInteger( bottom, 4, &area, 12 )
DllCall( "SystemParametersInfo", "uint", 0x2F, "uint", 0, "uint", &area, "uint", 0 )

EncodeInteger( p_value, p_size, p_address, p_offset )
{
   loop, %p_size%
      DllCall( "RtlFillMemory"
         , "uint", p_address+p_offset+A_Index-1
         , "uint", 1
         , "uchar", ( p_value >> ( 8*( A_Index-1 ) ) ) & 0xFF )
}


Hope I helped.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2008, 12:09 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
jk7800 wrote:
Hope you like it.


Nice jk7800 :)

I get a flicker when the windows is made transparent on Creation.
FYI, though it cannot be fully eliminated, adding the following lines reduces it:

Code:
Process, Priority,, High
SetBatchlines -1


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 10:15 am 
Offline

Joined: February 12th, 2008, 2:25 pm
Posts: 13
Location: Munich, Germany
Hi -
sorry for the late reply (I'm moving at the moment and needed some time to set up my system again).

@lexiKos:
Thanks - this would be a solution, just not sure I understand all of Skan's appbar at the moment. But I think an invisible child window of the taskbar would do the trick...

@jk7800:
Thanks a lot, too - this sounds easy enough even for me! :D

Well, more questions to come for sure... ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2008, 2:19 pm 
Offline

Joined: July 6th, 2008, 9:19 am
Posts: 101
Hi thanks for the code it was just what i'm looking for.. although i'm having trouble adapting it.

I want to switch between two windows every time i press "a" how would i change the script to release the focus and then reapply it? heres what i have so far but i'm not sure how to let the focus go.

Code:
WinGet, myarray, List, ahk_class ATL:00420130,,gamers

a::

SetBatchLines -1
Process, Priority,, High
DetectHiddenWindows, On                         ; Since Notepad is launched hidden

IfWinActive, ahk_id %myarray1%
{
   
   
   ;WinSet, AlwaysOnTop, Off, ahk_id %myarray1%
   ;WinSet, AlwaysOnTop, On, ahk_id %myarray2%
   ;WinActivate, ahk_id %myarray2%
   
   ;current = ahk_id %myarray2%
   current = %myarray2%
   goto, nextwin
}
IfWinActive, ahk_id %myarray2%
{
   
   ;WinSet, AlwaysOnTop, Off, ahk_id %myarray2%
   ;WinSet, AlwaysOnTop, On, ahk_id %myarray1%
   ;WinActivate, ahk_id %myarray0%
   ;current = ahk_id %myarray1%
   current = %myarray1%
   goto, nextwin
}

MsgBox, %current%
nextwin:



hnp := WinExist(ahk_id %current%)                ; Obtain hwnd
WinSetUnMovable( hnp )                          ; Make the window unmovable
;WinSet, AlwaysOnTop, On, ahk_id %hnp%           ; Flag it Always-On-Top
 
; SHELLHOOK method to detect active window -----------------------------------------------
; Refer Tips N Tricks : http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323

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

; ----------------------------------------------------------------------------------------

OnExit, QuitScript
WinActivate, ahk_id %hnp%
Return ;                                                 // End of Auto-Execute Section //

ShellMessage( wParam,lParam ) {
  global hnp
  If ( wParam=4 && lParam<>hnp ) ; any window other than notepad is activated
       WinActivate, ahk_id %hnp%
  If ( wParam=2 && lParam=hnp ) ; if Notepad window is closed/destroyed
       ExitApp
}

WinSetUnMovable( hwnd ) {
  hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
  nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
  DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-6,"Uint","0x400")
  DllCall("DrawMenuBar","Int",hWnd)
}   

QuitScript:
 ;PostMessage, 0x112, 0xF060,,, ahk_id %hnp%
 ExitApp
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2008, 1:27 pm 
netboom wrote:
Hi thanks for the code it was just what i'm looking for.. although i'm having trouble adapting it.

I want to switch between two windows every time i press "a" how would i change the script to release the focus and then reapply it?


Here is the (untested) code with most commented lines removed, and with
important re-arrangement of the code blocks/functions.

It may still not work, but the re-arrangement should increase your chance of success.
Code:
SetBatchLines -1
Process, Priority,, High
WinGet, myarray, List, ahk_class ATL:00420130,,gamers ; <---- gets list of window handles

OnExit, QuitScript

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

Return ;                                                 // End of Auto-Execute Section //
; ----------------------------------------------------------------------------------------
a::
IfWinActive, ahk_id %myarray1%
{
   current = %myarray2%
   goto, nextwin
}
IfWinActive, ahk_id %myarray2%
{
   current = %myarray1%
   goto, nextwin
}
return
; ---------------------------------------------------------------------------------------
nextwin:
  if ( lastCurrent = current)                 ; if current window was last processed, return
    return
  lastCurrent := current                      ; update last processed window
; MsgBox, %current%
;  hnp := WinExist(ahk_id %current%)               ; Obtain hwnd
  hnp := current                  ; <----- current already has window handle
  WinActivate, ahk_id %hnp%
  WinSetUnMovable( hnp )                          ; Make the window unmovable
  WinSet, AlwaysOnTop, On, ahk_id %hnp%           ; Flag it Always-On-Top
  return
; ----------------------------------------------------------------------------------------

; SHELLHOOK method to detect active window -----------------------------------------------
; Refer Tips N Tricks : http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323

ShellMessage( wParam,lParam ) {
  global hnp
  If ( wParam=4 && lParam<>hnp ) ; any window other than ahk_id %hnp%  is activated
       WinActivate, ahk_id %hnp%
  If ( wParam=2 && lParam=hnp ) ; if ahk_id %hnp%  window is closed/destroyed
       ExitApp
}
; -----------------------------
WinSetUnMovable( hwnd ) {
  hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
  nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
  DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-6,"Uint","0x400")
  DllCall("DrawMenuBar","Int",hWnd)
}   
; -----------------------------
QuitScript:
 ;PostMessage, 0x112, 0xF060,,, ahk_id %hnp%
 ExitApp
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2008, 1:41 pm 
helper wrote:
Code:
a::
IfWinActive, ahk_id %myarray1%
{
   current = %myarray2%
   goto, nextwin
}
IfWinActive, ahk_id %myarray2%
{
   current = %myarray1%
   goto, nextwin
}
return

On re-examining the code, if the main body of the previously posted code does what you want, this code will have to be re-written to suit your needs. Once one of the windows has been tagged as "always on top and in focus", your a:: hotkey will not work because the tagged window will always be active. ;)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2008, 2:40 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
SKAN,

Thanks for the great scripts. Is it possible to use the method described in "How to Hook on to Shell to receive its messages?" to execute code when a standard "Save as" window is created? I've been using the following code for testing:
Code:
#Persistent
#singleinstance force
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
     {
      WinGetClass, class, ahk_id %lParam%
      traytip, New Window, New "%class%"-class window created.
      if class = #32770
       msgbox, Fired on a "#32770"-class window!
     }
}


The traytip pops up for all new windows, but not for any "Save as" type windows. The kind of window I'm talking about is the kind that pops up when you click "File -> Save as" in for example Notepad. The ahk class is #32770, but since the ShellMessage doesn't fire nothing happens. Do you have any advise on this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 6:00 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Unfortunately, SHELLHOOK method will detect only top level windows.
The file save dialog is a child window of notepad.
So, notepad will be detected but not its child window.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 9:26 am 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
Thanks, that explains it. If anyone knows of something similar I could apply to child windows I much appreciate hearing about it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 11:49 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
You could try [tool] WinEventHook Messages posted by Serenity especially the popup blocker example


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2009, 9:21 pm 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Great works SKAN,

This thread is so long that I fear that the very important:
How to Hook on to Shell to receive its messages is
lost in the sauce.

But anyway, could you add an experiment or thread or PM me
on how to get instant onMessage notification of when a screensaver
activates. Hopefully it should work on W98-XP-Vista all windows
versions.

This thread says that your technique could do this but I can't see it anywhere. orbik said in:
http://www.autohotkey.com/forum/topic31038.html

Quote:
This sounds like a job for the shell hook method explained here http://www.autohotkey.com/forum/viewtop ... 323#123323
You'll get notified immediately when the screensaver starts instead of waiting inside a loop.


Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2009, 12:45 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Visioneer, Sorry for the late reply.

Quote:
How to get instant onMessage notification of when a screensaver activates.


Code:
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
     {
       WinGet, PN, ProcessName, ahk_id %lParam%
       If ( SubStr(PN,-3) = ".scr" )
          SetTimer, ScreenSaverHandler, -1
     }
}

ScreenSaverHandler:
 Send {Esc}                    ; Cancel ScreenSaver
 MsgBox, ScreenSaver was detected and cancelled immediately
Return


Quote:
Hopefully it should work on W98-XP-Vista all windows versions.


I hope.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2009, 5:04 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
RegisterShellHookWindow does not exist in Win98SE's user32.dll so the above doesn't work. Not sure about WinME, but I guess the info at MSDN is accurate that it has only been implemented beginning with Win2000.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 10th, 2009, 2:44 am 
Offline

Joined: January 28th, 2009, 10:53 pm
Posts: 6
Location: MN, USA
SKAN you are the greatest! this has helped out so much :-D

a couple notes i have: on experiment 3 (the volume OSD), where you have
    If ( wParam = 12 AND ( (lParam>>16) >= 8 OR (lParam>>16) <= 10) )
you should have
    If ( wParam = 12 AND ( (lParam>>16) >= 8 AND (lParam>>16) <= 10) )

otherwise the OSD triggers for every wParam=12 event

also, for anybody out there using a standard DELL multimedia keyboard (such as SK-8135 ), it might be helpful to note that the volume wheel uses (lParam>>16)=4106 for volume up and (lParam>>16)=4105 for volume down

_________________
-AJ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group