Page 1 of 1

Menu

Posted: Fri Aug 08, 2008 9:30 am
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

Posted: Fri Aug 08, 2008 10:22 am
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!

Posted: Sun Aug 10, 2008 9:58 am
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

Posted: Sun Aug 10, 2008 10:17 am
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

Thanks

Posted: Thu Aug 21, 2008 6:54 pm
by dannyboy99
Thanks very much for those who helped me here.

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

Thanks again

Danny

Posted: Thu Aug 21, 2008 11:38 pm
by blueznl