AutoHotkey Community

It is currently May 26th, 2012, 12:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: January 3rd, 2008, 9:12 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
To show you how to implement what I said above do the following
Replace:
Code:
ret := DllCall("ReadProcessMemory", "Uint", hProc
    , "Uint", pdata, "UintP", hwnd, "Uint", 4, "Uint", 0)

With:
Code:
WinGetClass, cl, ahk_id %win%
If ( cl = "Shell_TrayWnd" )
{
    DllCall("ReadProcessMemory", "Uint", hProc
        , "Uint", pdata, "UintP", hwnd, "Uint", 4, "Uint", 0)
}
Else
{
    hWnd := pdata
}


:arrow:

You much also have done the changes lexikos suggested, i.e.
Replace:
Code:
if (cl != "Shell_TrayWnd")

With:
Code:
if cl not in Shell_TrayWnd,UltraMonDeskTaskBar


Replace:
Code:
if (cl != "MSTaskSwWClass")

With:
Code:
if cl not in MSTaskSwWClass,TaskBand


Replace:
Code:
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd

With:
Code:
WinGet, pidTaskbar, PID, ahk_id %ctl%


:arrow:

Hopefully it will now work fine with UltraMon taskbars also


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2008, 10:10 am 
Offline

Joined: December 28th, 2007, 8:52 pm
Posts: 6
Location: holland / netherland
mm to bad.. doesn't work.. i think there's no way to do it :S:*(
but thanks any way!! :D

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2008, 7:50 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
jxerot wrote:
mm to bad.. doesn't work.. i think there's no way to do it :S:*(
but thanks any way!! :D

Why so negative?
This is the script I used that worked fine:
Code:
#NoEnv
#Persistent
#SingleInstance, Force
SendMode, Input
SetWorkingDir %A_ScriptDir%
Return

MButton::
{
    If ( ( GetTaskbarHandle(hWindow) != 0 ) And ( hWindow != 0 ) )
    {
        WinClose, ahk_id %hWindow%
    }
    Else
    {
        Click Middle Down
        KeyWait, MButton
        Click Middle Up
    }
    Return
}

GetTaskbarHandle( ByRef hWindow )
{
    hWindow = 0
    Return = 0
    CoordMode, Mouse, Screen
    MouseGetPos, MouseX, MouseY, idWindow, idClass, 2
    WinGetClass, cWindow, ahk_id %idWindow%
    If cWindow Not In Shell_TrayWnd,UltraMonDeskTaskBar
        Return, Return
    WinGetClass, cClass, ahk_id %idClass%
    If ( cClass != "ToolbarWindow32" )
        Return, Return
    hParent := DllCall( "GetParent", "UInt", idClass )
    WinGetClass, cParent, ahk_id %hParent%
    If cParent Not In MSTaskSwWClass,TaskBand
        Return, Return

    WinGet, pidTaskbar, PID, ahk_id %idClass%

    hProcess := DllCall( "OpenProcess", "UInt", (PROCESS_VM_OPERATION:=0x08)+(PROCESS_VM_READ:=0x10)+(PROCESS_VM_WRITE:=0x20), "UInt", 0, "UInt", pidTaskbar)
    pButton := DllCall( "VirtualAllocEx", "UInt", hProcess, "UInt", 0, "UInt", 20, "UInt", (MEM_COMMIT:=0x1000), "UInt", (PAGE_READWRITE:=0x4) )

    VarSetCapacity( Point, 8, 0 )
    NumPut( MouseX, Point, 0, "UInt" )
    NumPut( MouseY, Point, 4, "UInt" )

    DllCall( "ScreenToClient", "UInt", idClass, "UInt", &Point )

    DllCall( "WriteProcessMemory", "UInt", hProcess, "UInt", pButton+0, "UInt", &Point, "UInt", 8, "UInt", 0 )

    SendMessage, (TB_HITTEST:=0x445), 0, pButton,, ahk_id %idClass%
    nButton := ErrorLevel

    If nButton > 0x7FFFFFFF
        nButton := -(~nButton)-1

    If ( nButton > -1 )
    {
        SendMessage, (TB_GETBUTTON:=0x417), nButton, pButton,, ahk_id %idClass%

        VarSetCapacity(Button, 20)
        DllCall( "ReadProcessMemory", "UInt", hProcess, "UInt", pButton, "UInt", &Button, "UInt", 20, "UInt", 0 )

        If ( cWindow = "Shell_TrayWnd" )
        {
            DllCall( "ReadProcessMemory", "UInt", hProcess, "UInt", NumGet( Button, 12, "UInt" ), "UInt*", hWindow, "UInt", 4, "UInt", 0 )
        }
        Else
        {
            hWindow := NumGet( Button, 12, "UInt" )
        }
        Return := nButton+1
    }

    DllCall( "VirtualFreeEx", "UInt", hProcess, "UInt", pButton, "UInt", 0, "UInt", (MEM_RELEASE:=0x8000) )
    DllCall( "CloseHandle", "UInt", hProcess )

    Return, Return
}

If the above script doesnt work for you then please run this next script
And tell me what the message box says:
Code:
#NoEnv
#Persistent
#SingleInstance, Force
SendMode, Input
SetWorkingDir %A_ScriptDir%
Return

MButton::
{
    Return := GetTaskbarHandle(hWindow)
    MsgBox, %Return%
    Return
}

GetTaskbarHandle( ByRef hWindow )
{
    hWindow = 0
    Return = 0
    CoordMode, Mouse, Screen
    MouseGetPos, MouseX, MouseY, idWindow, idClass, 2
    WinGetClass, cWindow, ahk_id %idWindow%
    If cWindow Not In Shell_TrayWnd,UltraMonDeskTaskBar
        Return, "hWindow = |" . hWindow . "| cWindow = |" . cWindow . "|"
    WinGetClass, cClass, ahk_id %idClass%
    If ( cClass != "ToolbarWindow32" )
        Return, "hWindow = |" . hWindow . "| cWindow = |" . cWindow . "| cClass = |" . cClass . "|"
    hParent := DllCall( "GetParent", "UInt", idClass )
    WinGetClass, cParent, ahk_id %hParent%
    If cParent Not In MSTaskSwWClass,TaskBand
        Return, "hWindow = |" . hWindow . "| cWindow = |" . cWindow . "| cClass = |" . cClass . "| cParent = |" . cParent . "|"

    WinGet, pidTaskbar, PID, ahk_id %idClass%

    hProcess := DllCall( "OpenProcess", "UInt", (PROCESS_VM_OPERATION:=0x08)+(PROCESS_VM_READ:=0x10)+(PROCESS_VM_WRITE:=0x20), "UInt", 0, "UInt", pidTaskbar)
    pButton := DllCall( "VirtualAllocEx", "UInt", hProcess, "UInt", 0, "UInt", 20, "UInt", (MEM_COMMIT:=0x1000), "UInt", (PAGE_READWRITE:=0x4) )

    VarSetCapacity( Point, 8, 0 )
    NumPut( MouseX, Point, 0, "UInt" )
    NumPut( MouseY, Point, 4, "UInt" )

    DllCall( "ScreenToClient", "UInt", idClass, "UInt", &Point )

    DllCall( "WriteProcessMemory", "UInt", hProcess, "UInt", pButton+0, "UInt", &Point, "UInt", 8, "UInt", 0 )

    SendMessage, (TB_HITTEST:=0x445), 0, pButton,, ahk_id %idClass%
    nButton := ErrorLevel

    If nButton > 0x7FFFFFFF
        nButton := -(~nButton)-1

    If ( nButton > -1 )
    {
        SendMessage, (TB_GETBUTTON:=0x417), nButton, pButton,, ahk_id %idClass%

        VarSetCapacity(Button, 20)
        DllCall( "ReadProcessMemory", "UInt", hProcess, "UInt", pButton, "UInt", &Button, "UInt", 20, "UInt", 0 )

        If ( cWindow = "Shell_TrayWnd" )
        {
            DllCall( "ReadProcessMemory", "UInt", hProcess, "UInt", NumGet( Button, 12, "UInt" ), "UInt*", hWindow, "UInt", 4, "UInt", 0 )
        }
        Else
        {
            hWindow := NumGet( Button, 12, "UInt" )
        }
        Return := nButton+1
    }

    DllCall( "VirtualFreeEx", "UInt", hProcess, "UInt", pButton, "UInt", 0, "UInt", (MEM_RELEASE:=0x8000) )
    DllCall( "CloseHandle", "UInt", hProcess )

    Return, "hWindow = |" . hWindow . "| cWindow = |" . cWindow . "| cClass = |" . cClass . "| cParent = |" . cParent . "| nButton = |" . nButton . "|"
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2008, 2:13 pm 
Offline

Joined: December 28th, 2007, 8:52 pm
Posts: 6
Location: holland / netherland
wouw!!! THANKS!!! the first one works!! thanks thanks thanks!! realy
i'm realy happy whit this! thanks

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2008, 8:20 pm 
Offline

Joined: January 13th, 2008, 6:00 pm
Posts: 115
This is hugely useful! I made an adjustment to the first part to hide a specific window rather than close it:

Code:
mButton:: ; Close windows from taskbar except Google Calendar
          if GetMouseTaskButton(hwnd) && hwnd
               {
               WinGetTitle,  wintitle, ahk_id %hwnd%
               IfInString, wintitle, Google Calendar - Mozilla Firefox
               WinHide,  ahk_id %hwnd%
               else
              WinClose, ahk_id %hwnd%
              }
          else {
              Click M Down
              KeyWait, MButton
              Click M Up
          }
      return
            
         ; Gets the index+1 of the taskbar button which the mouse is hovering over.
         ; Returns an empty string if the mouse is not over the taskbar's task toolbar.
         ;
         ; Some code and inspiration from Sean's TaskButton.ahk
         GetMouseTaskButton(ByRef hwnd)
         {
             CoordMode, Mouse, Screen
             MouseGetPos, x, y, win, ctl, 2
             ; Check if hovering over taskbar.
             WinGetClass, cl, ahk_id %win%
             if (cl != "Shell_TrayWnd")
                 return
             ; Check if hovering over a Toolbar.
             WinGetClass, cl, ahk_id %ctl%
             if (cl != "ToolbarWindow32")
                 return
             ; Check if hovering over task-switching buttons (specific toolbar).
             hParent := DllCall("GetParent", "Uint", ctl)
             WinGetClass, cl, ahk_id %hParent%
             if (cl != "MSTaskSwWClass")
                 return
         
            
             WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
         
             hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
             pRB := DllCall("VirtualAllocEx", "Uint", hProc
                 , "Uint", 0, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
         
             VarSetCapacity(pt, 8, 0)
             NumPut(x, pt, 0, "int")
             NumPut(y, pt, 4, "int")
            
             ; Convert screen coords to toolbar-client-area coords.
             DllCall("ScreenToClient", "uint", ctl, "uint", &pt)
            
             ; Write POINT into explorer.exe.
             DllCall("WriteProcessMemory", "uint", hProc, "uint", pRB+0, "uint", &pt, "uint", 8, "uint", 0)
         
         ;     SendMessage, 0x447,,,, ahk_id %ctl%  ; TB_GETHOTITEM
             SendMessage, 0x445, 0, pRB,, ahk_id %ctl%  ; TB_HITTEST
             btn_index := ErrorLevel
             ; Convert btn_index to a signed int, since result may be -1 if no 'hot' item.
             if btn_index > 0x7FFFFFFF
                 btn_index := -(~btn_index) - 1
            
            
             if (btn_index > -1)
             {
                 ; Get button info.
                 SendMessage, 0x417, btn_index, pRB,, ahk_id %ctl%   ; TB_GETBUTTON
            
                 VarSetCapacity(btn, 20)
                 DllCall("ReadProcessMemory", "Uint", hProc
                     , "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
            
                 state := NumGet(btn, 8, "UChar")  ; fsState
                 pdata := NumGet(btn, 12, "UInt")  ; dwData
                
                 ret := DllCall("ReadProcessMemory", "Uint", hProc
                     , "Uint", pdata, "UintP", hwnd, "Uint", 4, "Uint", 0)
             } else
                 hwnd = 0
         
                
             DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
             DllCall("CloseHandle", "Uint", hProc)
         
         
             ; Negative values indicate seperator items. (abs(btn_index) is the index)
             return btn_index > -1 ? btn_index+1 : 0
         }


I'm so glad you all posted this. I'm happy I could make it work for me, even though I'm very confused by how it actually works. :mrgreen:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 1:29 pm 
Offline

Joined: December 28th, 2007, 8:52 pm
Posts: 6
Location: holland / netherland
I know it's a really old post..
But now I have windows vista ultimate 64x. + ultramon.
Do you guy's know an script that will work now??

Thank!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2008, 1:41 pm 
I've been using the version Mustang posted, but after installing QTTabBar I haven't been able to close Windows Explorer windows by middle clicking their taskbar buttons. Anyone have a clue how to fix this?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2008, 10:26 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
Larkku wrote:
I've been using the version Mustang posted, but after installing QTTabBar I haven't been able to close Windows Explorer windows by middle clicking their taskbar buttons. Anyone have a clue how to fix this?

Mustang wrote:
If the above script doesnt work for you then please run this next script
And tell me what the message box says:


P.S.
I installed QTTabBar especially to test it for you
And for me the script still works fine (Vista x86)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2008, 8:43 am 
Mustang wrote:
If the above script doesnt work for you then please run this next script
And tell me what the message box says:


hWindow = 2950684
cWindow = Shell_TrayWnd
cClass = ToolbarWindow32
cParent = MsTaskSwWClass
nButton = 7

I'm using XP Home x86.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2008, 7:14 am 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
Well from that it looks that it should be working fine

Do you have grouping of windows enabled?
If so disable it and try again
Also make sure you have rebooted since installing QTTabBar


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2008, 10:07 am 
Mustang wrote:
Well from that it looks that it should be working fine

That's what I thought, strange..

Quote:
Do you have grouping of windows enabled?

Nope.

Quote:
Also make sure you have rebooted since installing QTTabBar

Done that too.

Btw, when you tried QTTabBar, was it active - so you could actually see the tab(s)? I had a little trouble with that, and this problem only appeared after I got it working.

Sorry for the trouble...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2008, 12:07 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
Yes I got it working
To do this goto Organize > Layout > Menu Bar
Then right click on the menu bar and tick to options

Don't think I can help any more
Ran out of ideas


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 4:52 pm 
Offline

Joined: August 21st, 2006, 4:29 am
Posts: 30
Mustang wrote:
This is the script I used that worked fine:


Mustang, big thanks for this script - it was exactly what I was looking for! :D

jxerot, thanks for your persistence also ;)

p.s. If anyone has time to put some comments in the code to explain how it works, that would be super!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Windows 7
PostPosted: October 5th, 2009, 3:28 pm 
Offline

Joined: August 21st, 2006, 4:29 am
Posts: 30
Hi there,

Can anyone get mustangs script working in Windows 7?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 9th, 2009, 7:19 am 
Offline

Joined: June 14th, 2008, 7:47 pm
Posts: 56
Location: Sydney, Australia
Does not work. :(

I got Win7 64 ultimate.

If any one needs to test some ideas and don't have win7...Post it here and I'll test it.

Otherwise get Win7 is great! I just miss all the nice tricks we already manage for XP 32

Cheers,

_________________
Thanks, Yogui.
_____________________________


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Morpheus, RUBn, SKAN, sks, StepO, Yahoo [Bot] and 19 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