|
Post by alincon on Nov 21, 2018 12:18:19 GMT -5
I want to remove the file and edit items in a text window menu bar and replace them with my own. This code does not do that. r.m.
NoMainWin
Open "A Window" For text As #main
#main "!trapclose [quit]"
hMain=hWnd(#main)
hMainMenu=GetMenu(hMain)
hMainEdit=GetSubMenu(hMainMenu,1)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hWnd(#main)
hMainEdit=GetSubMenu(hMainMenu,0)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hWnd(#main)
Wait
[quit]
Close #main: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
|
|
|
Post by Alyce Watson on Nov 21, 2018 13:17:11 GMT -5
The handle you got is for the texteditor. Use GetParent to get the handle of the window.
|
|
|
Post by alincon on Nov 21, 2018 15:10:05 GMT -5
The original code (yours?) had a text editor. I wanted to use a text window. Also, I'm missing the DLL call to add new menu items.
r.m.
|
|
|
Post by Chris Iverson on Nov 21, 2018 15:33:22 GMT -5
Alyce knows that. The reason your code isn't working is because of an implementation detail, that she's told you how to resolve. Take the handle you get with hMain, pass it to the GetParent() Win32 API call, and use THAT handle to manage the window's menu.
Alyce's example code created a regular LB window(which you could then get a handle to directly), and put a texteditor on that window as a child window/control.
Your code uses a text window.
Thing is, there's no such thing as a text window.
LB fakes it by creating a secret normal window with a fully-sized child texteditor control. The handle you get from the OPEN command with a text window is NOT a handle to the secret normal window, it's a handle to the texteditor control on that window. That's why all the texteditor commands work directly.
THAT's why your code is failing. GetMenu() needs the top-level main window, which you don't have access to with #main. #main points to the texteditor control, not the secret main window.
To get the handle of the secret main window, you use the Win32 API to get the handle of the texteditor control's parent window. Once you have that, you have the secret main window's handle. Once you have that, you can use that to do all the menu manipulation you want.
EDIT: Here:
NoMainWin
Open "A Window" For text As #main
#main "!trapclose [quit]"
hText=hWnd(#main)
hMain = GetParent(hText)
hMainMenu=GetMenu(hMain)
hMainEdit=GetSubMenu(hMainMenu,1)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hMain
hMainEdit=GetSubMenu(hMainMenu,0)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hMain
Wait
[quit]
Close #main: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
Function GetParent(hWnd) CallDLL #user32, "GetParent",_ hWnd as ulong,_ GetParent as ulong End Function
|
|
|
Post by Alyce Watson on Nov 22, 2018 5:56:39 GMT -5
Chris Iverson is amazing, and on Thanksgiving day, I want to give thanks to him. He is an incredibly busy young man, but he always replies in detail and with great kindness.
To rm:
My thought is that it would be much easier to use a window with a texteditor. That's all a text window is.
|
|
|
Post by alincon on Nov 24, 2018 21:27:30 GMT -5
I am thankful that two giants of LB have taken time to help me on this case, as well as so many times in the past. Chris' code used a 1 and a 0 in the remove menu calls I had to use a 1 in both calls because I added this LB command: menu #main, "Item 1 Item 2" It appears that using a window with a text editor introduces a horizontal scrollbar, but not so in a text_fs window One more note: the _EM_SETREADONLY command seems not to work in LB text window; the user can change the text.
r.m.
|
|