Tuesday, 20 December 2011

First GUI application in Code Blocks

This tutorial is about creating the first GUI (Graphical User Interface) application in Code Blocks IDE(see the Necessary tools page). Follow these steps:
Step 1:
Run Code Blocks.

Step  2:
Click on the Create a new project link.

Step 3:
Select Win32 Gui Project in the window that appears.

Step 4:
Click on Go button. In the wizard that appears, click next and then under "Select a project type", select "Dialog based"(selected by default). Click next. Type a project title and then keep all as it is. Lastly, click finish.

Step 5:
On the left side, you can see the main.cpp file that contains the actual code that runs the program. Plus, there is a resource.h header file and a resource.rc resource file.

Step 6:
Click on the build icon. Once the project is built, click on the run icon.
Congratulations, you have run your first windows GUI application.
A screen shot of the application is shown below:

Like main() is the entry point of a program in normal C programs, so is WinMain() in win32 programs. resource.rc file contains our dialog design information. In other words, it is the dialog box here. A detailed discussion on what exactly the parameters are, the resource.rc file and other things will make the post lengthy. Instead, I post below some good links for you to further grasp the concepts.


For the call back function DialogProc(name can be different), see the WindowProc function at msdn at the link below:

For resource files:

There is also a free resource editor that allows you to graphically design the dialog. Download it from  http://www.resedit.net/. Now run the resource editor, browse to the resource.rc file and open with it. Bring some changes in it. Save it, and rebuild the application. Now see that the changes you made are reflected in the dialog box.

Rest is left for the reader to explore.
Constructive criticism and suggestions are welcome.

No comments:

Post a Comment