Thursday, February 21, 2008

How to write a program in order to create a window

How to write a program in order to create a window?

STEPS:

• We have a structure called WNDCLASS, which will store information about the windows, first we have to assign values to the variables of this structure.

• Check whether the values assigned to variables of WNDCLASS structure are valid or not by using a function called RegisterClass().

• Create a Window by the calling a function called CreateWindow();

• Even though we create a window it is not visible until and unless we use a function called ShowWindow()

First step:

Every window must come from a WNDCLASS structure.

We will have to fill up the WNDCLASS structure by assigning values to variables in WNDCLASS structure.

There are 10 variables in WNDCLASS

1) style --It specifies the style about how is the WNDCLASS object created.

2) lpfnWndProc—It specifies the name of the function that will receive and process the messages received by windows created from this class.

3) cbClsExtra—It stores the count extra bytes that may be required by the WNDCLASS structure

4) cbWndExtra—It stores the count of extra bytes that may be needed by windows created from this WNDCLASS.

5) hInstance—It is a handle to the application which has creates this WNDCLASS.

6) hIcon—It specifies the icon that will be displayed when windows created from this class are minimised.

7) hCursor—It specifies the mouse cursor that will be displayed in windows created from this class.

8) hbrBackground—It specifies the brush that will be used for painting the client area.

9) lpszClassName—It specifies the Class name.

10) lpszMenuName—It specifies the menu name that is to be displayed on the window.



Second step:

The second step is to verify whether the values, which are assigned to variables of WNDCLASS structure, are valid or not.

We use RegisterClass function for this purpose.

This function expects a parameter that will be the address of object of WND CLASS structure.




Third step:

After the class is registered successfully we have to create the window from that class.

We use CreateWindow for this purpose that should be provided with 11 parameters.

The declaration of the CreateFunction is as follows:

HWND CreateWindow (LPSTR lpclassname, LPSTR lpwindowname, DWORD dwStyle, int X , int y ,int nWidth,int nHeight, HWND Parent, HMENU menuname, HINSTANCE hInstance, PARAM param)

No comments: