Home   Index   About
Ultimate Pack


Custom Search
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;

.

.

.

}


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun