Kjell wrote:
> Hi,
>
> I've recently taken to experimenting with this graphics library and have
> had some success with it so far.
Just as a side, you may want to look at these links if you haven't
already:
FLTK CHEAT PAGE:
http://seriss.com/people/erco/fltk/
FLTK FIRST TIME USER VIDEO TUTORIALS
http://seriss.com/people/erco/fltk-videos/
> I'm developing my own application with
> the limited knowledge that I have of programming but consider myself an
> intermediate programmer.
The one big problem in the code is the callback tries to manipulate
the userdata argument "void*v", but when you set up the callback, you're
not passing in any user data. So at runtime *v in the callback will
likely
be NULL, causing a runtime error.
See below.
> int main()
> {
> Fl_Double_Window* Win = new Fl_Double_Window(150,150, "Test");
> Win->begin();
>
> Fl_Button* But = new Fl_Button(40, 50, 75, 30, "CB Test");
After the above line, you probably want "Win->end();"
so that your NuWin doesn't become parented (inside of) Win.
(I'm assuming you want NuWin as a separate window. If not,
disregard this recommendation)
> Fl_Window* NuWin = new Fl_Window(50, 100, "Hooray!");
After this, do your NuWin->end();
regardless of the intention of the above.
> But->callback(Button_CB);
Here lies the problem: the second argument is supposed to be the
userdata; you can leave it unset if you don't plan to use the userdata
in your callback.. but down below it appears you DO try to use it,
so you should set it here; change the above line to read:
But->callback(Button_CB, (void*)NuWin);
..so that the NuWin pointer is passed as the void userdata
to the callback. See below for a needed change to the callback.
So in all, basically you want:
// Define main window
Win = new Fl_Double_Window(..);
But = new Fl_Button(..);
Win->end();
Win->show();
// Define second window
Fl_Window *NuWin = new Fl_Window(..);
But->callback(Button_CB, (void*)NuWin);
NuWin->end();
> void Button_CB(Fl_Widget* w, void* v)
> {
> TestWin* tWin = (TestWin*)v;
> tWin->NuWin->show();
> }
Not sure what TestWin is doing here since you don't
actually create a TestWin instance.
I think what you might want instead is:
void Button_CB(Fl_Widget* w, void* v)
{
Fl_Window *NuWin = (Fl_Window*)v;
NuWin->show();
}
If you DO want to use TestWin, then create an instance of it, eg:
// Define second window
TestWin *NuWin = new TestWin(..); // USE
"TestWin" INSTEAD OF "Fl_Window"
..and change your callback similarly:
void Button_CB(Fl_Widget* w, void* v)
{
TestWin *NuWin = (TestWin*)v;
NuWin->show();
}
But note that your TestWin class is missing some stuff,
namely the constructor is missing the ": Fl_Window(w,h,c)",
and also the pointers inside are not being initialized to
anything. That class definition will need more work to do
what you want.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk