Edit Control Notification Messages and Processing
Windows Predefined Controls – Part 5
Volume - Windows User Interface
Forward: In this part of the series, we look at Edit Control Notification Messages and Processing.
By: Chrysanthus Date Published: 29 Aug 2012
Introduction
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Scenario
The user does something to the edit control such as changing the text in the edit control or clicking it. This event is sent as a notification message to the procedure of the parent window by the operating system. That procedure processes the message.
Assume that the user changes text in the edit control. The notification code for this is, EN_CHANGE (see below). The edit control uses a WM_COMMAND Message to send its notification code to the procedure of the parent window. In the procedure, code can be written to check if the new spelling in the edit control is correct. Such spelling checker code will be very long; I am just indicating that here as an example; you are not oblige to check the spelling of the content of the edit control. However, by checking the spelling you are processing the message (notification code).
The WM_COMMAND Message
A windows message has three parts in general, which are the uMsg parameter, the wParam parameter and the lParam parameter. For the WM_COMMAND Message, uMsg is, WM_COMMAND; the low word (LOWORD) of the wParam parameter is the Control Identifier, while the high word (HIWORD) of the wParam parameter is control-defined notification code such as EN_CHANGE. The lParam parameter is the handle of the control window.
Assume that the user change text in the edit control. The procedure of the parent window would look like:
LRESULT CALLBACK ParentProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (wParam)
{
if ((LOWORD(wParam) == Edit Identifier)&&(HIWORD(wParam) == EN_CHANGE))
{
//check spelling
}
}
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
As I said above, check spelling is just an example. There are other simpler things (processing) to do, which you will discover. Note how uMsg and its WM_COMMAND have been coded, from the parameter list to the switch statement, in the parent procedure. The notification message is ultimately sent to the procedure of the parent window by the system, not your code. All you have to do is to handle it in the parent procedure with a CASE statement as illustrated above.
In the code, Edit Identifier will have to be replaced with an integer (used in creating the control). Note how the low word of wParam and the high word of wParam were accessed. Note how EN_CHANGE was used.
We shall now have a list of notification code and corresponding action from the user that gives rise to the code.
EN_ERRSPACE: The edit control cannot allocate enough memory to meet a specific request.
EN_HSCROLL: The user has clicked the edit control's horizontal scroll bar. The system sends this notification code before updating the screen.
EN_KILLFOCUS: Focus on the current control is lost because the user has selected another control.
EN_MAXTEXT: While inserting text, the user has exceeded the specified number of characters for the edit control. So insertion has been truncated. This notification code is also sent either when an edit control does not have the ES_AUTOHSCROLL style and the number of characters to be inserted exceeds the width of the edit control or when an edit control does not have the ES_AUTOVSCROLL style and the total number of lines to be inserted exceeds the height of the edit control.
EN_SETFOCUS: The user has selected this edit control, which has gained focus.
EN_UPDATE: The user has modified the text in the edit control and the system is about to display the new text. The system sends this notification code after formatting the text, but before displaying it, so that the application can resize the edit control window. The action here is opposite in timing to that of EN_CHANGE.
EN_VSCROLL: The user has clicked the edit control's vertical scroll bar or has scrolled the mouse wheel over the edit control. The system sends this notification code before updating the screen.
That is it for this part of the series. We stop here and continue in the next part.
Chrys
Related Courses
C++ CourseRelational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem
NEXT