Friday, November 4, 2011

Creation and Displaying of Window in C programming language

Creating and displaying a window on the screen is a 4-step process. These steps are:
(a) Creation of a window class.
(b) Registering the window class with the OS.
(c) Creation of a window based on the registered class.
(d)
Displaying the window on the screen.
Creation of a window class involves setting up of elements of a structure called WNDCLASSEX. This structure contains several
elements. They govern the properties of the window. Registration of a window class, creation of a window and displaying of a window involves calling of API functions RegisterClassEx( ), CreateWindow( ) and ShowWindow( ) respectively. Since all the 4 steps mentioned above would be required in almost every program in this chapter I have written this code in a user-defined function called InitInstance( ) in the file ‘helper.h’.
Though writing code in a header file goes against the convention I have still done so to achieve simplicity. The complete listing of ‘helper.h’ file is available in Appendix F. Alternatively you can download it from the following link:
www.kicit.com/books/letusc/sourcecode/helper.h
As expected WinMain( ) starts off by calling the function InitInstance( ) present in ‘helper.h’ file. This file has been #included at the beginning of the program. Remember to copy this file to your project directory—the directory in which you are going to create this program.
Once the window has been created and displayed let us see how we can interact with it.

No comments:

Post a Comment