wxWidget Beginner Questions

BlitzMax Forums/BlitzMax Programming/wxWidget Beginner Questions

Glenn Dodd(Posted 2007) [#1]
I am just starting to work through the modules.
The below code opens 2 windows:


I now want to ask a question if the parent closes with the code below:

but it complains about "unable to convert from wxFrame to MyFrame"

What am i doing wrong?

Cheers
Glenn


Brucey(Posted 2007) [#2]
You'll need something like this :
ParentFrame = MyFrame(New MyFrame.Create(,,"Parent Frame", 100, 100))


"MyFrame.CreateFrame" will create an instance of wxFrame, not MyFrame.
You could override the CreateFrame() function, but using "New MyFrame.Create()" is less work on your part.

What that does, is create a new instance of MyFrame, and then calls the Create() Method - which CreateFrame() also happens to call under-the-hood.

But since Create() is defined as "Method Create:wxFrame()" you need to cast it to MyFrame.
Fun with OOP ;-)

Your next problem is going to be with OnCloseWindow....


Brucey(Posted 2007) [#3]
OnCloseWindow().. :-)

To receive events for window close, you will need to "Connect" a function to the event - this way of coding lets you choose what you are interested in, rather than having every conceivable event available at a particular time. So, as part of your MyFrame type :

	Method OnInit()
		ConnectAny(wxEVT_CLOSE, OnCloseWindow)
	End Method


Now the important bit. Because you are overriding the Close event, you are now in control of the life of the Window. That means that it is up to you to Destroy the window if you *really* want it to close...

	Function OnCloseWindow(_event:wxEvent)
		Local Result:Int = Confirm("Are you sure you want to Close BOTH Windows?")
		If Result = True Then
			wxWindow(_event.parent).Destroy()
		End If
	End Function


And note that you will also have to add an "Import BRL.System" to get Confirm to work.
You might otherwise use a wxMessageDialog, which works in a similar way to Confirm.

HTH :-)


Glenn Dodd(Posted 2007) [#4]


Added what you said and it works perfectly. Many thanks.
The next obvious question is how do I identify if the ChildFrame is still open? No need to ask the question if it is already closed...
I have checked the wxWindow help but i couldn't find anything like "IfChildStillAlive" and the above doesn't work either.

Apologies for the really simple questions but i tried going through the ListCtrl example to get back to basics but it was too much for me. I am building up a small library of step by step examples for myself.


Glenn Dodd(Posted 2007) [#5]
BTW - I have 2 weeks of free time so i plan to get further into the wxWidget stuff.


Brucey(Posted 2007) [#6]
i tried going through the ListCtrl example

You'll probably find the Minimal and Notebook easier to get your head around, since they don't do very much. The others get a bit more complicated much more quickly.

how do I identify if the ChildFrame is still open?

Perhaps you need to create a new Type for that too, which has a flag on it. Otherwise, you have a basic problem because of this - "Field ChildFrame:wxFrame" - which adds a reference count to the ChildFrame. So, even though when the frame is closed and internally you drop 1 reference, you still have your own reference of it, and therefore ChildFrame will never change to Null.
But that's a design problem ;-)

Maybe your parent window can keep a count of the number of child windows, and when the count is zero you don't need to ask any more...
There is a GetChildren() on wxWindow, but I don't think I've implemented it yet - plus that would return you a list of *all* children : frames, panels etc...


Glenn Dodd(Posted 2007) [#7]
Cheers
Have a Merry Christmas.

Glenn