AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Attach a script to a custom toolbar on windows taskbar

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jonib



Joined: 09 May 2006
Posts: 66

PostPosted: Mon May 15, 2006 8:04 pm    Post subject: Attach a script to a custom toolbar on windows taskbar Reply with quote

Hi all

I started this script as a mod to Veovis Sysinfo script

This sample script puts time and date on a custom toolbar named "CustomToolbar" that can be moved on the taskbar or even separated.

It should be easy to change MainInit and MainUpdate to have whatever you want on the toolbar.

I hope this is useful?
Code:
;Test script to show how to attach a script to a custom toolbar on windows
;taskbar, that works even if separated from the taskbar.
;author jonib

;Here you define what folder the custom toolbar is attached to:
ToolbarName=CustomToolbar
;How often script is updated in ms.
UpdateTime=1000

;This initializes the toolbar code and runs custom MainInit.
gosub CreateWindow

return

;Here you define all controls you want to show on the toolbar.
MainInit:
   Gui -Caption ToolWindow
   FormatTime, CurrentTime,,Time
   Gui Add, Text,vTheTime,%CurrentTime%
   FormatTime, CurrentDate,,ShortDate
   Gui Add, Text,vTheDate,%CurrentDate%
   Gui Show, x-639
return

;Here all controls you want to show gets updated using the timer.
MainUpdate:
   FormatTime, CurrentTime,,Time
   GuiControl,,TheTime ,%CurrentTime%
   FormatTime, CurrentDate,,ShortDate
   GuiControl,,TheDate ,%CurrentDate%
return

;This gets the handle to the toolbar, creates the window and attaches it to the
;toolbar, and activates the timer.
CreateWindow:
   hw_tray:=FindToolbar(ToolbarName)
   gosub MainInit
  Process Exist
  WinGet GuiID, ID, ahk_pid %ErrorLevel%
   if Not DockIt(hw_tray,GuiID)
   {
      msgbox, Toolbar not found
      exitapp
   }
   Gui Show, x%tX% y%tY%
   SetTimer WindowUpdate, %UpdateTime%
return

;The timer runs this code that checks if the toolbar has changed and runs the
;MainUpdate routine
WindowUpdate:
   IfWinNotExist ,ahk_id %hw_tray%
   {
      gosub CreateWindow
   }
   gosub MainUpdate
return

;This just attaches the toolbar
DockIt(Parent,Child)
{
   return DllCall("SetParent",UInt,Child,UInt,Parent)
}

;This function checks what kind the toolbar is and gets the windows handle
FindToolbar(Name)
{   
   global tX tY
   loop
   {
      tX=5
      tY=5
      hwnd:=WinExist("ahk_class BaseBar",Name) ; Find Toolbar window
      if Not hwnd
      {
         tX=0
         tY=0
         WinExist("ahk_class Shell_TrayWnd") ; Find Systemtray
         WinGet, Controls ,ControlList ;Get list of all controls
         Loop, Parse, Controls, `n
         {
            ControlGetText, CurControl , %A_LoopField%
            if CurControl=%Name% ;Find the toolbar we want by comparing controls Text
               ControlGet, hwnd, Hwnd,,%A_LoopField% ;Get the handle for the toolbar
         }
      }
      if hwnd
         break
   }
   return hwnd
}
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Tue May 16, 2006 2:41 pm    Post subject: Reply with quote

Nice! Could you mod it, such that the GUI could be larger than the toolbar it is docked to, or just hangs out in one side? I'd like to cover the name of the toolbar, too.
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1239

PostPosted: Tue May 16, 2006 4:00 pm    Post subject: Reply with quote

@Laszlo: Did you know you can hide the name of the toolbar? If you right click on the taskbar and unlock it you can then right click on a toolbar's handle or name and choose a few extra options like hiding its title.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Tue May 16, 2006 4:53 pm    Post subject: Reply with quote

Thanks evl, and jonib! I did not know the title disabling trick. It is really handy. With that the Gui can cover completely the toolbar, what I wanted to achieve.
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1239

PostPosted: Tue May 16, 2006 8:44 pm    Post subject: Reply with quote

@ jonib:

Nice idea here (just had a chance to check it out properly). I played with the code a little and posted an example along with my other SetParent functions:
http://www.autohotkey.com/forum/viewtopic.php?p=60226
Back to top
View user's profile Send private message
jonib



Joined: 09 May 2006
Posts: 66

PostPosted: Tue May 16, 2006 9:41 pm    Post subject: Reply with quote

@ evl

Cool idea to connect to a diffrent gui, makes it easy to have a master window and one or more toolbars, I will have to steal that. Very Happy
Back to top
View user's profile Send private message
jonib



Joined: 09 May 2006
Posts: 66

PostPosted: Tue May 16, 2006 10:05 pm    Post subject: Reply with quote

I'm having a bit of a problem, I wanted to put a progress bar on my toolbar, and it's working fine, but if I separate the toolbar from the taskbar
or attach it back to the taskbar the progress bar is not updated anymore but the clock is.

I assume it's because I recreate the Gui everytime the toolbar is attached to or detached from the taskbar, but the clock is working fine.

if I use reload instead of CreateWindow when the toolbar has changed it works.

Anybody have any ideas why the progress bar is not updated when the window is moved?

This code has a progress bar with CPU meter from Sysinfo otherwise it's the same as my last code.
Code:
;Test script to show how to attach a script to a custom toolbar on windows
;taskbar, that works even if separated from the taskbar.
;author jonib

;Here you define what folder the custom toolbar is attached to:
ToolbarName=CustomToolbar
;How often script is updated in ms.
UpdateTime=1000

;This initializes the toolbar code and runs custom MainInit.
gosub CreateWindow

return

;Here you define all controls you want to show on the toolbar.
MainInit:
   Gui Margin, 0, 0
   Gui -Caption ToolWindow
   FormatTime, CurrentTime,,Time
   Gui Add, Text,vTheTime,%CurrentTime%
   FormatTime, CurrentDate,,ShortDate
   Gui Add, Text,vTheDate,%CurrentDate%
   Gui, Add, Progress,vMyProgress zx0 zy0 w80 h10 cBlue
   
   
   Gui Show, x-639
return

;Here all controls you want to show gets updated using the timer.
MainUpdate:
   FormatTime, CurrentTime,,Time
   GuiControl,,TheTime ,%CurrentTime%
   FormatTime, CurrentDate,,ShortDate
   GuiControl,,TheDate ,%CurrentDate%
   gosub ProcUpdate

return

ProcUpdate:
   ;-----Get Processor------
   IdleTime0 = %IdleTime%  ; Save previous values
   Tick0 = %Tick%
   DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
   IdleTime := *(&IdleTicks)
      Loop 7                  ; Ticks when Windows was idle
   IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
   Tick := A_TickCount     ; #Ticks all together
   load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
   GuiControl,, MyProgress, %load%
return

;This gets the handle to the toolbar, creates the window and attaches it to the
;toolbar, and activates the timer.
CreateWindow:
   hw_tray:=FindToolbar(ToolbarName)
   gosub MainInit
  Process Exist
  WinGet GuiID, ID, ahk_pid %ErrorLevel%
   if Not DockIt(hw_tray,GuiID)
   {
      msgbox, Toolbar not found
      exitapp
   }
   Gui Show, x%tX% y%tY%
   SetTimer WindowUpdate, %UpdateTime%
return

;The timer runs this code that checks if the toolbar has changed and runs the
;MainUpdate routine
WindowUpdate:
   IfWinNotExist ,ahk_id %hw_tray%
   {
      gosub CreateWindow
;      reload
   }
   gosub MainUpdate
return

;This just attaches the toolbar
DockIt(Parent,Child)
{
   return DllCall("SetParent",UInt,Child,UInt,Parent)
}

;This function checks what kind the toolbar is and gets the windows handle
FindToolbar(Name)
{   
   global tX tY
   loop
   {
      tX=5
      tY=5
      hwnd:=WinExist("ahk_class BaseBar",Name) ; Find Toolbar window
      if Not hwnd
      {
         tX=0
         tY=0
         WinExist("ahk_class Shell_TrayWnd") ; Find Systemtray
         WinGet, Controls ,ControlList ;Get list of all controls
         Loop, Parse, Controls, `n
         {
            ControlGetText, CurControl , %A_LoopField%
            if CurControl=%Name% ;Find the toolbar we want by comparing controls Text
               ControlGet, hwnd, Hwnd,,%A_LoopField% ;Get the handle for the toolbar
         }
      }
      if hwnd
         break
   }
   return hwnd
}
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Tue May 16, 2006 10:20 pm    Post subject: Reply with quote

This works fine, even if I resize the toolbar. Why and how do you want to separate the toolbar from the taskbar and attach it back?
Back to top
View user's profile Send private message
jonib



Joined: 09 May 2006
Posts: 66

PostPosted: Tue May 16, 2006 11:19 pm    Post subject: Reply with quote

Laszlo wrote:
This works fine, even if I resize the toolbar. Why and how do you want to separate the toolbar from the taskbar and attach it back?

Well the custom toolbar can be dragged and moved from the taskbar onto the desktop and then docked on the sides of the desktop.

I want to support this functionality, but there seems to be a problem recreating some controls with AHK.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group