This example shows how to fl_message function.
1 #pragma package ".." 2 3 #include "chfltk.h" 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 void message_cb(Fl_Widget *g, void *v) { 8 int *counter = (int*)v; 9 (*counter)++; 10 const char *message = "Called %d times"; 11 fl_message(message, *counter); 12 } 13 14 int main(int argc, char *argv[]) 15 { 16 Fl_Window *window = new Fl_Window(300, 180); 17 Fl_Button *countbutton = new Fl_Button(20, 40, 200, 50, "Message Button"); 18 countbutton->box(FL_UP_BOX); 19 int counter = 0; 20 countbutton->callback((ChFl_Callback)message_cb, (void*)&counter); 21 window->end(); 22 window->show(argc, argv); 23 Fl::run(); 24 exit(1); 25 return 0; 26 }
Code description
- 20
- Overloaded methods need exlicit casting of parameters
- 21
- Type uchar is defined by FLTK to unsigned char. See also the * comment above about overloaded methods
- 23
- Start FLTK event loop
- 24
- This shouldn't be necessary if future releases of ChFLTK but at the moment one needs to call exit() to terminate application smoothly