GUI Menus

BlitzPlus Forums/BlitzPlus Beginners Area/GUI Menus

Kirkkaf(Posted 2011) [#1]
Hi everyone,

For some reason the text for my menu isn't showing up anyone got any ideas here is a picture and the source.

[img]http://imageshack.us/f/843/errorck.png/[/img]


;MapEditor

;Varaibles
Global Version$ = "V.0.0.1"

;Initalize 
Global MapEditor = CreateWindow("MapEditor" + Version$, 0, 0, 1024, 600, 0, 15)
MainMenu()

;Main Loop
Repeat 
	WindowEvent()
Forever

;Functions
Function WindowEvent()
	If WaitEvent(100000) = $803 Then
		WindowClose()
	EndIf	
End Function

Function WindowClose()
	Local Status% = 1
	CloseProgram = CreateWindow("Close Program?", 512 - 150, 300 - 150, 300, 300, MapEditor, 0)
	CreateLabel("Are you sure you want to close the program?", 50, 25, 250, 25, CloseProgram)
	ButtonYes = CreateButton("Yes", 75, 75, 50, 50, CloseProgram)
	ButtonNo = CreateButton("No", 175, 75, 50, 50, CloseProgram)
	Repeat 
		If WaitEvent(100000) = $201 Or $2001 Then	
			ActivateWindow(CloseProgram)
			If EventSource() = ButtonYes Then
				End()
			ElseIf EventSource() = ButtonNo Then
				FreeGadget(CloseProgram)
				Status% = 0
			EndIf 
		EndIf
	Until Status% = 0
End Function

Function MainMenu()
	Menu = WindowMenu(MapEditor)
	CreateMenu("File", 0, Menu)
End Function 


Last edited 2011

Last edited 2011


Kirkkaf(Posted 2011) [#2]
Cant seem to get the picture to work.


Andy_A(Posted 2011) [#3]
It seems to me that MapEditor - is a window handle but is not Global, so MainMenu() never sees the window handle.


Kirkkaf(Posted 2011) [#4]
The handle is global as shown in the source though from the image the menu appears just without text


Andy_A(Posted 2011) [#5]
Yeah, I copy and pasted only some of the code, missing the Global declarations.

In WindowClose() function if you change the [style] from zero to one, you'll see the title bar and your text appears.


[edit]
To get the "File" on the menu bar to show you need to add this line to the MainMenu() function.

UpdateWindowMenu(MapEditor)

[/edit]

Last edited 2011

Last edited 2011


Kirkkaf(Posted 2011) [#6]
Thanks alot for your help Andy.


Gladclef - Ben B(Posted 2011) [#7]
Does it work now? Do you not still need to call
UpdateWindowMenu()
?


Kirkkaf(Posted 2011) [#8]
I have just started working on this again and added my CloseProgram function to my Exit menu event. When exit is chosen from the menu bar and the dialogue appears to confirm if you would like to end the program if you click no then try exit again it does not work until you try it the third time.

;MapEditor

;Varaibles
Global Version$ = "V.0.0.1"

;Initalize 
Global MapEditor = CreateWindow("MapEditor" + Version$, 0, 0, 1024, 600, 0, 13)
MainMenu()

;Main Loop
Repeat 
	UpdateWindowMenu(MapEditor)
	WindowEvent()
Forever

;Functions
Function WindowEvent()
	If WaitEvent(100000) = $803 Then
		WindowClose()
	ElseIf WaitEvent(100000) = $1001 Then
		If EventData() = 2 Then
			WindowClose()
		EndIf
	EndIf	
End Function

Function WindowClose()
	Local Status% = 1
	CloseProgram = CreateWindow("Close Program?", 512 - 150, 300 - 150, 300, 300, MapEditor, 0)
	CreateLabel("Are you sure you want to close the program?", 50, 25, 250, 25, CloseProgram)
	ButtonYes = CreateButton("Yes", 75, 75, 50, 50, CloseProgram)
	ButtonNo = CreateButton("No", 175, 75, 50, 50, CloseProgram)
	Repeat 
		If WaitEvent(100000) = $201 Or $2001 Then	
			ActivateWindow(CloseProgram)
			If EventSource() = ButtonYes Then
				End()
			ElseIf EventSource() = ButtonNo Then
				FreeGadget(CloseProgram)
				Status% = 0
			EndIf 
		EndIf
	Until Status% = 0
End Function

Function MainMenu()
	Menu = WindowMenu(MapEditor)
	File = CreateMenu("File", 0, Menu)
	CreateMenu("New", 1, File)
	CreateMenu("", 0, File)
	CreateMenu("Exit", 2, File)
End Function 


What seems to be causing this issue?