Possible decl windows as type

BlitzMax Forums/BlitzMax GUI Programming/Possible decl windows as type

hi there

I wondering if it's possible to do this

Type InfoWin
     Field Index:Int
     Field Caption:String
End Type

Global Window:InfoWin[30]
Window[0]=CreateWindow("My Window",30,20,400,300,0)


this code does't work. it's there a way to use variable with type in this case ? or maybe there another way to archive this


thanks

I don't really understand what you are trying to achieve. Do you want an array of windows? In which case, you could do something like:

Global MyWindows:<b>TGadget</b>[30]
MyWindows[0] = CreateWindow("My Window",30,20,400,300,Null)
Or do you actually want to extend the TGadget type to hold more information about each gadget? If this is the case, you may want to consider extending TProxyGadget instead.

Please clarify exactly what you mean.

Sorry .... Yes I want to extend TGadget to hold getting more information about other gadgets. TProxyGadget ? humm it's in MaxGUI ?

Yes I want to extend TGadget to hold getting more information about other gadgets. TProxyGadget ? humm it's in MaxGUI ?

Yep - have a look in brl.mod/maxgui.mod/gadget.bmx. Basically, it's something Skidracer added to allow you to easily extend TGadget to create custom gadgets etc.

Here's a quick demo:

SuperStrict

Global myInfoWins:TInfoWin[5]

'Let's create some TInfoWin s
For Local i% = 0 Until myInfoWins.length
	
	myInfoWins[i] = CreateInfoWindow( "Window " + i, 50+40*i, 50+20*i, 200, 150, Null, WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_TOOL)
	myInfoWins[i].myInfoText = "Random fact " + i
	
Next

CreateTimer 1

Repeat

	Select WaitEvent()
		
		Case EVENT_APPTERMINATE;End
		
		Case EVENT_TIMERTICK
		
			For Local tmpInfoWin:TInfoWin = EachIn myInfoWins
				
				'You can use them just like normal gadgets, except you can also access your extended fields
				SetGadgetText tmpInfoWin, tmpInfoWin.myInfoText + " (" + CurrentTime() + ")"
			
			Next
		
		Case EVENT_WINDOWCLOSE;End
		
	EndSelect
	
Forever


'TInfoWin Custom Declarations

Type TInfoWin Extends TProxyGadget

	Field myInfoText$

EndType

Function CreateInfoWindow:TInfoWin( pTitle$, pX%, pY%, pW%, pH%, pParent:TGadget = Null, pStyle% = 15 )
	
	Local tmpWindow:TGadget = CreateWindow(pTitle, pX, pY, pW, pH, pParent, pStyle)
	Local tmpInfoWin:TInfoWin = New TInfoWin
	tmpInfoWin.SetProxy tmpWindow	'We tell the type instance, which gadget it is to represent
	Return tmpInfoWin

EndFunction


ah thanks a lot :)