Explanation of parameters:
LPSTR lpclassname = It is used to specify the class name.
LPSTR lpwindowname = It is used to specify the caption of the window.
DWORD dwStyle = This parameter is used to specify the style how the window should be displayed. We generally the window style that is WS_OVERLAPPEDWINDOW.
int X and int Y = they specify the x, y co-ordinates of the starting point of the window.
int width and int height = They specify the width and height of the window.
HWND parent = It is used to specify the handle to the parent if we are going to create a child window.
If we are going to create a window for the first time or if it is parent window, this value would be NULL.
HMENU menuname = It is used to specify the handle of the menu, if it NULL it will take the menu name from WNDCLASS structure.
HINSTANCE hInstance = It is used to specify the handle to he application to which the windows belongs to.
PARAM param = It is used to parameters passed to the parent window from the child window.
SHOW WINDOW FUNCTION:
This function is used to show the window created by CreateWindow function, which takes two parameters.
The following is the declaration of the ShowWindow function
BOOL ShowWindow (HWND hWnd, int nCmdShow)
This function will return true that the window is displayed successfully else it will return false.
PARAMETERS :
HWND hWnd = It is the parameter which will specify the handle to the window that is to be displayed.
int nCmdStyle = It is the parameter that specifies the window style how the window should be displayed.
It parameter is one of the parameter of the WinMain function.
It is an integer. By default has 1 as its value.
The parameter nCmdShow can have the any of the below values:
• SW_HIDE
• SW_MINIMIZE
• SW_RESTORE
• SW_SHOW
• SW_SHOWMAXIMISED
• SW_SHOWMINIZED
Now as we have completed all the functions required to create and show a window now the next task is to handle the messages send by the windows operating system to our application,
As discussed earlier the information that event is raised is sent from windows operating system in terms of messages to the active application.
In the application it is stored as a queue and uses a structure called MSG structure
Showing posts with label Chapter3. Show all posts
Showing posts with label Chapter3. Show all posts
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)
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)
MSG STRUCTURE
This is a structure, which is created by the windows operating system for every window as soon as a window is created.
It consists of 6 variables the declaration of the structure is as follows.
Struct tagMSG
{
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
PARAMETERS:
HWND hWnd = It specifies a handle to the window for which the message is generated.
UINT message = It specifies the actual message about the event that got generated.
WPARAM wParam and LPARAM lParam = These parameters hold some additional information about the message generated.
DWORD time = It specifies the time the message was sent or the time when the event is raised.
POINT x, y = It specifies the x, y co-ordinate of the mouse cursor.
MSG structure is the structure, which will store the information of the messages generated.
Messages are small packets of data that windows send to a running program to let it know that an event has occurred.
Windows generates message for every hardware event.
It passes these messages to the appropriate message queue.
The running program or application pulls messages from message queue using the message loop.
The message loop uses the GetMessage function to read messages.
It consists of 6 variables the declaration of the structure is as follows.
Struct tagMSG
{
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
PARAMETERS:
HWND hWnd = It specifies a handle to the window for which the message is generated.
UINT message = It specifies the actual message about the event that got generated.
WPARAM wParam and LPARAM lParam = These parameters hold some additional information about the message generated.
DWORD time = It specifies the time the message was sent or the time when the event is raised.
POINT x, y = It specifies the x, y co-ordinate of the mouse cursor.
MSG structure is the structure, which will store the information of the messages generated.
Messages are small packets of data that windows send to a running program to let it know that an event has occurred.
Windows generates message for every hardware event.
It passes these messages to the appropriate message queue.
The running program or application pulls messages from message queue using the message loop.
The message loop uses the GetMessage function to read messages.
Subscribe to:
Posts (Atom)