Course list http://www.c-jump.com/bcc/
FLTK ( www.fltk.org ) is a is an Open Source, cross-platform C++ library to create desktop applications with Graphical User Interface. FLTK includes FLUID program to interactively design your GUI interface.
Download the source of the latest stable release version (e.g. fltk-N.N.N-source.tar.gz) from FLTK library website. FLTK is cross-platform tool that works with Microsoft Visual Studio on Windows, as well as Linux and MAC OS.
Unzip the downloaded file. The process takes two steps: first, it unzips into a .tar file. Next, unzip the .tar file, which creates a subdirectory named fltk-N.N.N.
Navigate to fltk-N.N.N\ide\VisualC2010
Double-click the file named fltk.sln. This will open a large solution that includes the source code for the FLTK demo apps and FLTK library itself. Be patient, it may take almost up to a minute for all parts to load into Visual Studio development environment.
Since FLTK is open source software, once downloaded, it needs to be built on your computer. Click Visual Studio menu
Build -> Configuration Manager...
and switch active configuration to Release.
Click Visual Studio menu
Build -> Rebuild Solution
Be patient as the surce code is being compiled. It will take several minutes to finish. If everything is okay, you should see a message similar to
========== Rebuild All: 79 succeeded, 0 failed, 0 skipped ==========
at the end.
Click Visual Studio menu
Build -> Configuration Manager...
and switch active configuration to Debug.
Click Visual Studio menu
Build -> Rebuild Solution
Exit Visual Studio.
You need to decide where your GUI projects will reside on your computer. It doesn't have to be a fixed directory (Windows refers to directories as "folders".) For example, on my laptop it may be
C:\bcc
and
F:\research
on my desktop.
You can copy your FLTK projects to different places and it should continue to work just fine.
Do not to use spaces in your directory and file names. If you do, some things can break and cause a headache.
Download c255labs_vc2019_fltk_1_3_5.zip built with Visual Studio 2019.
(If you are using an older compiler, try c255labs.zip, which was built with Visual Studio 2010.)
Unzip c255labs_vc2019_fltk_1_3_5.zip in your directory. (I also recommend deleting the ZIP file when you are done.) The result should be:
C:\bcc\c255labs
It will contain the following subdirectories:
bin.........EXE programs that you build will be here example.....Sample programs external....External libraries: FLTK C++ headers, LIB files, and the FLUID program JPEG........JPEG Image files shared between multiple projects labs........Our lab projects and your homework
The external subdirectory is preconfigured. Unless you having problems building and running your C++ programs, don't change anything. Alternatively, you can replace LIB and C++ header files with those that you build yourself as described later in "Copy FLTK files" section of this handout.
Go to fltk.org and click Download link.
Download the latest fltk-N.N.N-N-source.tar.gz file.
Unzip downloaded content. For example,
C:\Users\myself\Downloads\fltk-N.N.N-N
Open ide, then VisualC2010 subdirectory:
C:\Users\myself\Downloads\fltk-N.N.N-N\ide\VisualC2010
Scroll down and locate file named fltk.sln
Start Visual Studio and click File, Open, Project/Solution...
Open fltk.sln solution file.
Click OK to upgrade VC++ compiler and libraries.
Check that everything is completed, 0 failed, 0 skipped.
Click Build, then Build Solution. Wait till the build is complete. This may take a few minutes. Verify that build succeeded, 0 failed, 0 up-to-date, and 0 skipped.
Click Build, then Configuration Manager... Change "Active solution configuration" to Release and click Close.
Again, click Build, then Build Solution. Wait till the build is complete. This may take a few minutes. Verify that build succeeded, 0 failed, 0 up-to-date, and 0 skipped.
Exit Visual Studio.
Note: current version of c255labs_vc2019_fltk_1_3_5.zip is pre-configured with Microsoft Visual Studio Community 2019 Version 16.6.5 and fltk-1.3.5. If you are running Visual Studio 2019, chances are you don't need the latest version of FLTK. Try "Hello, GUI!" in the next section.
If your project builds and runs fine, continue reading the next part, "C++ headers and LIB files".
If you want the newest version of FLTK library or experiencing compiler, linker, or runtime errors, use two side-by-side Windows Explorer windows to copy and paste the latest FLTK files from fltk-N.N.N-N to c255labs\external as follows:
From To fltk-N.N.N-N\fluid\fluid.exe ----> c255labs\external\fluid fltk-N.N.N-N\FL\*.* -------------> c255labs\external\include\FL fltk-N.N.N-N\GL\*.* -------------> c255labs\external\include\GL fltk-N.N.N-N\lib\*.* ------------> c255labs\external\lib
Start Visual Studio and open project
C:\bcc\c255labs\labs\c255_lab01_intro\c255_lab01.sln
Click
View -> Solution Explorer
Open source file c255_lab01_main.cpp. The file is empty. Paste the following code:
#include <Windows.h> // include Windows.h only if using WinMain #include "FL/Fl.H" #include "FL/Fl_Box.H" #include "FL/Fl_Window.H" // Use standard main to have console background: // int main() // Use WinMain if you don't want the console in the background: int __stdcall WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd ) { Fl_Window window( 200, 200, "My window title" ); Fl_Box box( 0, 50, 200, 20, "Hello" ); window.show(); return Fl::run(); }
Compile the project:
Build -> Build Solution
(or simply press F7.)
When you compile your program,
All CPP files are compiled into OBJ files by the C++ compiler
All OBJ and LIB files are linked together and written into the EXE file by the linker.
When you run your EXE program, necessary DLLs are also loaded into memory, and program can starts calling functions in our EXE and in DLL files.
C++ header files are plain text files that contain declarations of constant variables, C++ functions, and classes.
C++ function declarations are functions without a body. For example,
// myheader.h // Function declaration: bool load_data_from_file( char const* filename );
Once the header is included in your C++ program, you can call this function
// main.cpp #include "myheader.h" int main( int argc, char* argv[] ) { bool success = false; success = load_data_from_file( "C:/data/mydata.txt" ); if ( !success ) { // could not load data from file } else { // everything is good } return 0; }
There are a few possibilities where the function load_data_from_file() can be defined:
(a) you implement it in your own C++ file and compile
(b) it is written by someone else and exists in a binary form inside a DLL file (dynamic link library)
(c) it is written by someone else and exists in a binary form inside a LIB file (linker library)
What's the difference?
(a) -- no additional steps required
(b) and (c) -- you need to tell the linker where the LIB file is located. To do this, you set the path to the LIB file in "Additional Library Directories" and "Additional Dependencies" of your linker's configuration.
FLTK does not use DLLs, only LIB files. (However, if you want to add DLL files to our project, you can copy your DLLs to the directory where your EXE file is written. The reason is because when the program runs, it first searches the local directory (the place where the program is run from) for the required DLLs. If it can't find it, it looks in anything that your $PATH environment variable specifies.)
There are actually two places where our EXE files may be written:
C:\bcc\c255labs\bin\Debug C:\bcc\c255labs\bin\Release
It depends whether you use "Debug" or "Release" configuration in your project. Most programmers test their code under both configurations.
A LIB file (or library) contains binary code used by the linker to link someone else's code with our executable file. LIB files may also contain indirect references to functions in DLLs, but we don't have to use those with FLTK.
Our c255_lab01 project has been pre-configured to use FLTK. The configuration specifies the location of
FLTK C++ header files:
c255labs\external\include
FLTK LIB files:
c255labs\external\lib
EXE output directory (for Debug and Release):
c255labs\bin
If you need to create your own project:
Use menu
File -> New -> Project
Make sure to select C++ language and "Win32 Project"
Specify project name
Specify directory location of your project, such as
C:\bcc\c255labs\playground
Uncheck "Create directory for solution"
Once project is created, select
View -> Solution Explorer
Right-click "Source Files", then
Add -> New Item...
and select CPP file type. Name it main.cpp. Copy and paste the code from this lab.
Right-click the name of your project in the Solution Explorer. Select Properties.
Under C/C++, specify Additional Include Directories:
..\..\external\include
Switch to Debug configuration.
Under Linker/Input, specify Ignore Specific Default Libraries:
libcd.lib
Under Linker/Input, specify Additional Dependencies as follows:
fltkd.lib fltkformsd.lib fltkgld.lib fltkimagesd.lib fltkjpegd.lib fltkpngd.lib fltkzlibd.lib
Switch to Release configuration.
Under Linker/Input, specify Ignore Specific Default Libraries:
libc.lib
Under Linker/Input, specify Additional Dependencies as follows:
fltk.lib fltkforms.lib fltkgl.lib fltkimages.lib fltkjpeg.lib fltkpng.lib fltkzlib.lib
Make sure to test your program for both Debug and Release builds.
This is a self-learning lab. There are no files to submit. Make sure to complete all required steps to build and test the project on your own home computer.