Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 06:03:30 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Auto Resize Taskbar  (Read 8164 times)

blackcat

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 62
    • View Profile
    • Donate to Member
Auto Resize Taskbar
« on: November 03, 2008, 08:37:42 PM »
there's a time when we open too many programs they will start to filling up our taskbar then we are force to resize the taskbar just so those taskbar buttons become manageable again. Can you write a program to automate this when there are too many taskbar buttons in the taskbar and resize it back to the normal size when there are just few taskbar buttons after we have close some of them

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #1 on: November 06, 2008, 07:14:53 PM »
 :) Try TaskbarSize - it resizes the taskbar when it gets too crowded.

This is a very simple hack, I'll see if I can find a better way of sizing the taskbar.

Skrommel


;TaskbarSize.ahk
; Resizes the taskbar when it gets too crowded
;Skrommel @ 2008

#SingleInstance,Force
DetectHiddenWindows, On
SetWinDelay,0

WinMove,ahk_class Shell_TrayWnd,,100,0

buttonlimit=5

WinGetPos,tx,ty,tw,th,ahk_class Shell_TrayWnd

WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
idxTB:= GetTaskSwBar()
oldbuttons:=buttons
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
previous:=ErrorLevel

Loop
{
  Sleep,1000
  idxTB:= GetTaskSwBar()
  oldbuttons:=buttons
  SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
  buttons:=ErrorLevel
  If (oldbuttons=buttons)
    Continue
  If (buttons>previous+buttonlimit)
  {
    winid:=WinExist("A")
    WinActivate, ahk_class Shell_TrayWnd
    PostMessage, 0x112, 0xF000,,, ahk_class Shell_TrayWnd  ; SC_SIZE
    MouseGetPos,mx,my
    BlockInput,On
MouseClickDrag,L,1,1,1,-50,0
    BlockInput,Off
    MouseMove,% mx,% my,0
    WinActivate,ahk_id %winid%
  previous:=previous+buttonlimit
}
  If (buttons<previous-buttonlimit)
  {
    winid:=WinExist("A")
    WinActivate, ahk_class Shell_TrayWnd
    PostMessage, 0x112, 0xF000,,, ahk_class Shell_TrayWnd  ; SC_SIZE
    MouseGetPos,mx,my
    BlockInput,On
MouseClickDrag,L,1,1,1,50,0
    BlockInput,Off
    MouseMove,% mx,% my,0
    WinActivate,ahk_id %winid%
    previous:=previous-buttonlimit
  }
}
Return

;Stolen from Sean at http://www.autohotkey.com/forum/viewtopic.php?t=18652
TaskButtons(sExeName = "")
{
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
idxTB:= GetTaskSwBar()
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
Loop, %ErrorLevel%
{
SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
VarSetCapacity(btn,32,0)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
iBitmap := NumGet(btn, 0)
idn := NumGet(btn, 4)
Statyle := NumGet(btn, 8)
If dwData := NumGet(btn,12)
iString := NumGet(btn,16)
Else dwData := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "int64P", hWnd:=0, "Uint", NumGet(btn,12) ? 4:8, "Uint", 0)
If Not hWnd
Continue
WinGet, pid, PID,              ahk_id %hWnd%
WinGet, sProcess, ProcessName, ahk_id %hWnd%
WinGetClass, sClass,           ahk_id %hWnd%
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
, DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
, DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
, sTaskButtons .= "idx: " . A_Index-1 . " | idn: " . idn . " | pid: " . pid . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
Return sTaskButtons
}

HideButton(idn, bHide = True)
{
idxTB := GetTaskSwBar()
SendMessage, 0x404, idn, bHide, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_HIDEBUTTON
}

DeleteButton(idx)
{
idxTB := GetTaskSwBar()
SendMessage, 0x416, idx, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_DELETEBUTTON
}

MoveButton(idxOld, idxNew)
{
idxTB := GetTaskSwBar()
SendMessage, 0x452, idxOld, idxNew, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd    ; TB_MOVEBUTTON
}

GetTaskSwBar()
{
ControlGet, hParent, hWnd,, MSTaskSwWClass1 , ahk_class Shell_TrayWnd
ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
Loop
{
ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
If  Not hWnd
Break
Else If hWnd = %hChild%
{
idxTB := A_Index
Break
}
}
Return idxTB
}
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

blackcat

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 62
    • View Profile
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #2 on: November 13, 2008, 07:06:44 AM »
nice but it takes over my mouse pointer from me everytime it resize/shrink the taskbar  ;D

Genomi

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #3 on: September 04, 2009, 11:38:41 AM »
Hi, I wanted this too but Skrommel's script seemed to miss the taskbar when resizing, so I've edited it a bit to work for me. It seems to work pretty seamless, sorta like it's built into Windows. :) Also I made sure it works for the two (3 if you have XP MCE) default Windows XP themes, but it should work for other similar ones I hope. I haven't tried it in Vista or 7, so no idea if it works there. I guess post to let us know if you tried it and whether it worked.

Here's some things I added:

- it makes sure you aren't pressing the mouse button or keyboard modifiers (ctrl, alt, etc) before it resizes.
- I tried to make sure the mouse doesn't get stolen and doesn't travel off.

Warning: it only works when your taskbar is at the bottom of the screen!

(ahk file is attached, I don't know how to do the code window thing like Skrommel did up there)

Ampa

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 592
  • I am cute ;)
    • View Profile
    • MonkeyDash - 2 Player strategy boardgame
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #4 on: September 04, 2009, 02:35:08 PM »
Genomi: Don't think this is doing anything on my system! I launch numerous applications that add their buttons to the taskbar but it never resizes.

Not using a standard windows theme (have Luna Royal visual style at the moment).

I haven't tried Skrommel's version.

My taskbar is locked - is that an issue?

I run dual monitors.

Any thoughts?

Genomi

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #5 on: September 04, 2009, 02:40:09 PM »
Yep, locked taskbar will prevent it from being resizable, I completely forgot about that. I don't know how well it works on dual monitors, let us know how it goes!

Ampa

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 592
  • I am cute ;)
    • View Profile
    • MonkeyDash - 2 Player strategy boardgame
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #6 on: September 04, 2009, 03:27:17 PM »
Unlocked my taskbar - makes no difference :(

Genomi

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Auto Resize Taskbar
« Reply #7 on: September 04, 2009, 07:39:33 PM »
Hmm wait, I forgot to mention it takes 14 or 15 windows before it resizes bigger. It'll resize smaller once you go back down to about 10. Also, different screen resolutions might need different amount of windows before resizing, so I could add a line up top or something to adjust how many windows.

If it wasn't just the not enough windows were up thing:

Hmm try putting a sleep,1000 or something after the mousemove events to see exactly where the mouse goes to before it drags, and maybe you can adjust it from there to work for you. I guess a testing function could be made to do it all in slow motion so you can see what it does. I'll go ahead and do something like that if you're still having trouble after this. What OS are you on? Luna Royal should work fine, as the "Media Center Style" theme looks like it's the same thing and works for me. Sooo I'm guessing it's either you're not on XP and taskbar has a different class, or possibly the multi monitor thing - maybe try it on the different monitors.