Page 1 of 1
MenuItem Help in Statusbar
Posted: Sat Nov 01, 2003 3:40 am
by fsw
Tested under WinXP, hope it works fine also with other WinOSses...
Code: Select all
; Example Of A MenuItem Help in Statusbar
; (c) 2003 - By FSW
;
; Tested under WinXP
; do whatever you want with it
;
#Window = 0
#MenuItemFocus = 287
Enumeration
#Menu
#Menu1
#Menu2
#Menu3
#StatusBar
EndEnumeration
Procedure LoWord (var)
ProcedureReturn var & $FFFF
EndProcedure
Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
wParamLo = LoWord (wParam)
If Message = #MenuItemFocus
If wParamLo = #Menu1
StatusBarText(#StatusBar, 0, "Test 1: Help Text")
ElseIf wParamLo = #Menu2
StatusBarText(#StatusBar, 0, "Test 2: A Much Longer Help Text")
ElseIf wParamLo = #Menu3
StatusBarText(#StatusBar, 0, "Test 3: This Is The Longest Help Text. Believe Me!")
Else
StatusBarText(#StatusBar, 0, "")
EndIf
EndIf
ProcedureReturn Result
EndProcedure
If OpenWindow(#Window,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Menu Help Text In Statusbar")
CreateMenu(#Menu,WindowID())
MenuTitle("File")
MenuItem(#Menu1,"Test 1")
MenuItem(#Menu2,"Test 2")
MenuItem(#Menu3,"Test 3")
CreateStatusBar(#StatusBar, WindowID())
SetWindowCallback(@MyWindowCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Posted: Sat Nov 01, 2003 6:47 am
by TronDoc
works in w98fe
--jb
Nice
Posted: Sat Nov 01, 2003 4:43 pm
by Hi-Toro
Good stuff, same for your status bar events code -- thanks!
Posted: Thu Nov 06, 2003 3:48 pm
by ebs
fsw,
Your MenuItem Help code is really handy. Is there a way to know when the menu title ("File") is highlighted?
I don't mean when it is clicked on, but as soon as the mouse cursor passes over the title and it is highlighted.
I'm making a talking editor for blind/vision-impaired users, and it's important to be able to announce all menu
titles and items when they are highlighted.
Thanks,
Eric
Posted: Thu Nov 06, 2003 4:40 pm
by Fred
nice tip !
Posted: Thu Nov 06, 2003 10:08 pm
by fsw
@ebs
Sorry but this is not possible.
This is all I can do for you:
Code: Select all
; Example Of Another MenuItem Help
; (c) 2003 - By FSW
;
; do whatever you want with it
;
#Window = 1
#MenuFocus = 287
#Menu = 1
Enumeration 100
#Menu1
#Menu2
#Menu3
#Menu4
#Menu5
#Menu6
#StatusBar
EndEnumeration
Procedure LoWord (var)
ProcedureReturn var & $FFFF
EndProcedure
Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
wParamLo = LoWord (wParam)
lParamLo = LoWord (lParam)
If Message = #MenuFocus
If wParamLo = 0 ;File Title
StatusBarText(#StatusBar, 0, "File Title: Help Text")
ElseIf wParamLo = #Menu1
StatusBarText(#StatusBar, 0, "File 1: Help Text")
ElseIf wParamLo = #Menu2
StatusBarText(#StatusBar, 0, "File 2: A Much Longer Help Text")
ElseIf wParamLo = #Menu3
StatusBarText(#StatusBar, 0, "File 3: This Is The Longest Help Text. Believe Me!")
ElseIf wParamLo = 1 ;Edit Title
StatusBarText(#StatusBar, 0, "Edit Title: Help Text")
ElseIf wParamLo = #Menu4
StatusBarText(#StatusBar, 0, "Edit 1: Help Text")
ElseIf wParamLo = #Menu5
StatusBarText(#StatusBar, 0, "Edit 2: A Much Longer Help Text")
ElseIf wParamLo = #Menu6
StatusBarText(#StatusBar, 0, "Edit 3: This Is The Longest Help Text. Believe Me!")
EndIf
ElseIf Message = 32
If lParamLo = 5 ; menu
StatusBarText(#StatusBar, 0, "You are over the menu")
ElseIf lParamLo = 1 ; client area ; you need this to cancel the text
StatusBarText(#StatusBar, 0, "")
EndIf
EndIf
ProcedureReturn Result
EndProcedure
If OpenWindow(#Window,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Menu Help Text In Statusbar")
CreateMenu(#Menu,WindowID())
MenuTitle("File")
MenuItem(#Menu1,"File 1")
MenuItem(#Menu2,"File 2")
MenuItem(#Menu3,"File 3")
MenuTitle("Edit")
MenuItem(#Menu4,"Edit 1")
MenuItem(#Menu5,"Edit 2")
MenuItem(#Menu6,"Edit 3")
CreateStatusBar(#StatusBar, WindowID())
SetWindowCallback(@MyWindowCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Now it's important that you enumerate the Items with numbers higher the amount of your menu titles.
Because:
1st MenuTitle = 0
2nd MenuTitle = 1
and so on.
If your MenuItem start with 0 it doesn't work out.
Posted: Fri Nov 07, 2003 5:22 pm
by ebs
fsw,
Actually, that does exactly what I need - THANKS! It doesn't tell the menu title if it is selected with the mouse, but it does work if the menu selection is done with the keyboard, which is how my users would do it.
Thanks again,
Eric
BTW: Your #MenuFocus constant is the same as the Windows API constant #WM_MENUSELECT.
Posted: Fri Nov 07, 2003 6:36 pm
by fsw
Posted: Tue Nov 11, 2003 11:54 am
by lazy
Why my pb tell me : "Invalide name: same as an external command"
for this line :" Procedure LoWord (var) "
i'm waiting for your answer!

Posted: Tue Nov 11, 2003 12:58 pm
by Rings
lazy wrote:Why my pb tell me : "Invalide name: same as an external command"
for this line :" Procedure LoWord (var) "
i'm waiting for your answer!

you have a userlib installed which has the same command.
Look into Purelibraries/Userlibraries .
Re: MenuItem Help in Statusbar
Posted: Mon Aug 01, 2016 7:30 pm
by Al_the_dutch
This is what I dit with it with thanx to FSW and FangBeast
Code: Select all
; Example Of Another MenuItem Help
; (c) 2003 - By FSW ; http://forums.purebasic.com/english/viewtopic.php?p=39116
;
; do whatever you want with it
; 20160801 adapted by Al_the_dutch; a.o. the use of FangBeast's GetStatusBarText to save&restore the text
; and being able to have the helpitems in the same location as the menuitems itself.
; do whatever you want with it
EnableExplicit
#Window = 4900
#MenuFocus = 287
#Menu = 4900
#MenuOffset = 4900
#MenuTitles = 100
Enumeration #MenuOffset ; 4900
#Menu1
#Menu2
#Menu3
#Menu4
#Menu5
#Menu6
#StatusBar
EndEnumeration
#MenuLast = #Menu6 ; set it to the last #Menu
Global Dim MenuHelp.s(#MenuLast - #MenuOffset + #MenuTitles) ; The first 100 are for the MenuTitle's
;==========================================================================================================================
; Get the text from a specified statusbar and field in that statusbar
; From Fangbeast in http://www.forums.purebasic.com/english/viewtopic.php?f=13&t=45850
;==========================================================================================================================
Procedure.s GetStatusBarText(StatusbarNumber, FieldNumber)
Protected StringBufferLength.l, StringBuffer.s
StringBufferLength = SendMessage_(StatusBarID(StatusbarNumber), #SB_GETTEXTLENGTH, FieldNumber, 0)
If StringBufferLength
StringBuffer = Space(StringBufferLength)
SendMessage_(StatusBarID(StatusbarNumber), #SB_GETTEXT, FieldNumber, @StringBuffer)
If StringBuffer
ProcedureReturn PeekS(@StringBuffer)
Else ; Return an empty string as nothing was retrieved despite the buffer length being initialised
ProcedureReturn ""
EndIf
Else
ProcedureReturn "There are no characters to be retrieved"
EndIf
EndProcedure ; GetStatusBarText
;==========================================================================================================================
; END Fangbeast
;==========================================================================================================================
Procedure LoWord (var)
ProcedureReturn var & $FFFF
EndProcedure ; LoWord
Procedure MyWindowCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Static OldText$, bGotItAlready.b = #False
Protected wParamLo.w, lParamLo.w
If Not bGotItAlready
OldText$ = GetStatusBarText(#StatusBar, 0)
bGotItAlready = #True
EndIf
wParamLo = LoWord(wParam)
lParamLo = LoWord(lParam)
If Message = #MenuFocus And wParamLo <= #MenuTitles
StatusBarText(#StatusBar, 0, MenuHelp(wParamLo))
ElseIf Message = #MenuFocus
StatusBarText(#StatusBar, 0, MenuHelp(wParamLo - #MenuOffset + #MenuTitles))
ElseIf Message = 32
If lParamLo = 5 ; menu
StatusBarText(#StatusBar, 0, "Choose the menu item to get details")
ElseIf lParamLo = 1 ; client area ; you need this to cancel the text
StatusBarText(#StatusBar, 0, OldText$)
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure ; MyWindowCallback
Procedure MenuItemHelp(Item.l, Txt$)
If Item <= #MenuTitles
MenuHelp(Item) = Txt$
Else
MenuHelp(Item - #MenuOffset + #MenuTitles) = Txt$
EndIf
EndProcedure ; MenuItemHelp
;Main
If OpenWindow(#Window,0,0,320,240,"Menu Help Text In Statusbar", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateMenu(#Menu,WindowID(#Window))
MenuTitle("File")
MenuItemHelp(0, "File Title: Help Text")
MenuItem(#Menu1,"File 1")
MenuItemHelp(#Menu1, "File 1: Help Text")
MenuItem(#Menu2,"File 2")
MenuItemHelp(#Menu2, "File 2: A Much Longer Help Text")
MenuItem(#Menu3,"File 3")
MenuItemHelp(#Menu3, "File 3: This Is The Longest Help Text. Believe Me!")
MenuTitle("Edit")
MenuItemHelp(1, "Edit Title: Help Text")
MenuItem(#Menu4,"Edit 1")
MenuItemHelp(#Menu4, "Edit 1: Help Text")
MenuItem(#Menu5,"Edit 2")
MenuItemHelp(#Menu5, "Edit 2: A Much Longer Help Text")
MenuItem(#Menu6,"Edit 3")
MenuItemHelp(#Menu6, "Edit 3: This Is The Longest Help Text. Believe Me!")
CreateStatusBar(#StatusBar, WindowID(#Window))
AddStatusBarField(#PB_Ignore) ; automatically resize this field ;20160801 added
StatusBarText(#StatusBar, 0, "The current statusbar text") ;20160801 added
SetWindowCallback(@MyWindowCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End ; EndItAll
Re: MenuItem Help in Statusbar
Posted: Tue Aug 02, 2016 10:16 am
by Al_the_dutch
A MenuBar() made it crash and some adjustments. Here is the new code.
Code: Select all
; Example Of Another MenuItem Help
; (c) 2003 - By FSW ; http://forums.purebasic.com/english/viewtopic.php?p=39116
;
; do whatever you want with it
; 20160801 adapted by Al_the_dutch; a.o. the use of FangBeast's GetStatusBarText to save&restore the text
; and being able to have the helpitems in the same location as the menuitems itself.
; do whatever you want with it
EnableExplicit
#Window = 4900
#MenuFocus = 287
#Menu = 4900
#MenuOffset = 4900
#MenuTitles = 100
Enumeration #MenuOffset ; 4900
#Menu1
#Menu2
#Menu3
#Menu4
#Menu5
#Menu6
#StatusBar
EndEnumeration
#MenuLast = #Menu6 ; set it to the last #Menu
Global Dim MenuHelp.s(#MenuLast - #MenuOffset + #MenuTitles) ; The first 100 are for the MenuTitle's
;==========================================================================================================================
; Get the text from a specified statusbar and field in that statusbar
; From Fangbeast in http://www.forums.purebasic.com/english/viewtopic.php?f=13&t=45850
;==========================================================================================================================
Procedure.s GetStatusBarText(StatusbarNumber, FieldNumber)
Protected StringBufferLength.l, StringBuffer.s
StringBufferLength = SendMessage_(StatusBarID(StatusbarNumber), #SB_GETTEXTLENGTH, FieldNumber, 0)
If StringBufferLength
StringBuffer = Space(StringBufferLength)
SendMessage_(StatusBarID(StatusbarNumber), #SB_GETTEXT, FieldNumber, @StringBuffer)
If StringBuffer
ProcedureReturn PeekS(@StringBuffer)
Else ; Return an empty string as nothing was retrieved despite the buffer length being initialised
ProcedureReturn ""
EndIf
Else
ProcedureReturn "There are no characters to be retrieved"
EndIf
EndProcedure ; GetStatusBarText
;==========================================================================================================================
; END Fangbeast
;==========================================================================================================================
Procedure LoWord (var)
ProcedureReturn var & $FFFF
EndProcedure ; LoWord
Procedure MyWindowCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Static OldText$, bGotItAlready.b = #False
Protected wParamLo.w, lParamLo.w
If Not bGotItAlready
OldText$ = GetStatusBarText(#StatusBar, 0)
bGotItAlready = #True
EndIf
wParamLo = LoWord(wParam)
lParamLo = LoWord(lParam)
If wParamLo < 0 Or wParamLo - #MenuOffset + #MenuTitles > ArraySize(MenuHelp()) ; 20160802 MenuBar ed
ProcedureReturn #PB_ProcessPureBasicEvents
EndIf
If Message = #MenuFocus And wParamLo <= #MenuTitles
StatusBarText(#StatusBar, 0, MenuHelp(wParamLo),#PB_StatusBar_Center)
ElseIf Message = #MenuFocus
StatusBarText(#StatusBar, 0, MenuHelp(wParamLo - #MenuOffset + #MenuTitles),#PB_StatusBar_Center)
ElseIf Message = 32
If lParamLo = 5 ; menu
StatusBarText(#StatusBar, 0, "Choose the menu item to get details",#PB_StatusBar_Center)
ElseIf lParamLo = 1 ; client area ; you need this to cancel the text
StatusBarText(#StatusBar, 0, OldText$)
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure ; MyWindowCallback
Procedure MenuItemHelp(Item.l, Txt$)
If Item <= #MenuTitles
MenuHelp(Item) = Txt$
Else
MenuHelp(Item - #MenuOffset + #MenuTitles) = Txt$
EndIf
EndProcedure ; MenuItemHelp
;Main
If OpenWindow(#Window,0,0,320,240,"Menu Help Text In Statusbar", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateMenu(#Menu,WindowID(#Window))
MenuTitle("File")
MenuItemHelp(0, "File Title: Help Text")
MenuItem(#Menu1,"File 1")
MenuItemHelp(#Menu1, "File 1: Help Text")
MenuBar()
MenuItem(#Menu2,"File 2")
MenuItemHelp(#Menu2, "File 2: A Much Longer Help Text")
MenuItem(#Menu3,"File 3")
MenuItemHelp(#Menu3, "File 3: This Is The Longest Help Text. Believe Me!")
MenuTitle("Edit")
MenuItemHelp(1, "Edit Title: Help Text")
MenuItem(#Menu4,"Edit 1")
MenuItemHelp(#Menu4, "Edit 1: Help Text")
MenuItem(#Menu5,"Edit 2")
MenuItemHelp(#Menu5, "Edit 2: A Much Longer Help Text")
MenuItem(#Menu6,"Edit 3")
MenuItemHelp(#Menu6, "Edit 3: This Is The Longest Help Text. Believe Me!")
CreateStatusBar(#StatusBar, WindowID(#Window))
AddStatusBarField(#PB_Ignore) ; automatically resize this field ;20160801 added
StatusBarText(#StatusBar, 0, "The current statusbar text",#PB_StatusBar_Center) ;20160801 added
SetWindowCallback(@MyWindowCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End ; EndItAll
Re: MenuItem Help in Statusbar
Posted: Tue Aug 02, 2016 7:02 pm
by fsw
So the code from 2003 is still usable
Glad that I wasn't totally useless...
Thanks for keeping this code alive
