WinMain
The WinMain function performs the same tasks as a regular Windows function:
- It calls the initialization functions to register window classes and create
windows.
- It enters a message loop to process messages from the application queue.
- The message loop ends when the user chooses Exit from the menu, generating a
WM_DESTROY message, which in turn posts a WM_QUIT message to WinMain. When the GetMessage function detects the WM_QUIT message, it returns NULL to end the loop.
The WinMain function calls
GetSystemMetrics to check whether pen services are installed. If they are not found, the
application should either exit with an explanatory message or alter its behavior to
run without pen input.
Note that Microsoft pen services must be installed when Windows starts. Simply
linking PENWIN.DLL and loading it at runtime is not sufficient to initialize
pen services. For this reason, unless it is known that the application being
developed will always be run on a system with pen services installed, pen API
should be called through function pointers. This mechanism insures that a
pen-aware application can run only on a system on which pen services has been properly
installed and will not run on any system that merely has PENWIN.DLL on the
path. See the HFORM sample application for an example of this technique.
For the sake of simplicity and readability, the PENAPP application described
in this chapter links directly to PENWIN.DLL and does not use function pointers.
int PASCAL WinMain(
HANDLE hInstance, // Instance handle
HANDLE hPrevInstance, // Previous instance handle
LPSTR lpszCommandLine, // Command line string
int cmdShow ) // ShowWindow flag
{
MSG msg;
// Mention to prevent compiler warnings ....
lpszCommandLine;
if (!hPrevInstance) // If first instance,
if (!InitApp( hInstance )) // register window class
return FALSE; // Exit if can't register
if (!InitInstance( hInstance, nCmdShow ))
// Create this instance's window
return FALSE; // Exit if error
if (!GetSystemMetrics( SM_PENWINDOWS )) // If no pen services
return FALSE; // exit
while (GetMessage( (LPMSG) &msg, NULL, 0, 0) )
{
TranslateMessage( (LPMSG) &msg );
DispatchMessage( (LPMSG) &msg );
}
return 0; // Success
}
The InitApp function initializes data and registers the window classes. Following
standard programming practice for Windows, the function returns FALSE if it cannot
register the window classes.
For the Input window, InitApp specifies a cursor type of IDC_PEN. This is the default cursor type supplied
by the pen-aware display driver. For more information on pen types, see the
reference section for the IDC_ constants in Chapter 13, "Pen Application
Programming Interface Constants."
The following fragment shows how InitApp creates the Input window:
BOOL InitApp( HANDLE hInstance ) // Instance handle
{
WNDCLASS wc;
.
.
.
//
// Register PenApp child window classes
//
wc.hCursor = LoadCursor( NULL, IDC_PEN );
wc.hIcon = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = (LPSTR) szPenAppInputClass;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS;
wc.lpfnWndProc = InputWndProc;
if (!RegisterClass( (LPWNDCLASS) &wc) )
return FALSE;
.
.
.
}
- Software for developers
-
Delphi Components
.Net Components
Software for Android Developers
- More information resources
-
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
- Databases for Amazon shops developers
-
Amazon Categories Database
Browse Nodes Database