[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Windows API messages
--------------------------------------------------------------------------------
If you review the examples provided in the Petzold book, you will realize
all Windows applications have the same structure:
* Creating the application main window
* Start running the main get-message loop
* Taking decisions based on received messages
Almost all that we see in Windows enviroment is a window. The PushButtons,
the Scrollbars, the CheckBoxes, the Dialogs, etc... are all windows.
Windows sends messages to all windows informing them about what is
happening and about what every window has to do. That is why Windows
API requires the programmer to provide a window procedure for every
window which will be called by Windows in order to give us the messages.
In all Windows applications there must be a typicall defined window
function:
long WINAPI WndProc( HWND hWnd, WORD wMessage, WORD wParam, LONG lParam )
That is the function Windows API uses to sends messages to our defined
window. Lets review those parameters:
* hWnd It is the Window API handle of our window. Windows
identifies every window using a 'handle': a numeric
value Windows API internally generates. This value
must NOT be manipulated, it is a 'read-only' value.
* wMessage It is a numeric value that identifies any of the
Windows API differents messages. All these differents
messages values are provided in a header file
-provided by Microsoft- called Windows.h. FiveWin has
its own WinApi.ch which includes most used messages
identifiers values. If you need to know about them,
please review Windows.h supplied by Microsoft or
Borland or any other Windows tools manufacturer.
* wParam It is a numeric value -a 'WORD' is a number of two
bytes so it is in the range 0-216 - wich is used
to provide the window function with some parameter
value. This parameter may be many different things
according to the sent message.
* lParam It is a numeric value -a 'LONG' is a number of four
bytes so it is in the range 0-232 - wich is used
to provide the window function with some extra parameter
value. This parameter may be many different things
according to the sent message.
The window function typically performs a C swith statement -a Clipper
DO CASE... ENDCASE statement- an performs different actions according
to the message received and its parameters -provided by Windows API-.
In all Petzold examples we will find C code like this:
switch( wMsg )
{
case WM_PAINT:
...
return 0;
case WM_COMMAND:
...
return ...;
...
default:
return DefWindowProc( hWnd, wMsg, wParam, lParam );
}
Windows provides a mechanism for processing unattended messages, that
is, default behaviors to be performed in case we don't care about
all sent messages. That is why those window functions call at the bottom
of them to the Windows API function DefWindowProc( ... ) -Default window
procedure provided by Windows API-.
Our window tells Windows API what to do acording to the different values
the window function may returns. Typically there are these possibilities:
* return 0 Means we have performed an action
and we don't want Windows to do anything.
* return non-zero In some cases Windows API requires some
values.
* If we want We call DefWindowProc( ... ) and returns
standard behavior its value to Windows API.
This process is the main conversation system between Windows API and
our defined windows. In this proccess is where we have to connect to
Clipper Object Oriented kernel in order to convert it into an Object
Oriented process.
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson