MenuItem Help in Statusbar

Share your advanced PureBasic knowledge/code with the community.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

MenuItem Help in Statusbar

Post 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 

I am to provide the public with beneficial shocks.
Alfred Hitshock
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

works in w98fe
--jb
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Nice

Post by Hi-Toro »

Good stuff, same for your status bar events code -- thanks!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
Fred
Administrator
Administrator
Posts: 18243
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

nice tip !
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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.

I am to provide the public with beneficial shocks.
Alfred Hitshock
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post 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.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

:D :D :D
lazy
New User
New User
Posts: 7
Joined: Tue Nov 04, 2003 4:23 pm

Post 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! :lol:
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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! :lol:
you have a userlib installed which has the same command.
Look into Purelibraries/Userlibraries .
SPAMINATOR NR.1
Al_the_dutch
User
User
Posts: 70
Joined: Mon Nov 11, 2013 11:07 am
Location: Portugal

Re: MenuItem Help in Statusbar

Post by Al_the_dutch »

This is what I dit with it with thanx to FSW and FangBeast :D

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
Al_the_dutch
User
User
Posts: 70
Joined: Mon Nov 11, 2013 11:07 am
Location: Portugal

Re: MenuItem Help in Statusbar

Post 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
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: MenuItem Help in Statusbar

Post by fsw »

So the code from 2003 is still usable :?:

Glad that I wasn't totally useless... :shock:

Thanks for keeping this code alive :mrgreen:

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply