LB Booster
Programming >> Liberty BASIC language >> Another flaky idea?
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1474148110

Another flaky idea?
Post by Alincon on Sep 17th, 2016, 9:35pm

Alyce wrote the following code to remove file and edit menus from a text window.
I am only responsible for the menu statement that turns the menu bar into column headings for a report that are always visible, regardless of scrolling.

Is this useful to anyone else?

r.m.

Code:
 menu #rpt, "      Category                             Cost               Date                          Description                                                         Period                           Remarks"     , "", [x]   
    Open "Diary Report by " + seq$ for text_fs as #rpt   
    
    hMain=hWnd(#rpt)
    hMainMenu=GetMenu(hMain)
    hMainEdit=GetSubMenu(hMainMenu,1)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#rpt)
    hMainEdit=GetSubMenu(hMainMenu,1)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#rpt)    
    return

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As ulong, r As boolean
    End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As ulong, nPos As long,_
    GetSubMenu As ulong
    End Function
    
   Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As ulong,_
    GetMenu As ulong
    End Function

    Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As ulong,_
    hSubMenu As ulong, _MF_BYCOMMAND As ulong,_
    RemoveMenu As boolean
    End Function 

 

Re: Another flaky idea?
Post by CryptoMan on Sep 17th, 2016, 10:08pm

But, File Edit is still appearing at the right end after Remarks.
Re: Another flaky idea?
Post by Alincon on Sep 17th, 2016, 11:38pm

I don't know what you are doing, but I just ran my program again, and File and Edit do NOT appear anywhere on my menu bar.

r.m.
Re: Another flaky idea?
Post by Jack Kelly on Sep 18th, 2016, 08:02am

I think the idea is ingenious and has many ways to be useful. I've cleaned up the code example a bit for (hopefully) easier testing.

Code:
NoMainWin
WindowWidth=800 : WindowHeight=600
menu #rpt, "Category                  Cost                  Date_
                  Description                  Period                  Remarks"
Open "Menu Report Headings " for text as #rpt   
#rpt "!TrapClose [quit]"
hMain=hWnd(#rpt)
hMainMenu=GetMenu(hMain)
hMainEdit=GetSubMenu(hMainMenu,1)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hWnd(#rpt)
hMainEdit=GetSubMenu(hMainMenu,1)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hWnd(#rpt)    
Wait

[quit]
close #rpt
end

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As ulong, r As boolean
End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As ulong, nPos As long,_
    GetSubMenu As ulong
End Function
    
Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As ulong,_
    GetMenu As ulong
End Function

Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As ulong,_
    hSubMenu As ulong, _MF_BYCOMMAND As ulong,_
    RemoveMenu As boolean
End Function
 

Re: Another flaky idea?
Post by Richard Russell on Sep 18th, 2016, 09:31am

on Sep 17th, 2016, 9:35pm, Alincon wrote:
Alyce wrote the following code to remove file and edit menus from a text window

If you want to remove all the menus (and the menu bar itself) then the method I showed before is easy. But if you want to selectively remove menus and retain the menu bar you can use Alyce's code.

Richard.


Re: Another flaky idea?
Post by CryptoMan on Sep 19th, 2016, 1:15pm

@Jack Kelly: I don't think you can put _ continuation character within quoted strings. Strangely enough this works in LBB but it doesn't work in LB.

I must have tested your code with LB instead of LBB. In LB File Edit keeps coming on the right but in LBB it is not coming. I don't know the reason for this difference.

However, _ in the middle of unclosed quotes is quite unorthodox.