Menu

Just starting out? Need help? Post your questions and find answers here.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Menu

Post by dannyboy99 »

Being new to programming, I need soem help please.

I want to write a small data input program that has data menu on the first screen, but I need to include a top bar menu with a preference options.

Enumeration
#WINDOW_MAIN
#MENU_MAIN
#MENU_QUIT
#MENU_ABOUT
#TEXT_INPUT
#STRING_INPUT
#LIST_INPUT
#BUTTON_INTERACT
#BUTTON_CLOSE
EndEnumeration

Global Quit.b = #False
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

If OpenWindow(#WINDOW_MAIN, 0, 0, 300, 222, "Interaction", #FLAGS)
If CreateMenu(#MENU_MAIN, WindowID(#WINDOW_MAIN))
MenuTitle("File")
MenuItem(#MENU_QUIT, "Quit")
MenuTitle("Help")
MenuItem(#MENU_ABOUT, "About...")

If CreateGadgetList(WindowID(#WINDOW_MAIN))
TextGadget(#TEXT_INPUT, 10, 10, 280, 20, "Enter text here:")
StringGadget(#STRING_INPUT, 10, 30, 280, 20, "")
ListViewGadget(#LIST_INPUT, 10, 60, 280, 100)
ButtonGadget(#BUTTON_INTERACT, 10, 170, 120, 20, "Enter text")
ButtonGadget(#BUTTON_CLOSE, 190, 170, 100, 20, "Close window")
SetActiveGadget(#STRING_INPUT)
Repeat

Event.l = WaitWindowEvent()
Select Event

Case #PB_Event_Menu
Select EventMenu()

Case #MENU_QUIT
Quit = #True

Case #MENU_ABOUT
MessageRequester("About", "This is your program description.")
EndSelect


I copied this from the book.

I was able to put in the preference menu, but try as I might I can not get it to open a new window, and have a button on the bottom that allows you to come out of that window when you have finsihed with the preferences option.

Any ideas pse
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

This show you how to manage the event handling of two windows:

Code: Select all

OpenWindow(0,0,0,400,300,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(0,5,5,120,23,"Open Dialog")

Repeat
	EventID = WaitWindowEvent()
	
	Select EventID
		Case #PB_Event_Gadget
		Select EventGadget()
			Case 0
			DisableWindow(0,1)
			OpenWindow(1,0,0,320,200,"Preferences",#PB_Window_SystemMenu | #PB_Window_ScreenCentered,WindowID(0))
			CreateGadgetList(WindowID(1))
			ButtonGadget(1,5,5,120,23,"Close Dialog")
			
			Case 1
			DisableWindow(0,0)
			CloseWindow(1)
		EndSelect
		
		Case #PB_Event_CloseWindow
		Select EventWindow()
			Case 0
			Quit = 1
			
			Case 1
			DisableWindow(0,0)
			CloseWindow(1)
		EndSelect
	EndSelect
Until Quit = 1
PS: Please use code tags!
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Arcee_uk
User
User
Posts: 29
Joined: Fri Jul 25, 2008 6:09 am
Location: England

Post by Arcee_uk »

BEcause I am new to PB can I just confirm I am understanding the code above.

You are basically saying:

Select EventGadget() : If xxx gadget is selected.

Case 0 : If on Window 0

Case 1 : If On Window 1

etc


Is that right? I could not follow this Case and Select commands as they are a strange way of working to me. Just want to make sure I have the right gist of the premise.

Thanks

Arcee
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

nope

Code: Select all

  Select EventWindow() 
    Case   #Win_Main 
      ; Main Window

    Case #Win_Sub1 
      ; First Subwindow

    Case #Win_Sub2 
      ; second Subwindow
etc...

this is similar to:

Code: Select all

WindowThatHasEvent = EventWindow() 

If WindowThatHasEvent = #Win_Main
      ; Main Window
EndIf

If WindowThatHasEvent = #Win_Sub1
      ; First Subwindow
EndIf

If WindowThatHasEvent = #Win_Sub2
      ; second Subwindow
EndIf
http://www.purebasic.fr/english/viewtop ... 031#175031
oh... and have a nice day.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Thanks

Post by dannyboy99 »

Thanks very much for those who helped me here.

I have finsihed the programs, which seem to working well.

Thanks again

Danny
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply