FLTK GUI
Simple FLTK tutorial using Bloodshed Dev-C++ with MinGw
Download Software
Get the latest version of Bloodshed Dev-C++ with Mingw/GCC from (~9 MB):
http://www.bloodshed.net/dev/devcpp.html
or v-4.9.9.2 directly from:
http://prdownloads.sourceforge.net/dev-cpp/devcpp-4.9.9.2_setup.exe
Install in an appropriate place.
After starting the program the first thing you need to do is to download the FLTK library. Go to “Tools->Check for updates / packages”.
Select devpak server “devpaks.org Community Devpaks” click “Check for updates” and check the fltk version 1.1.7 and click “Download selected” and continue with the installation of the library. 1.1.7 is a stable version of the FLTK library. FLTK2 is still a beta release.
Start a new FLTK project
Start Bloodshed Dev-C++ and start a new project “File->new-> project”. Choose “Empty Project” and give the project a name.
Add a new source file to the project “File->new->Source File”. Save file as main.cpp.
In order to setup the FLTK library for the project go to “Project->Project options” and add the following under the Parameters tab:
Compiler: -DWIN32 -mms-bitfields Linker: -lfltk -lole32 -luuid -lcomctl32 -lwsock32 –lm
Under the General tab choose Win32 GUI.
The quick way of creating a FLTK project
“File->new-> project” and choose GUI and FLTK. This will automatically set up the linking and compiler setttings. File:Newproject2.bmp
Develop code
Create a new source file and write the following code:
#include !<FL/Fl.H> #include \<FL/Fl_Window.H> int main (int argc , int **argv) { Fl_Window win(400,200,"Test"); //win(width, height,name) win.show(); // show window return(Fl::run()); //fltk application loop }
Save and press F9 (Compile & Run) and a simple window will be created.
Create a simple window with a button
#include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> void but_cb(Fl_Widget* w, void*){ Fl_Button *b= (Fl_Button*)w; if (b->label() == "Off") { b->label("On"); }else{ b->label("Off"); } } int main (int argc , int **argv) { Fl_Window win(400,200,"Test"); //win(width, height,name) Fl_Button but(100,50,70,30,"On"); win.show(); // show window but.callback(but_cb); return(Fl::run()); //fltk application loop }