Home   Index   About
Ultimate Pack


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


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