AutoHotkey Community

It is currently May 27th, 2012, 12:24 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: January 1st, 2009, 6:09 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
You can use it to modify toolbars from other applications. For example, the TaskBar has several ToolBars. These functions need the hwnd of the toolbar control to work.

Many thanks to Sean for his Taskbar/TrayIcon.ahk scripts; of which most of this is based on. :)

I will later extend this to include more toolbar messages documented in MSDN.

Note: This requires majkinetor's recently updated RemoteBuffer module in your library. :)

Save it as TB.ahk in your library for other scripts to use.

Code:
/*
############################################################################# Information

By Infogulch
See this url for more information: http://www.autohotkey.com/forum/viewtopic.php?t=39389

!!  Requires RemoteBuf.ahk in your library. Found here: http://www.autohotkey.com/forum/topic12251.html

Special thanks to Sean, majkinetor, and ahklerner

############################################################################# ToolBar Styles Reference

   TBSTYLE_BUTTON  :=  0x0
   TBSTYLE_SEP  :=  0x1
   TBSTYLE_EX_DRAWDDARROWS  :=  0x1
   TBSTYLE_CHECK  :=  0x2
   TBSTYLE_GROUP  :=  0x4
   TBSTYLE_DROPDOWN  :=  0x8
   TBSTYLE_EX_MIXEDBUTTONS  :=  0x8
   TBSTYLE_AUTOSIZE  :=  0x10
   TBSTYLE_EX_HIDECLIPPEDBUTTONS  :=  0x10
   TBSTYLE_NOPREFIX  :=  0x20
   TBSTYLE_EX_DOUBLEBUFFER  :=  0x80
   TBSTYLE_TOOLTIPS  :=  0x100
   TBSTYLE_WRAPABLE  :=  0x200
   TBSTYLE_ALTDRAG  :=  0x400
   TBSTYLE_FLAT  :=  0x800
   TBSTYLE_LIST  :=  0x1000
   TBSTYLE_CUSTOMERASE  :=  0x2000
   TBSTYLE_REGISTERDROP  :=  0x4000
   TBSTYLE_TRANSPARENT  :=  0x8000
   TBSTYLE_CHECKGROUP  :=  (TBSTYLE_GROUP Or TBSTYLE_CHECK)

############################################################################# ToolBar Functions
*/


TB_Hide(hwnd, idn, bHide = True) {
   SendMessage, 0x404, idn, bHide, , ahk_id %hwnd%   ; TB_HIDEBUTTON
   return ErrorLevel
}

TB_Delete(hwnd, idx) {
   SendMessage, 0x416, idx, 0, , ahk_id %hwnd%   ; TB_DELETEBUTTON
   return ErrorLevel
}

TB_Move(hwnd, idxOld, idxNew) {
   ; Shift + Swap
   SendMessage, 0x452, idxOld, idxNew, , ahk_id %hwnd%    ; TB_MOVEBUTTON
}

TB_GetHotItem(hwnd) {
   SendMessage, 0x447, 0, 0, , ahk_id %hwnd%   ; TB_GETHOTITEM
   Return ErrorLevel << 32 >> 32
}

TB_SetInsertMark(hwnd, idx, side=0) { ;idx is 0 based, so the first button would be 0. use -1 to remove; 0 on the left side, 1 on the right side
   idPar := DllCall("GetParent", uint, hwnd)
   RemoteBuf_Open(bufData, idPar, 8)
   RemoteBuf_Write(bufData, idx, 4)
   RemoteBuf_Write(bufData, side := !!side, 4, 4)
   SendMessage, 0x450, 0, RemoteBuf_Get(BufData, "adr"), , ahk_id %hwnd%
   return ErrorLevel, RemoteBuf_Close(BufData)
}

TB_SetInsertMarkColor(hwnd, rgb) { ; COLORREF: 0x00bbggrr
   SendMessage, (0x400 + 88), 0, (rgb & 0xff << 16) | (rgb >> 8 & 0xff << 8) | (rgb >> 16 & 0xff)
      , , ahk_id %hwnd% ;TB_SETINSERTMARKCOLOR  :=  (WM_USER + 88)
   return ErrorLevel
}

TB_SetStyle(hwnd, styles) {
   SendMessage, 0x438, 0, styles, , ahk_id %hwnd%
   return ErrorLevel
}

TB_GetStyle(hwnd) {
   SendMessage, 0x439, 0, , , ahk_id %hwnd% ;TB_GETSTYLE
   return ErrorLevel
}

TB_ChangeStyle(hwnd, add = 0, remove = 0) {
   return TB_SetStyle(hwnd, TB_GetStyle(hwnd) | add ~ remove)
}

TB_GetItemRect(hwnd, idx, ByRef RECT) {
   idPar := DllCall("GetParent", uint, hwnd)
   RemoteBuf_Open(bufData, idPar, 16)
   SendMessage, 0x41D, idx, RemoteBuf_Get(bufData, "adr"),, ahk_id %hwnd%
   err := errorlevel
   RemoteBuf_Read(bufData, RECT, 16, 0   )
   RemoteBuf_Close(BufData)
   return err
}

TB_ButtonCount(hwnd) {
   SendMessage, (0x400 + 24), , , , ahk_id %hwnd%
   return ErrorLevel
}

TB_AutoSize(hwnd) {
   SendMessage, (0x400 + 33), , , , ahk_id %hwnd% ;no return value
}

MSDN Toolbar Control

:D

_________________
Scripts - License


Last edited by infogulch on October 14th, 2009, 10:54 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2009, 3:43 pm 
Offline

Joined: July 26th, 2006, 8:50 pm
Posts: 68
Location: Wuppertal
Very nice.
But why the focus on only modifying the toolbar?

It would be cool if TB_GETBUTTONTEXT and TB_GETTOOLTIPS would be implemented (as well as other not modifying but info-getting messages)
(e.g. TB_GetTooltip would return the text of the associated ToolTip control)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 12th, 2009, 7:50 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
I am getting error on line 60 of the script in Win XP.
I put the RemoteBuf.ahk in various places ( subfolder \Lib\ and tried \lib\ and in the same folder) but always have the same error.

Error: Call to nonexistent function.

Specifically: RemoteBug_Open(bufData, idPar, 8)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 12th, 2009, 8:01 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
dv wrote:
Specifically: RemoteBug_Open(bufData, idPar, 8)
It's supposed to be RemoteBuf_Open(...

And read about libraries of functions

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 12th, 2009, 8:20 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
Thanks my typo. I am using your script exactly and it does have the "f".

I read the Libraries link quickly before. I had put the Lib folder in the subfolder of the .ahk script not the .exe path... ooops.
Now I do not get an error now when running the script.

Is this script also supposed to move taskbar buttons on the main bottom taskbar? I double-clicked the script and tried to drag and drop a taskbutton on the taskbar and move it. But no luck.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2009, 8:26 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
No, this is just a generalized set of helper functions that other scripts could use for moving taskbar buttons if they wanted.

Note that it's called: "[lib] Remote ToolBar Functions" (not "Taskbar") so it should work for any toolbar, not just the taskbar. Note that the Taskbar is just a special type of toolbar. (Damn ms nicknames.. :roll: )

Search the forum if you want an implementation.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2009, 8:37 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
I have searched but am not sure if there is one script that does this (with includes...) - I tried combining some snippets, but had no luck.

Thanks infogulch.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 21st, 2009, 3:33 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
Found the script I was looking for to move taskbar buttons.
http://www.autohotkey.com/forum/viewtop ... 441#297441
(see last post).
It works great on Vista.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 25th, 2009, 8:16 pm 
Offline

Joined: September 20th, 2006, 2:05 pm
Posts: 73
Here's how I used this:

Code:
~LButton::
    StartPos := GetControl()
return
   
~LButton Up::
   MouseGetPos, , , id, control
   WinGetClass, class, ahk_id %id%
   WinGet, pid, PID, ahk_id %id%
   ControlGet, hWnd, hwnd,, %control%, ahk_class %class%
  TB_Move(hwnd, StartPos, GetControl())
return

GetControl() {
   MouseGetPos, , , id, control
   WinGetClass, class, ahk_id %id%
   WinGet, pid, PID, ahk_id %id%
   ControlGet, hWnd, hwnd,, %control%, ahk_class %class%
   hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pid)
   pRB  :=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 8, "Uint", 0x1000, "Uint", 0x4)
   DllCall("GetCursorPos", "int64P", pt)
   DllCall("ScreenToClient", "Uint", hWnd, "int64P", pt)
   DllCall("WriteProcessMemory", "Uint", hProc, "Uint", pRB, "int64P", pt, "Uint", 8, "Uint", 0)
   idx  :=   DllCall("SendMessage", "Uint", hWnd, "Uint", 0x445, "Uint", 0, "Uint", pRB)   ; TB_HITTEST
   DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
   DllCall("CloseHandle"  , "Uint", hProc)
   Return   idx
}



thanks for the awesomeness infogulch.

Can taskbar styling eg. when using third party skinning apps be extended to standard toolbars?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Google Feedfetcher, SKAN and 5 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