Hi,
I know that this is an old post, but I thought I would give the solution since I just came accross this problem myself. Hope this helps
.
Paste this code into the Load procedure for the form (create a status bar and name it âsbStatusBarâ):
' Set up the status bar.
' Make 4 panels.
Do While sbStatusBar.Panels.Count < 4
sbStatusBar.Panels.Add
Loop
sbStatusBar.Panels.Item(1).Alignment = sbrLeft
sbStatusBar.Panels.Item(2).Alignment = sbrCenter
sbStatusBar.Panels.Item(4).Alignment = sbrCenter
sbStatusBar.Panels.Item(1).Bevel = sbrInset
sbStatusBar.Panels.Item(2).Bevel = sbrNoBevel
sbStatusBar.Panels.Item(3).Bevel = sbrInset
sbStatusBar.Panels.Item(4).Bevel = sbrInset
sbStatusBar.Panels.Item(1).MinWidth = 5000
If MDIMain.ScaleWidth - sbStatusBar.Panels.Item(1).Width - sbStatusBar.Panels.Item(3).Width - sbStatusBar.Panels.Item(4).Width > 30 Then
sbStatusBar.Panels.Item(2).MinWidth = MDIMain.ScaleWidth - sbStatusBar.Panels.Item(1).Width - sbStatusBar.Panels.Item(3).Width - sbStatusBar.Panels.Item(4).Width
Else
sbStatusBar.Panels.Item(2).MinWidth = 30
End If
sbStatusBar.Panels.Item(1).Style = sbrText
sbStatusBar.Panels.Item(3).Style = sbrDate
sbStatusBar.Panels.Item(4).Style = sbrTime
' Hook all messages.
lOldMDIMainProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) ' Hook window sub-classing.
Paste this code into the Resize procedure for the form:
If MDIMain.ScaleWidth - sbStatusBar.Panels.Item(1).Width - sbStatusBar.Panels.Item(3).Width - sbStatusBar.Panels.Item(4).Width > 30 Then
sbStatusBar.Panels.Item(2).MinWidth = MDIMain.ScaleWidth - sbStatusBar.Panels.Item(1).Width - sbStatusBar.Panels.Item(3).Width - sbStatusBar.Panels.Item(4).Width
Else
sbStatusBar.Panels.Item(2).MinWidth = 30
End If
Paste this code into the Unload procedure for the form:
Call SetWindowLong(hWnd, GWL_WNDPROC, lOldMDIMainProcAddr) ' Unhook window sub-classing.
Paste this code in a code module:
Option Explicit
Public lOldMDIMainProcAddr As Long
Public Const MF_POPUP = &H10&
Public Const WM_MENUSELECT = &H11F
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
wParam As Any, lParam As Any) As Long
' Windows API Call for catching messages
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
' Windows API call for calling window procedures
Public Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim MenuItemStr As String * 128
Dim MenuHandle As Integer
Select Case iMsg
Case WM_MENUSELECT
' This occurs when the menu is being closed
If lParam = 0 Then Exit Function
' Get the low word from wParam. This contains the command ID or position of the menu entry.
MenuHandle = GetLowWord(wParam)
' If the highlighted menu is the top of a poup menu, pass menu item by position.
If (GetHighWord(wParam) And MF_POPUP) = MF_POPUP Then
' If the MF_POPUP bit was set in the high word, the menu item has a
' sub-menu attached to it. The position in MenuHandle will be useless.
MDIMain.sbStatusBar.Panels.Item(1).Text = ""
Else ' Otherwise, MenuHandle will contain a unique ID of the menu item.
Select Case MenuHandle
Case 2
MenuItemStr = "Exit the program..."
Case 3
MenuItemStr = "Print the selected item..."
' Use this code to see the ID of all menu items, then add a Case
' clause to set MenuItemStr for each instance.
Case Else
MenuItemStr = MenuHandle
End Select
MDIMain.sbStatusBar.Panels(1).Text = MenuItemStr
End If
WindowProc = CallWindowProc(lOldMDIMainProcAddr, hWnd, iMsg, wParam, lParam)
Case Else
' Pass all other messages.
WindowProc = CallWindowProc(lOldMDIMainProcAddr, hWnd, iMsg, wParam, lParam)
End Select
End Function
Public Function GetLowWord(Word As Long)
GetLowWord = CInt("&H" & Right$(Hex$(Word), 4))
End Function
Public Function GetHighWord(Word As Long)
GetHighWord = CInt("&H" & Left$(Hex$(Word), 4))
End Function