Can you hide a menu?

Started by Juiceter, November 21, 2019, 04:03:01

Previous topic - Next topic

Juiceter

A menu is a gadget, right? So I've tried hiding one using hidegadget(menu) to save on a bit of vertical screen space. but it won't hide like other gadgets. Can it be done?

Derron

Assume you talk about MaxGUI ...

MaxIDE refreshes the complete menu if it adds/removes entries.
Only Enable/DisableMenu can be used (together with an UpdateMenu-thing afterwards) without a complete refresh there.



bye
Ron

Dabz

#2
I'm at work so cannot write an example or have a play, but, you will need WinAPI, nab your windows Hwnd, then use the WinApi function SetMenu(Hwnd, Null)

That will remove the menu from your window, well, it should do!
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Juiceter

#3
Thanks so much lads - I don't know much about WinAPI but I'll give it a try.

Derron

Then do as I wrote: have a "CreateMyMenu()" function creating it according what is to show then. And when you want to hide a menu entry you remove the existing menu and create a new one (without that entry then).


bye
Ron

Dabz

#5

Import MaxGui.Drivers

Strict

Extern "win32"
Function SetMenu(hWnd,hMenu)
End Extern


Local window:TGadget
Global filemenu:TGadget
Global helpmenu:TGadget
Local button:TGadget 
Local hWnd:Int
Local hideFlag = 1

Const MENU_ITEM=101
Const MENU_EXIT=102
Const MENU_ABOUT=103

window=CreateWindow("Window",40,40,320,240)
BuildMenu(window)
button:TGadget = CreateButton ("Toggle Menu", 20,20,150,30, window, BUTTON_OK)


hWnd = QueryGadget(window,QUERY_HWND)


While True
WaitEvent
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_GADGETACTION
If EventSource() = button
hideFlag = -hideFlag
If hideFlag < 0
SetMenu(hWnd,Null)
Else
BuildMenu(window)
EndIf
EndIf
Case EVENT_MENUACTION
If hideFlag > 0
Select EventData()
Case MENU_EXIT
End
Case MENU_ABOUT
Notify "You know nowt about caravans, so don't~n~neven say you do!!!"
End Select
EndIf
End Select
Wend

Function BuildMenu(win:TGadget)
If filemenu <> Null
FreeMenu fileMenu
FreeMenu helpMenu
EndIf

filemenu=CreateMenu("File",0,WindowMenu(win))
CreateMenu"MenuItem",MENU_ITEM,filemenu
CreateMenu"",0,filemenu
CreateMenu"Exit",MENU_EXIT,filemenu

helpmenu=CreateMenu("Guff",0,WindowMenu(win))
CreateMenu "Say What?",MENU_ABOUT,helpmenu

UpdateWindowMenu win
End Function



Something like that!

You really need to have an explore of WinAPI, it does indeed have some really good stuff in there to tinker with*!

Dabz

*EDIT: That is, if your using Windows, though I'm sure Mac and Linux will have equivalents to play about with
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Juiceter

Thanks again guys - yep that api looks like it could be very useful. Are there any particularly good links you'd recommend with regards to studying it?

Dabz

https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-api-list

You'll find the SetMenu one here: https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-api-list

In some cases, to make something work, you may need to wrap some of it up in an external file then import it (e.g. Using C++ classes), which there is an article in the MaxIDE on how to do such a thing* (BlitzMax language reference->Advanced topics->Interfacing with C)

Happy playing

Dabz

*Note: you'll need MinGW installed to do that though
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Juiceter

#8
Heh heh - the buffet pizzas don't taste the same anyway so you were doing them a favour. Thanks one and all for your help lads. I'm sure this will be useful info to others too. I'm going to stay with blitzmax as I love it. C/C++ is boring in comparison  ;D

Dabz

Lol@Dave! :D

Quote
C/C++ is boring in comparison

Get awayyyy... I've had many an enjoyable coding session with the auld C/C++ setup, I like a bit of C# as well, and if your a Linux guy, take a look at Vala, that's pretty good for apps! :) ;)

Dabz

Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Juiceter

I find I can do a lot more, and more easily with Blitz. All those c/c++ memory leaks etc...
I even did my Uni project in Blitz Basic on the Amiga back in the day!