Extend your windows standard controls

Source: Internet
Author: User

Extend your windows standard controls
Author: shellex
Www.shellex.cn & blog.csdn.net/shellex is copyrighted.

Standard controls mean that their default functions and expressiveness are limited. For example, when you click the Edit Control
The Edit Control (which is also a form) that acts as a child form will receive messages such as wm_lbuttonup and wm_lbuttondown,
However, it does not send related notifications to the parent form. That is to say, when we process the wm_command message
In the edit notification, check whether the edit button has been clicked.
The following are notifications supported by standard edit, which will be placed in the high-byte wparam.
Wm_lbuttonup or similar messages.

En_change: the user has modified text in an edit control. Windows updates the display before sending this message (unlike en_update ).
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. Windows sends this message before updating the screen.
En_killfocus: the user has selected another control.
En_maxtext: while inserting text, the user has exceeded the specified number of characters for the Edit Control. insertion has been truncated. this message 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 the Edit Control.
En_setfocus: the user has selected this edit control.
En_update: the user has altered the text in the edit control and Windows is about to display the new text. windows sends this message after formatting the text, but before displaying it, so that the application can resize the edit control window.
En_vscroll: the user has clicked the Edit Control's vertical scroll bar. Windows sends this message before updating the screen.

To respond to the edit click event, you only need to subclass edit.
Define the message processing process of edit. There are two related functions:
Long getwindowlong (

Hwnd, // handle of window
Int nindex // offset of value to retrieve
);

Long setwindowlong (

Hwnd, // handle of window
Int nindex, // offset of value to set
Long dwnewlong // New Value
);
The former can obtain information about the form, and the latter can set several attributes of the form. Includes callback functions for processing messages.
For more information about function parameters, see msdn. The specific implementation is as follows.
First, create a dialog box-based Win32 GUI project, in the corresponding wm_initdialog message function
Write the following code in main_oninitdialog:

//////////////////////////////////////// ////////////////////////////////////////

// Obtain the original edit message processing callback function. The last parameter uses gwl_wndproc.
Oldeditprocaddr = getwindowlong (getdlgitem (hwnd, idc_edit_process), gwl_wndproc );
// Subclass Edit to en_lbuttonup notifications.
Setwindowlong (getdlgitem (hwnd, idc_edit_process), gwl_wndproc, (long) _ neweditproc );

//////////////////////////////////////// ////////////////////////////////////////

En_lbuttonup is a custom constant, Which is wm_user + 101, and idc_edit_process is an edit
Control ID. Hwnd is the handle of the parent form. _ Neweditproc is a callback function written by myself, which will be sent to edit later
The message is sent to _ neweditproc for processing.
The code for the _ neweditproc function is as follows:

//////////////////////////////////////// ////////////////////////////////////////
Lresult callback _ neweditproc (hwnd, uint umsg, wparam, lparam ){
// If you left the mouse button on edit
If (wm_lbuttonup = umsg ){
// Place the Edit ID in the lower-byte field of wparam, And the custom response notification in the higher-byte field.
Wparam Wp = makewparam (idc_edit_process, en_lbuttonup );
// Put the edit handle in lparam
Lparam Lp = (lparam) hwnd;
Combine the message and send it to the parent form as wm_command.
Sendmessage (getparent (hwnd), wm_command, WP, LP );
}
// Other messages are processed by the default processing function.
Return callwindowproc (wndproc) oldeditprocaddr, hwnd, umsg, wparam, lparam );
}
//////////////////////////////////////// ////////////////////////////////////////

Now, in the message loop of the main form, you can easily get the notification by clicking the mouse:

//////////////////////////////////////// ////////////////////////////////////////
Void main_oncommand (hwnd, int ID, hwnd hwndctl, uint codenostrap ){
Switch (ID ){
Case idc_edit_process:
If (codenoencode = en_lbuttonup)
Main_oneditprocess_click (hwnd, ID, hwndctl, codenoworkflow );
Break;
Default: break;
}
}
//////////////////////////////////////// ////////////////////////////////////////

You can easily implement the functions you want to implement in the main_oneditprocess_click function. :)
Www.shellex.cn & blog.csdn.net/shellex is copyrighted.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.