Window Procedures

The following code has been changed in the "InputWndProc" section.

#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;

PAINTSTRUCT 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( message, dwInfo ))

{

if (DoDefaultPenInput( vhwndInput, (UINT)dwInfo ) == PCMR_OK)

lRet = TRUE;

else

lRet = DefWindowProc( hwnd, message, 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, message, wParam, lParam );

break;

case PE_BEGINDATA:

//

// Action based on current menu selection:

//

// 1) If currently 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 rather than the system default.

//

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

// HPENDATA for it and specify 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.

//

// 3) If using the default recognizer, pass to DefWindowProc,

// which sets the maximum number of guesses to 1 and may

// or may not require any guide information. The Japanese

// default recognizer (RODAN.DLL) does require a guide

// for character recognition. The following code shows

// how to access the HRC that DefWindowProc creates,

// reset the number of guesses to MAX_GUESS, and set

// up the client rectangle of the input window as a

// single guide.

//

if (vhpendata)

{

DestroyPenData( vhpendata );

vhpendata = 0;

}

switch (viMenuSel)

{

case miSample:

hrc = CreateCompatibleHRC( NULL, vhrec );

if (hrc)

{

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

lRet = LRET_HRC;

}

break;

case miMirror:

vhpendata = CreatePenData( NULL, 0,

PDTS_HIENGLISH, 0 );

if (vhpendata)

{

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

lRet = LRET_HPENDATA;

}

break;

case miSystem:

lRet = DefWindowProc( hwnd, message,

wParam, lParam );

//

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

// Use it to reset max number of guesses.

//

SetMaxResultsHRC( ((LPTARGET) lParam)->dwData,

MAX_GUESS );

{

GUIDE guide;

RECT rc;

GetClientRect(vhwndInput, &rc);

ClientToScreen(vhwndInput, (LPPOINT) &rc.left);

ClientToScreen(vhwndInput, (LPPOINT) &rc.right);

guide.xOrigin = rc.left;

guide.yOrigin = rc.top;

guide.cxBox = rc.right - rc.left;

guide.cyBox = rc.bottom - rc.top;

guide.cxBase = 0;

guide.cyBase = guide.cyBox;

guide.cHorzBox = 1;

guide.cVertBox = 1;

guide.cyMid = guide.cyBox / 2;

SetGuideHRC(((LPTARGET) lParam)->dwData, &guide, 0);

}

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, message, 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.

//

// NOTE:

// Do not destroy HRC, even after getting results!

// DefWindowProc takes care of destroying the object.

//

// Collect pen data for DrawRawData

  • hpendata = CreatePenDataHRC( (HRC) lParam );

// Initialize array to zero

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

vcSyv[i] = 0;

// Get number of guesses available

cGuess = GetResultsHRC( (HRC) lParam,

GRH_ALL,

(LPHRCRESULT) vrghresult,

MAX_GUESS );

// Get guesses (in vsyvSymbol) and their lengths (invcSyv)

if (cGuess != HRCR_ERROR)

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

vcSyv[i] = GetSymbolsHRCRESULT( vrghresult[i],

0,

(LPSYV) vsyvSymbol[i],

MAX_CHAR );

// Destroy the HRCRESULTS

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

DestroyHRCRESULT(vrghresult[i]);

break;

.

.

.

default:

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

} // End switch (message)

return lRet;

}

  • In the "DisplayGuesses" section of the "InfoWndProc" section, the following code has changed.

VOID DisplayGuesses( HDC hdc ) // DC handle

{

TEXTMETRIC tm;

int nX, nY; // Text coords

.

.

.

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

{

if (vcSyv[i] > 0)

{

SymbolToCharacter( (LPSYV) vsyvSymbol[i],

vcSyv[i],

(LPSTR) szText,

(LPINT) &cChar );

for (nLen = 0; cChar > 0; cChar--)

nLen += IsDBCSLeadByte(*(szText + nLen)) ? 2 : 1;

TextOut( hdc, nX, nY, (LPSTR) szText, nLen );

nY += tm.tmExternalLeading + tm.tmHeight;

}

}

}

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