Author |
Topic: Shortcut keys? (Read 763 times) |
|
Pablo
New Member
member is offline


Posts: 3
|
 |
Re: Shortcut keys?
« Reply #2 on: Dec 21st, 2016, 11:38pm » |
|
Yes. But I want to right align the "F1" , "Ctrl+S" etc, like in the File menu in http://www.computerhope.com/shortcut.htm
Thanks.
- Pablo
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Shortcut keys?
« Reply #3 on: Dec 22nd, 2016, 08:57am » |
|
on Dec 21st, 2016, 11:38pm, Pablo wrote:| I want to right align the "F1" , "Ctrl+S" etc |
|
It's an annoying feature of Liberty BASIC (which LBB copies) that the text of a menu item must be supplied as a 'constant string', not as a variable. This doesn't work:
Non-working Code: menu$ = "Help Topics"+chr$(9)+"F1"
menu #w, "Help", menu$, [help]
open "Non-working test" for window as #w
wait What you get as the text of the menu item is 'menu$'!
As a result of this limitation you cannot insert the 'tab' character chr$(9) that is required to right-justify the F1. To allow that LBB would have to be modified either to accept a string variable as the menu text, or to adopt some 'escape convention' to represent a tab character, perhaps \t like C does.
In the absence of such a modification I think you are forced to use the Windows API to modify the text of the menu item, which is messy:
Code: nomainwin
menu #w, "Help", "Help Topics F1", [help]
open "Menu shortcut" for window as #w
hw = hwnd(#w)
calldll #user32, "GetMenu", hw as ulong, hMenuBar as ulong
calldll #user32, "GetSubMenu", hMenuBar as ulong, 0 as long, hHelpMenu as ulong
struct mii, cbSize as ulong, fMask as ulong, fType as ulong, fState as ulong, _
wID as ulong, hSubMenu as ulong, hbmpChecked as ulong, hbmpUnchecked as ulong, _
dwItemData as ulong, dwTypeData as ptr, cch as ulong
mii.cbSize.struct = len(mii.struct)
mii.fMask.struct = _MIIM_TYPE
mii.fType.struct = _MFT_STRING
mii.dwTypeData.struct = "Help Topics" + chr$(9) + "F1"
calldll #user32, "SetMenuItemInfoA", hHelpMenu as ulong, 0 as long, 1 as long, _
mii as struct, ret as long
#w "trapclose [quit]"
timer 10, [testkey]
wait
[quit]
close #w
end
[testkey]
calldll #user32, "GetAsyncKeyState", _VK_F1 as long, pressed as short
if pressed < 0 then goto [help]
wait
[help]
notice "Help Topics selected"
wait Richard.
|
|
|
|
|