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;

}

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