Wednesday, February 20, 2008

PROCESSMESSAGEFN, Explanation Function

PROCESSMESSAGEFN FUNCTION:

This function will process messages which it receives from DispatchMessage () function.

The syntax of this function is as follows

long PASCAL ProcessMessagefn (HWND hWnd, UINT message, WPARAM wParam, and LPARAM lParam)

PARAMETERS:

HWND hWnd: It is handle to the window for which the message has been generated.

UINT message: It is the message that has been generated.

WPARAM wParam and LPARAM lParam: It is the additional information about the message.


This will contain set of conditions that will do the job of processing the messages.

Consider the following example:

long PASCAL ProcessMessagefn(HWND hWnd, UINT message,WPARAM wParam LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default :
return DefWindowProc(hWnd,message,wParam,lParam);
}

return 0;
}



NOTE: This is a part of the program but not the complete program, and will give us the output if at all this is executed as it is.



Explanation of the program:

As already been explained ProcessMessagefn function is used to do the job of processing the messages.

So it contains a set of switch to handles different types of messages.

Whenever an event is generated windows operating system sent a message to the application message queue.

They are a set of window messages, which have their own definition, and they are raised in response to any event.

For example in the above example we have WM_DESTROY

This message is generated by windows operating system, where WM stands for window message. It is generated whenever we click on the close button or quit from the window.

This is the message sent by windows to the application to destroy the window crated by it.

Our application should be able to handle all the messages sent by the windows.

So, to terminate or destroy the application window and to return control back to the operating system we use a function that is PostQuitMessage (0);

This function release the entire memory allocated to all windows of that particular application and returns the value 0 or the control to the operating system.

No comments: