Tutorial 1 How To Make A Window For Our Application
Tutorial 1 How To Make A Window For Our Application
First of all make this thing clear that using windows.h is not a bad idea if you want your self
remain for windows platform but what happened when you also want to cover the domains of
other OS respectively so in this tutorial I will explain you both the methods to make something
good and platform dependent and also platform independent.
I assume that you are familiar with the terms “platform dependent” and “platform
independent” So I will make an introduction to windows.h header file which links to
windows library. This library was designed by Microsoft Corporation for windows OS
and still it is being used by programmers who are interested to work with some depth
level. There are also some good alternatives provides by Microsoft and other
organizations e.g. Microsoft family product Visual Studio for both Console and GUI
applications and JBuilder for java applications. So now lets move on to point.
These two code sections are only meant for memorizing or better to be copied because
you will use them frequently in your every Computer Graphics application.
So first we discuss our window library method here I am just pasting the Code from the
book “Programming Windows 5th ed by Charles Petzold” one of my favorite writer
You can view this code on the above mentioned book as “The HELLOWIN Program”.
So here we make a start but this code is little bit modified to meet our needs if you need actual
code then read the book for more knowledge
HELLOWIN.C
/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows XP!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/
#include <windows.h>
http:\\www.yahoogroups.com\cgmania
Computer Graphics tutorials by Jawad ul Hassan
Introduction to Graphics Programming with and without windows.h
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class
name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x
position
CW_USEDEFAULT, // initial y
position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window
handle
NULL, // window menu
handle
hInstance, // program
instance handle
NULL) ; // creation
parameters
switch (message)
{
case WM_PAINT:
http:\\www.yahoogroups.com\cgmania
Computer Graphics tutorials by Jawad ul Hassan
Introduction to Graphics Programming with and without windows.h
hdc = BeginPaint (hwnd, &ps);
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Now if you are familiar with c or C++ syntax and environment you will surely understand every
thing or you can view the book which I will surely upload on the group in some time but trust me
there is no need to waste your time on this section the only thing I recommend to you is that you
should just only copy this piece of code and run it using visual studio or any c compiler on
windows platform. The file windows.h is by default available in windows OS. You will see a
window box.
This is not a complete work for making any graphic application so just relax and observe I will
slightly make some changes in this code to make it workable with any graphic library which is in
our case is opengl.
Now for our second section which is “Creating window application without using
windows.h”.
#include<gl/glut.h>
void myinit(void)
{
// for making screen color
glClearColor(1.0,1.0,1.0,0.0);
// assigning color to our painter
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
void mydisplay(void)
http:\\www.yahoogroups.com\cgmania
Computer Graphics tutorials by Jawad ul Hassan
Introduction to Graphics Programming with and without windows.h
{
glClear(GL_COLOR_BUFFER_BIT);
// make your drawing between these two statements
glFlush();
}
int main() // or int main(int argc, char** argv)
{
// always use these lines
// this one is optional but you can use if you want to otherwise
//skipping it will not make any bad effect
//if you want to use the line below then you should make the main
function with arguments
//which is "int main(int argc, char** argv)"
//making our window size you will surely find it much easier than the
above method
glutInitWindowSize(300,300);
// what is the location of our window on the screen start from upper
left corner
glutInitWindowPosition(0,0);
//we make our window with a string in quotes for window name which is
displayed on //the top of our window which is in that case is CG MANIA
FIRST LESSON.
glutCreateWindow("CG MANIA FIRST LESSON ");
// this function is called only for once and used for initialization we
will also discuss it //later
myinit();
http:\\www.yahoogroups.com\cgmania