[WorkBook] = StartButton_ChangeText.xls [VBModule] = Module1 [Sub or Function] = Entire Module


Option Explicit


Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
x As Long
Y As Long
End Type

Private Declare Function GetWindowRect _
Lib "User32" ( _
ByVal hWnd As Long, _
lpRect As RECT) _
As Long

Private Declare Function SendMessage _
Lib "User32" _
Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long

Private Declare Function FindWindowEx _
Lib "User32" _
Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As Long

Private Declare Function FindWindow _
Lib "User32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Declare Function GetWindow _
Lib "User32" ( _
ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Declare Sub SetWindowPos _
Lib "User32" ( _
ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long)

Private Const WM_SETTEXT = &HC
Private Const SWP_SHOWWINDOW As Long = &H40

Private Const mStartBtnWidth = 99 'initial width
Private Const mStartBtnHeight = 32 'initial height
Private Const mTxtWidthMultiplyer = 9 '9 seems to work for my monito setup - change to suit yours

'// There are a number of Windows you need to take care of when doing this

Sub ChangeStartButtonText()
Dim bytTmp() As Byte
Dim strNewText As String
Dim lngTaskbarWndHnd As Long
Dim lngStartBtnWndHnd As Long
Dim lngReBarWindow32Handle As Long

'// Thes are the 3 windows you need Dims for
'// in order to resize it.
Dim udtTaskBarRect As RECT
Dim udtReBarWindow32Rect As RECT
Dim udtTrayNotifyWndRect As RECT

Dim NewReBarWindow32Width As Long
Dim NewStartbtnWidth As Long

Dim lRet As Long

Dim aArray() As Byte
Dim x As Integer
Dim ln As Integer

strNewText = "Warning from User"

ReDim bytTmp(Len(strNewText) + 1)
ln = Len(strNewText)

ReDim aArray(ln)
For x = 0 To ln - 1
aArray(x) = Asc(Mid(strNewText, x + 1, 1))
Next x

'// OK now Pad the last string with an EOS signal = 0
aArray(ln) = 0
bytTmp = aArray

'// lets get the Taskbar Window ,Class = "Shell_TrayWnd"
'// and the TaskBars Rectangle
lngTaskbarWndHnd = FindWindow("Shell_TrayWnd", "")
lRet = GetWindowRect(lngTaskbarWndHnd, udtTaskBarRect)

'// Get ReBarWindow32 Handle and Rectangle, Minimized programs go here and
'// includes (If you have enabled it, the QuickLaunch bar)
lngReBarWindow32Handle = FindWindowEx(lngTaskbarWndHnd, 0, "ReBarWindow32", "")
lRet = GetWindowRect(lngReBarWindow32Handle, udtReBarWindow32Rect)

'// Get TrayNotifyWnd Rectangle (Typically your Clock & Tray Icons go here)
lRet = GetWindowRect(FindWindowEx(lngTaskbarWndHnd, 0, "TrayNotifyWnd", ""), udtTrayNotifyWndRect)

'// Calculate Width size of the new Text in pixels
NewStartbtnWidth = Len(strNewText) * mTxtWidthMultiplyer + 64
If NewStartbtnWidth < mStartBtnWidth Then NewStartbtnWidth = mStartBtnWidth

NewReBarWindow32Width = (udtTaskBarRect.Right - udtTaskBarRect.Left) - _
(udtTrayNotifyWndRect.Right - udtTrayNotifyWndRect.Left) - NewStartbtnWidth

'// 5 stands for GW_CHILD or GW_MAX
lngStartBtnWndHnd = GetWindow(lngTaskbarWndHnd, 5)

'// Set new text of the [Start] button
SendMessage lngStartBtnWndHnd, WM_SETTEXT, 0, bytTmp(0)

'// Resize the ReBarWindow32 window
Call SetWindowPos(lngReBarWindow32Handle, _
0, _
NewStartbtnWidth + 5, _
0, _
NewReBarWindow32Width, _
udtTaskBarRect.Bottom - udtTaskBarRect.Top, _
SWP_SHOWWINDOW)

'// Resize the [Start] button
Call SetWindowPos(lngStartBtnWndHnd, _
0, _
0, _
0, _
NewStartbtnWidth, _
mStartBtnHeight, _
SWP_SHOWWINDOW)



End Sub