Child Windows (MaxGui)

BlitzMax Forums/BlitzMax Programming/Child Windows (MaxGui)

HI all,

I've created a popup window within another window (MDI style) but i want it so focus is fixed on the new window and the user cant go back to the main window until closing the front window, i thought maybe flag WINDOW_CHILD may do it but no :(

n e ideas?

cant u just disable the other window and then when the child window is closed just enable it again.

some variation of this might work:

http://www.blitzbasic.com/Community/posts.php?topic=56501

Perfect Mr Shaver thanks :D

note that you should disable any menus in other windows because they will still respond.

am i right in thinking that bmax ide was made with maxgui? if so i wonder how they did it with the syncmod dialog?

you get the source to bmax ide with blitzmaxGUI so why not look for yourself.

i did?? wow...lol

as far as i make out its all done with disable gadget
Type tapp
	
	Field mwindow:tgadget
	Field pwindow:tgadget
	
	Field sbutton:Tgadget
	
	Method New()
	
		mwindow = CreateWindow("main window", 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop()))
		MaximizeWindow mwindow
		
		pwindow = CreateWindow("Popup", 100, 100, 200, 200, Null, 65)
		HideGadget pwindow
		
		sbutton = CreateButton("popup", 10, 10, 100, 20, mwindow)
		
	End Method
	
End Type

Global mapp:tapp = New tapp

While True

	WaitEvent
	
	Select EventID()
	
		Case event_windowclose
		
			Select EventSource()
				
				Case mapp.mwindow
					End
				
				Case mapp.pwindow
					EnableGadget mapp.mwindow
					HideGadget mapp.pwindow
					
			End Select
			
		Case event_gadgetaction
			
			If EventSource() = mapp.sbutton Then 
				DisableGadget(mapp.mwindow)
				ShowGadget(mapp.pwindow)
			EndIf
			
	End Select
	

Wend


OK....been playin with code from another post and i can make a second window appear thats always in front. however it requires me to click the menu option twice to get the menu to appear in the first place:


Type TNWorderWin

Field Window:TGadget = CreateWindow("new window",0,0,640,480,Null,WINDOW_TITLEBAR|WINDOW_STATUS|WINDOW_MENU)
Field RegWin:TGadget
Field FileMnu:TGadget = CreateMenu ("&File",0,WindowMenu(window))
Field HelpMnu:TGadget = CreateMenu ("&Help",0,WindowMenu(window))

Method New()
CreateMenu("&About",101,HelpMnu)
CreateMenu("&Register",102,FileMnu,KEY_R,MODIFIER_COMMAND)
CreateMenu("&Exit",103,FileMnu,KEY_E,MODIFIER_COMMAND)
AddHook EmitEventHook,eventhook,Self
UpdateWindowMenu Window
EndMethod

Function eventhook:Object(id:Int,data:Object,context:Object)
If TNWorderWin(context) Then TNWorderWin(context).OnEvent TEvent(data)
Return data
EndFunction

Method Delete()
RemoveHook EmitEventHook,eventhook
FreeGadget(window)
EndMethod

Method OnEvent(event:TEvent)
Select event.id
Case EVENT_WINDOWCLOSE
Select Event.Source
Case window
FreeGadget(window)
End
Case RegWin
FreeGadget (RegWin)
End Select

Case EVENT_GADGETACTION
Select Event.Source

EndSelect
Case EVENT_GADGETPAINT
Select Event.Source

EndSelect
Case EVENT_MENUACTION
Select EventData()
Case 103
End
Case 101
RegWin = CreateWindow("Register",0,0,320,240,Window,WINDOW_TITLEBAR)
ActivateGadget RegWin
EndSelect

EndSelect
EndMethod

EndType


Global App:TNWorderWin= New TNWorderWin

While True
WaitEvent()
Wend

SuperStrict


Const MENU_FILE_NEWMAP%				= 1
Const MENU_FILE_SAVEMAP%			= 2
Const MENU_FILE_LOADMAP%			= 3
Const MENU_FILE_EXIT%				= 4

Type TApp
	
	Field mainWindow:TGadget
	Field mainFileMenu:TGadget
	
	Field otherWindow:TGadget
	
	Method OnEvent(event:TEvent)
		
		Select event.id
		
			Case EVENT_WINDOWCLOSE
				If event.source = mainWindow Then End
				If event.source = otherWindow Then HideGadget otherWindow
				
			Case EVENT_MENUACTION
				Select event.data
					
					Case MENU_FILE_NEWMAP
						ShowGadget otherWindow
							
					Case MENU_FILE_EXIT
						End
						
				End Select
						    
		End Select
		
	End Method
		
	Function EventHook:Object(id%, data:Object, context:Object)
		
		Local event:TEvent = TEvent(data)
		Local app:TApp = TApp(context)
		
		app.OnEvent event
		
	End Function
	
	Method New()
		
		mainWindow = CreateWindow("Wisp Engine Editor", 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop()))
		MaximizeWindow(mainWindow)
		
		otherWindow = CreateWindow("Register",0,0,320,240,mainWindow ,65)
		
		mainFileMenu = CreateMenu("&File", 0, WindowMenu(mainWindow))
		CreateMenu("New &Map...", MENU_FILE_NEWMAP, mainFileMenu, KEY_M, MODIFIER_COMMAND)
		CreateMenu("", 0, mainFileMenu)
		CreateMenu("&Save Map", MENU_FILE_SAVEMAP, mainFileMenu, KEY_S, MODIFIER_COMMAND)
		CreateMenu("&Load Map...", MENU_FILE_LOADMAP, mainFileMenu, KEY_L, MODIFIER_COMMAND)
		CreateMenu("", 0, mainFileMenu)
		CreateMenu("&Exit", MENU_FILE_EXIT, mainFileMenu, KEY_X, MODIFIER_COMMAND)
		UpdateWindowMenu mainWindow
				
		AddHook EmitEventHook, EventHook, Self
		
	End Method
	
End Type

Global myApp:TApp = New TApp

While True

	WaitEvent()

Wend 


couldnt figure out what yo wanted at first but is this it. cant think way you version dont work.

EDIT better version IMO
SuperStrict


Const MENU_FILE_NEWMAP%				= 1
Const MENU_FILE_SAVEMAP%			= 2
Const MENU_FILE_LOADMAP%			= 3
Const MENU_FILE_EXIT%				= 4

Type TApp
	
	Field mainWindow:TGadget
	Field mainFileMenu:TGadget
	
	Field otherWindow:TGadget
	
	Method OnEvent(event:TEvent)
		
		Select event.id
		
			Case EVENT_WINDOWCLOSE
				If event.source = mainWindow Then End
				If event.source = otherWindow Then HideGadget otherWindow;EnableGadget mainWindow
				
			Case EVENT_MENUACTION
				Select event.data
					
					Case MENU_FILE_NEWMAP
						ShowGadget otherWindow
						DisableGadget mainWindow
							
					Case MENU_FILE_EXIT
						End
						
				End Select
						    
		End Select
		
	End Method
		
	Function EventHook:Object(id%, data:Object, context:Object)
		
		Local event:TEvent = TEvent(data)
		Local app:TApp = TApp(context)
		
		app.OnEvent event
		
	End Function
	
	Method New()
		
		mainWindow = CreateWindow("Wisp Engine Editor", 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop()))
		MaximizeWindow(mainWindow)
		
		otherWindow = CreateWindow("Register",0,0,320,240,mainWindow ,65)
		
		mainFileMenu = CreateMenu("&File", 0, WindowMenu(mainWindow))
		CreateMenu("New &Map...", MENU_FILE_NEWMAP, mainFileMenu, KEY_M, MODIFIER_COMMAND)
		CreateMenu("", 0, mainFileMenu)
		CreateMenu("&Save Map", MENU_FILE_SAVEMAP, mainFileMenu, KEY_S, MODIFIER_COMMAND)
		CreateMenu("&Load Map...", MENU_FILE_LOADMAP, mainFileMenu, KEY_L, MODIFIER_COMMAND)
		CreateMenu("", 0, mainFileMenu)
		CreateMenu("&Exit", MENU_FILE_EXIT, mainFileMenu, KEY_X, MODIFIER_COMMAND)
		UpdateWindowMenu mainWindow
				
		AddHook EmitEventHook, EventHook, Self
		
	End Method
	
End Type

Global myApp:TApp = New TApp

While True

	WaitEvent()

Wend 


yeah, thats alot better :) Thank Diablo, not sure why mine went pear shaped :)