I tried to explain what happens and how to solve it in my
reply to your first post before I saw this one. Please look at
the example code given there for how to write the close_cb()
callback and below for instructions and comments how to
include it in your code.

On 08.10.2011 09:46, Marko wrote:
> #include<Fl/Fl_Window.h>
>
> #include "inputwin.h"   //<-THIS IS A CUSTOM DIALOG WITH ITS OWN WINDOW

add close_cb() callback here...

> //MAIN WINDOW CLASS
>
> class MainAppWin : public Fl_Window
> {
>    public:
>    MainAppWin(int width, int height, char* title);
>     ~MainAppWin();
>
>    inputwin *inputdialog;
>
> };
>
>
> //CONSTRUCTOR
>
> MainAppWin::MainAppWin(int width, int height, char* title) : Fl_Window(width, 
> height, title)
> {
>
>    inputdialog = new inputwin(300,105,"Input Dialog");

// add the callback to your main window here:

      callback(close_cb,inputdialog);
>
>
> }
>
> //DESTRUCTOR
>
> MainAppWin::~MainAppWin()
> {
>

// at this point, the inputdialog window will already be
// closed - no need to hide() it, but it doesn't do any harm.

// remove next line
>    inputdialog->hide();

// see comment below about the next line
>    delete inputdialog;
>
>   }
>
>
>
> //MAIN
>
> int main(int argc, char** args)
> {
>     MainAppWin *mywin= new MainAppWin(400, 400, "MainAppWin");
>
>
>        mywin->show();
>        mywin->inputdialog->show();
>
>
>
>     Fl::run();
>
>     return 0;
> }
>
>
>
> //------------------------------------------
>
> Thanks Ian MacArthur for your explanation but I'm still unsure how to solve 
> this.  So I posted some code.
>
> This compiles and when I run it two windows show up on the screen.
>
> See this image;
>
> http://www.hyperscope.net/snapshot1.png
>
>
> One window with the title "MainAppWin" and the other (which is in front) 
> titled "Input Dialog" (that one was created from the class in the include 
> file input.h)
>
> If I click on the kill button at the top of the "MainAppWin" it closes but 
> the window that was in front stays open, why doesn't it close also?  How 
> would I make it work right?  Thanks for helping.

Further notes:
As I explained in my other post, closing (hiding) windows doesn't delete
the window objects, and hence the d'tor of the main win will be called
when the program exits. However, there is no need to delete objects that
are used until the program exits - this will be done by the OS anyway,
and doing it explicitly will usually slow down your program at exit.
The only exception would be if you had to do some other cleanup when
deleting objects, such as closing files (and maybe writing logs or
other clean shutdown functions).

Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to