hedit Control Messages

The Pen API defines the WM_PENCTL message and its alias, WM_HEDITCTL. An application can send the WM_PENCTL message to an hedit control like this:

lRet = SendMessage( hwndHedit, WM_PENCTL, wParam, lParam );

The wParam parameter of WM_PENCTL contains an identifier for an HE_ submessage, as listed in Chapter 12, "Pen API Messages." The lParam specifies a value dependent on the HE_ submessage. For more information about the wParam and corresponding lParam values, see the entry for WM_PENCTL messages in Chapter 12, "Pen Application Programming Interface Messages."

Sizing the Writing Area with Control Messages

An hedit control must make allowances for handwriting input by providing a sufficiently large area in which to write. Typically, this area incorporates the control window itself plus an ample margin around the border of the window. Besides increasing user comfort, this extra space helps ensure parts of written characters are not inadvertently clipped, making them difficult to recognize. For example, the cut gesture X often extends above the text selected for deletion. Losing part of the gesture at the edge of the control window can make it less recognizable.

Note that adjusting a control's writing area does not change the appearance or size of the control window on the screen. It only specifies an invisible area overlaying the window; any ink within the writing area belongs to the control. It is possible, though not recommended, to enlarge the writing areas of two nearby controls so that they overlap. In this case, Windows assumes ink within the overlapping area belongs to only one of the control windows, according to normal Windows z-ordering.

The Pen API provides two methods for an application to adjust the size of the control writing area. These methods involve either receiving a PE_SETTARGETS submessage or sending an HE_SETINFLATE submessage. The following sections describe both methods.

PE_SETTARGETS Submessage

As described in the "DoDefaultPenInput Messages" section in Chapter 2, Windows sends a PE_SETTARGETS submessage to the application's window procedure before ink collection begins. This submessage gives the application the opportunity to set the target writing areas by specifying a new TARGINFO structure identified by lParam. The structure member rgTarget contains an array of TARGET structures, one for each target area. The rectangle in the rectBound member of TARGET specifies each target's writing area. The following code fragment shows how to set a writing area 4 pixels larger than the boundaries of the child window:

#define NTARG 3 // Number of target windows

#define MARGIN 4 // Inflation margin in pixel units

LPTARGINFO lpti; // Allocate new TARGINFO structure

HWND hwndCtl[NTARG]; // Handles to child windows

RECT rect; // Bounding rectangle of child

RECTL rectl; // Long version of bounding rect

HGLOBAL h;

.

.

.

h = GlobalAlloc( sizeof( TARGINFO ) + (NTARG - 1)*sizeof( TARGET ) );

lpti = GlobalLock( h );

lpti->cbSize = sizeof( TARGETINFO );

lpti->wFlags = 0;

lpti->htrgOwner = HtrgFromHwnd( hWnd );

lpti->cTargets = NTARG;

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

{

GetWindowRect( hwndCtl[i], (LPRECT) &rect );

rectl.left = (LONG) (rect.left - MARGIN); // Inflate

rectl.top = (LONG) (rect.top - MARGIN); // rectangle

rectl.right = (LONG) (rect.right + MARGIN); // by MARGIN

rectl.bottom = (LONG) (rect.bottom + MARGIN); // pixel units

lpti->rgTarget[i].idTarget = i;

lpti->rgTarget[i].htrgTarget = HtrgFromHwnd( hwndCtl[i] );

lpti->rgTarget[i].rectBound.left = rectl.left;

lpti->rgTarget[i].rectBound.right = rectl.right;

lpti->rgTarget[i].rectBound.top = rectl.top;

lpti->rgTarget[i].rectBound.bottom = rectl.bottom;

}

If the Windows DefWindowProc function handles the PE_SETTARGETS submessage, it creates a TARGINFO structure identifying all child windows as targets. DefWindowProc does not inflate writing areas; that is, it sets the writing area for each child window within the window borders.

HE_SETINFLATE Submessage

An application can also enlarge a control's writing area by sending the submessage HE_SETINFLATE to the control window specifying a RECTOFS structure:

typedef struct {

int dLeft; // Left margin

int dTop; // Top margin

int dRight; // Right margin

int dBottom; // Bottom margin

} RECTOFS FAR * LPRECTOFS;

The RECTOFS structure does not contain the coordinates of a writing rectangle per se; instead, it contains the dimensions of the additional writing margin around the control window. The margins specify how many pixel units to add to each member of the windows rectangle. Margins conform to the x-y screen coordinate system. Thus, to inflate a writing area, specify negative values for dLeft and dTop as shown here:

#define MARGIN 4 // Inflation margin in pixel units

RECTOFS rectofs = { -MARGIN, // Structure of window margins

-MARGIN,

MARGIN,

MARGIN};

.

.

.

wParam = HE_SETINFLATE;

lParam = (LONG)((LPRECTOFS) &rectofs);

lRet = SendMessage( hwndHedit, WM_PENCTL, wParam, lParam );

An application can retrieve a window's current inflation margins with the submessage HE_GETINFLATE like this:

wParam = HE_GETINFLATE;

lParam = (LONG)((LPRECTOFS) &rectofs);

lRet = SendMessage( hwndHedit, WM_PENCTL, wParam, lParam );

This call fills the RECTOFS structure pointed to by lParam with the control window's current margins.

Notification Messages

An hedit window's parent receives the same EN_ notification messages as the parent of a standard edit window. The parent receives a WM_COMMAND message in which the low-order word of the wParam parameter contains the control ID number and the lParam parameter contains the edit window handle. In 16-bit applications, the high-order word of lParam also contains the notification value. In 32-bit applications, the high-order word of wParam contains the notification. The hedit control also provides HN_ notifications, described in Chapter 12, "Pen Application Programming Interface Messages."

The hedit control also sends a WM_CTLINIT message to its parent windows when created. The wParam parameter holds the constant CTLINIT_HEDIT and lParam points to a CTLINITBEDIT structure. The structure contains the current system assumptions concerning the appearance and behavior of the hedit control. The parent window has the option of changing any of these assumptions.

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