Use this file to discover all available pages before exploring further.
Windows are the container widgets that provide the actual operating system windows for your FLTK applications. The Fl_Window class manages both top-level windows (with borders and title bars) and embedded subwindows.
Windows can be created with or without explicit position (FL/Fl_Window.H:139-190):
Auto-positioned
Explicit Position
Subwindow
// Window manager chooses positionFl_Window *win = new Fl_Window(640, 480);Fl_Window *titled = new Fl_Window(640, 480, "My Application");
// Position at specific screen coordinatesFl_Window *win = new Fl_Window(100, 100, 640, 480);Fl_Window *titled = new Fl_Window(100, 100, 640, 480, "My App");
// Create parent windowFl_Window *parent = new Fl_Window(800, 600);parent->begin();// Subwindow positioned relative to parentFl_Window *child = new Fl_Window(50, 50, 300, 200);child->end();parent->end();
// Set window titlewin->label("Application Title");// Set icon label (for taskbar/iconified state)win->iconlabel("App");// Set both at oncewin->label("Window Title", "Icon Title");// Copy label (widget manages memory)win->copy_label(temp_string);
Fl_PNG_Image *icon = new Fl_PNG_Image("icon.png");win->icon(icon);// Multiple sizes for best qualityFl_RGB_Image *icons[] = {icon16, icon32, icon48};win->icons(icons, 3);// Set default icon for all windowsFl_Window::default_icon(icon);
From FL/Fl_Window.H:239-296, FLTK supports three window states:
1
Normal Windows
Fl_Window *win = new Fl_Window(400, 300);// Normal window - allows interaction with other windows
2
Modal Windows
Fl_Window *dialog = new Fl_Window(300, 200, "Dialog");dialog->set_modal();dialog->show();// Blocks all other windows until closedif (dialog->modal()) { // Window is modal}
3
Non-Modal Windows
Fl_Window *toolbar = new Fl_Window(400, 60, "Tools");toolbar->set_non_modal();toolbar->show();// Stays on top but doesn't block other windowsif (toolbar->non_modal()) { // Window is non-modal}
// Must hide window first to change modalitywin->hide();win->clear_modal_states(); // Clear modal/non-modalwin->set_non_modal(); // Set new statewin->show();
// Show windowwin->show();// Show with command-line arguments (for main window)win->show(argc, argv);// Hide windowwin->hide();// Check if shownif (win->shown()) { // Window has been show() called}// Wait for window to be fully displayedwin->wait_for_expose();
win->position(100, 100); // Position before show()win->show();// Free position (let window manager decide)win->free_position();
// Center on mouse cursorwin->hotspot(widget);win->show();// Position relative to coordinateswin->hotspot(x, y);win->show();
// Get screen dimensionsint X, Y, W, H;Fl::screen_xywh(X, Y, W, H, 1); // Screen #1// Position on specific screenwin->position(X + 100, Y + 100);win->screen_num(1);win->show();
// Set as current drawing contextwin->make_current();// Get current windowFl_Window *current = Fl_Window::current();// Flush buffered graphicswin->flush();
// Set window cursorwin->cursor(FL_CURSOR_DEFAULT);win->cursor(FL_CURSOR_WAIT);win->cursor(FL_CURSOR_CROSS);win->cursor(FL_CURSOR_HAND);win->cursor(FL_CURSOR_MOVE);// Custom cursor from imageFl_RGB_Image *cursor_img = new Fl_RGB_Image(...);win->cursor(cursor_img, hot_x, hot_y);// Set default cursor (used when mouse is over window)win->default_cursor(FL_CURSOR_ARROW);
// Create shaped window from image alpha channelFl_PNG_Image *shape = new Fl_PNG_Image("shape.png");win->border(0);win->shape(shape);// Get current shapeconst Fl_Image *s = win->shape();
// Prefer Fl_Double_Window to avoid flickerFl_Double_Window *win = new Fl_Double_Window(800, 600);
Set Size Constraints
// Prevent windows from becoming too smallwin->size_range(400, 300);
Handle Close Events
void close_cb(Fl_Widget *w, void *data) { if (Fl::callback_reason() == FL_REASON_CLOSED) { // Save state before closing if (confirm_exit()) { ((Fl_Window*)w)->hide(); } }}win->callback(close_cb);