Home   Index   About
Ultimate Pack


Custom Search
InputWndProc

The InputWndProc procedure receives the WM_LBUTTONDOWN message that signals the start of an input session. It distinguishes between a pen-down event and a true mouse event, using the methods described in the "Beginning an Input Session" section in Chapter 2.

When it detects the start of a pen-input session, InputWndProc calls the DoDefaultPenInput function to handle the chores of initialization, data collection, and inking.

As described in the "Step 3: PE_GETPCMINFO Message" section in Chapter 2, InputWndProc immediately receives a PE_GETPCMINFO submessage. The lParam variable points to an initialized PCMINFO structure that the system will use for recognition. The SREC recognizer requires the structure to specify a pen-up event as a condition of termination. Accordingly, InputWndProc takes this opportunity to set the PCM_PENUP flag.

InputWndProc next receives a PE_BEGINDATA submessage, as described in "Step 6: PE_BEGINDATA Message" in Chapter 2. In response, the procedure takes one of the following courses of action:

  • If currently using the sample recognizer, InputWndProc creates an HRC object for that recognizer and specifies the HRC in the TARGET structure pointed to by lParam. This tells DoDefaultPenInput to use the sample recognizer SREC instead of the system default recognizer.

  • If displaying a mirror image of the ink, InputWndProc creates an HPENDATA object for the ink and specifies it in the TARGET structure pointed to by lParam. This tells DoDefaultPenInput to collect data into the HPENDATA block instead of passing it to a recognizer.

  • If using the default recognizer, InputWndProc simply passes the message to DefWindowProc, which creates an HRC for the default recognizer. The code also demonstrates how an application can take advantage of the convenience afforded by DefWindowProc, yet override any default assumptions it makes.

When DefWindowProc returns, lParam still points to the TARGET structure, which now reflects the default assumptions. One of these assumptions limits to one the maximum number of guesses the system recognizer should return. Since PENAPP requires a maximum of five guesses, it changes the value by calling SetMaxResultsHRC for the HRC that DefWindowProc creates.

The PE_ENDDATA submessage informs InputWndProc that the input session has ended. The procedure collects any symbols returned by the current recognizer into an array of symbol strings called vsyvSymbol. This portion of the code does not check to see which menu option is current. It simply collects symbols into the array if available. If the Mirror option is selected, the attempt to collect recognized symbols harmlessly fails since no HRC exists.

After it collects the data, InputWndProc invalidates all three child windows. This sends WM_PAINT messages to each window, clearing the Input window and causing the other two windows to display their new data.

#define MAX_GUESS 5 // Maximum number of guesses

#define MAX_CHAR 20 // Maximum number of characters per guess

// Global Variables ***************************************************

HRCRESULT vrghresult[MAX_GUESS]; // Array of results

SYV vsyvSymbol[MAX_GUESS][MAX_CHAR]; // Array of symbol strings

int vcSyv[MAX_GUESS]; // Array of string lengths

.

.

.

LRESULT CALLBACK InputWndProc(

HWND hwnd, // Window handle

UINT message, // Message

WPARAM wParam, // Varies

LPARAM lParam ) // Varies

{

LONG lRet = 0L; // Initialize return code to FALSE

HRC hrc; // HRC object

HDC hdc;

PAINSTRUCT ps;

DWORD dwInfo;

int i, cGuess;

switch (message)

{

.

.

.

case WM_LBUTTONDOWN:

//

// Two possibilities exist: user is using mouse or the pen. // The latter case indicates the user is starting to write.

//

dwInfo = GetMessageExtraInfo();

if (IsPenEvent( msg, dwInfo ))

{

if (DoDefaultPenInput( vhwndInput,

(UINT)dwInfo ) == PCMR_OK)

lRet = TRUE;

else

lRet = DefWindowProc( hwnd, msg, wParam, lParam );

}

break;

case WM_PENEVENT:

switch (wParam)

{

case PE_GETPCMINFO:

//

// If using SREC recognizer, ensure session ends

// on pen-up.

//

if (viMenuSel == miSample)

((LPPCMINFO) lParam)->dwPcm |= PCM_PENUP;

lRet = DefWindowProc( hwnd, msg, wParam, lParam );

break;

case PE_BEGINDATA:

//

// 1) If using sample recognizer, create an HRC

// for it and specify it in the TARGET structure

// pointed to by lParam. This tells

// DoDefaultPenInput to use the sample recognizer

// instead of the system default.

//

// 2) If displaying mirror image of ink, create an

// HPENDATA for it. This tells DeDefaultPenInput

// to collect data into the HPENDATA object

// instead of passing it to a recognizer.

//

// 3) If using default recognizer, pass to

// DefWindowProc. DefWindowProc sets the maximum

// number of guesses to 1; the code below shows

// how to access the HRC that DefWindowProc

// creates and reset the maximum number of

// guesses to MAX_GUESS.

//

if (vhpendata)

{

DestroyPenData( vhpendata );

  • hpendata = NULL;

}

switch (viMenuSel)

{

case miSample:

hrc = CreateCompatibleHRC( NULL, vhrec );

if (hrc)

{

((LPTARGET) lParam)->dwData = hrc;

lRet = LRET_HRC;

}

break;

case miMirror:

  • hpendata = CreatePenData( NULL, 0,

PDTS_HIENGLISH, 0 );

if (vhpendata)

{

((LPTARGET) lParam)->dwData = vhpendata;

lRet = LRET_HPENDATA;

}

break;

case miSystem:

lRet = DefWindowProc( hwnd, msg,

wParam, lParam );

//

// On return, lParam->dwData points to HRC.

// Use it to reset max number of guesses.

//

SetMaxResultsHRC(

((LPTARGET) lParam)->dwData,

MAX_GUESS );

break;

}

break;

case PE_ENDDATA:

//

// DefWindowProc will destroy vhpendata, so if

// collecting mirror image, don't let DefWindowProc

// handle message.

//

if (viMenuSel != miMirror)

lRet = DefWindowProc(hwnd, msg, wParam, lParam);

break;

case PE_RESULT:

//

// At end of input, collect recognition results (if

// any) into symbol strings. DoDefaultPenInput

// generates the PE_RESULT submessage only when

// using a recognizer. The lParam contains the HRC

// for the recognition process.

//

// Collect pen data for DrawRawData

  • hpendata = CreatePenDataHRC( (HRC) lParam );

// Initialize array to zero

for (i = 0; i < MAX_GUESS; i++)

  • cSyv[i] = SYV_NULL;

// Get number of guesses available

cGuess = GetResultsHRC( (HRC) lParam,

GRH_ALL,

(LPHRCRESULT) vrghresult,

MAX_GUESS );

// Get guesses (in vsyvSymbol) and

// their lengths (in vcSyv)

if (cGuess != HRCR_ERROR )

for (i = 0; i < cGuess; i++)

  • cSyv[i] = GetSymbolsHRCRESULT(

vrghresult[i],

0,

(LPSYV) vsyvSymbol[i],

MAX_CHAR );

break;

.

.

.

default:

lRet = DefWindowProc( hwnd, msg, wParam, lParam );

} // End switch (wParam)

break;

default:

lRet = DefWindowProc( hwnd, message, wParam, lParam );

} // End switch (msg)

return lRet;

}


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