> // hellofoo.cxx
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/param.h>
>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Box.H>
>
> int main(int argc, char **argv) {
> Fl_Window *window = new Fl_Window(720,120);
> char buf[MAXPATHLEN];
>
> getcwd(buf, sizeof(buf));
> Fl_Box *box = new Fl_Box(FL_UP_BOX,10,20,200,20,"getcwd(buf) returned:");
> box = new Fl_Box(FL_UP_BOX,210,20,500,20,buf);
> buf[0] = 0; // clear after use for next call
>
> fl_getcwd(buf, sizeof(buf));
> box = new Fl_Box(FL_UP_BOX,10,40,200,20,"fl_getcwd(buf) returned:");
> box = new Fl_Box(FL_UP_BOX,210,40,500,20,buf);
>
> char *cwd = getcwd(0, MAXPATHLEN);
> box = new Fl_Box(FL_UP_BOX,10,60,200,20,"getcwd(0,0) returned:");
> box = new Fl_Box(FL_UP_BOX,210,60,500,20,cwd);
> free((void*)cwd);
>
> cwd = fl_getcwd(0, MAXPATHLEN);
> box = new Fl_Box(FL_UP_BOX,10,80,200,20,"fl_getcwd(0,0) returned:");
> box = new Fl_Box(FL_UP_BOX,210,80,500,20,cwd);
> free((void*)cwd);
>
> window->end();
> window->show(argc, argv);
> return Fl::run();
> }
>
One problem with this code is that you are passing a pointer to
the char array, and then resetting the contents before FLTK has
a chance to draw the contents on the screen, hence garbage.
It's working for the "getcwd() returned:" type text because these
are pointers to fixed strings.
For the others you will need to add copy_label() calls so that
the contents are copied into the widget's memory and control.
> box = new Fl_Box(FL_UP_BOX,210,20,500,20,buf);
box->copy_label(buf);
> buf[0] = 0; // clear after use for next call
> box = new Fl_Box(FL_UP_BOX,210,60,500,20,cwd);
box->copy_label(cwd);
> free((void*)cwd);
D.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk