This example shows how to create Fl_Button widget.
The program produces the following picture:
1 #pragma package ".." 2 3 #include "chfltk.h" 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 void change_color_cb(Fl_Widget *g, void *v) { 8 static int i=0; 9 i=(i+1)%2; 10 if (i) { 11 g->labelcolor((unsigned)FL_RED); 12 } else { 13 g->labelcolor((unsigned)FL_GREEN); 14 } 15 } 16 17 int main(int argc, char *argv[]) 18 { 19 Fl_Window *window = new Fl_Window(300, 180); 20 Fl_Button *box = new Fl_Button(20, 40, 260, 100, "Hello World"); 21 box->box(FL_UP_BOX); 22 box->callback((ChFl_Callback)change_color_cb, (void*)0); 23 box->labelsize((uchar)36); 24 box->labelfont((uchar)(FL_BOLD+FL_ITALIC)); 25 window->end(); 26 window->show(argc, argv); 27 Fl::run(); 28 exit(1); 29 return 0; 30 }
Code description
- 11
- Argument type of overloaded methods must be set by explicit casting
- 22
- Overloaded methods need exlicit casting of parameters
- 23
- Type uchar is defined by FLTK to unsigned char. See also the * comment above about overloaded methods
- 27
- Start FLTK event loop
- 28
- This shouldn't be necessary if future releases of ChFLTK but at the moment one needs to call exit() to terminate application smoothly