December 07, 2019, 12:50:12 PM

Author Topic: Can you hide a menu?  (Read 314 times)

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 24
Can you hide a menu?
« on: November 21, 2019, 04:03:01 AM »
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?

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Can you hide a menu?
« Reply #1 on: November 21, 2019, 07:07:09 AM »
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

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 261
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Can you hide a menu?
« Reply #2 on: November 21, 2019, 10:25:19 AM »
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! 😂🤣😂

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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 24
Re: Can you hide a menu?
« Reply #3 on: November 21, 2019, 01:04:44 PM »
Thanks so much lads - I don't know much about WinAPI but I'll give it a try.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2607
Re: Can you hide a menu?
« Reply #4 on: November 21, 2019, 05:59:58 PM »
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

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 261
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Can you hide a menu?
« Reply #5 on: November 21, 2019, 06:10:35 PM »
Code: [Select]
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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 24
Re: Can you hide a menu?
« Reply #6 on: November 22, 2019, 01:12:23 AM »
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?

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 261
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Can you hide a menu?
« Reply #7 on: November 22, 2019, 06:11:07 AM »
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

Offline GfK

  • Jr. Member
  • **
  • Posts: 30
Re: Can you hide a menu?
« Reply #8 on: November 23, 2019, 04:02:20 PM »
I hid all the menus in Pizza Hut once.

All the fatties after an "all you can eat" went mental.
Intel I9-9900K 3.6-5.0GHz | GeForce RTX2070 8GB | 32GB RAM | 500GB NVMe M.2 SSD | 1TB HDD | Windows 10 x64.

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 24
Re: Can you hide a menu?
« Reply #9 on: November 26, 2019, 05:42:11 AM »
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

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 261
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Can you hide a menu?
« Reply #10 on: November 26, 2019, 08:18:20 AM »
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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 24
Re: Can you hide a menu?
« Reply #11 on: November 26, 2019, 05:13:00 PM »
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!