Summary of Edit control usage in VC

Source: Internet
Author: User

The Class Wizard allows you to generate two kinds of member variables, one for the CString type and one for the CEdit type.
The CString type member variable is recommended for use in programs when you simply get the content of the edit control or set simple content.
Example:
CString M_stredit;
Get edit box content
UpdateData (TRUE);
At this point, M_stredit is the string variable of the edit box content.
To update the edit, just assign a value to the M_stredit and then
Updatadata (false);//
If some of the complex operations on the edit box are suggested with the CEdit type.
Example:
CEdit M_ctrledit;
Move the cursor to the beginning
M_ctrledit.setsel (0,0);
Move the cursor to the end
M_ctrledit.setsel (-1);
Select All content
M_ctrledit.setsel (0,-1);
Write value
M_ctrledit.replacesel ("Replacement content");
Gets the number of characters in the current edit box
int Istart,icount;//icount is the number of characters
M_ctrledit.setsel (0,-1);
M_ctrledit.getsel (istart,icount); it can also be manipulated directly with the ID value of the control
Example:
((cedit*) GetDlgItem (Idc_edit)
He is similar to the m_ctrledit above
The benefit of this writing is that it can be used in message passing to facilitate the transfer of edit content between different windows.
For example: The following message in the response function
Seteditcontent (WPARAM WPARAM, LPARAM LPARAM)
Idc_edit can be passed through wparam recently, while the word nginx content can be passed directly through LPARAM recently
CString msg= "message to be delivered";
:: SendMessage (M_hparent,wm_sendmsg_edit, (WPARAM) Idc_edit, (LPARAM) (LPSTR) (LPCTSTR) MSG)
Such as:
((cedit*) GetDlgItem (WPARAM))->setsel (-1);
((cedit*) GetDlgItem (WPARAM))->replacesel ((LPCSTR) LPARAM); VC Edit frame (edit) automatic line wrapping and automatic scrolling
 

After many tests, summed up the VC editing box (edit) automatic line-wrapping and automatic scrolling method.

method One: (when edit is mapped to a CString)
m_string = m_string + snewstring + "\ r \ n"//Auto-wrap
UpdateData (FALSE);

This method can only be wrapped automatically, not automatically scrolling to the last line.

method Two: (when edit is mapped to an edit)
M_edit.setsel (-1,-1); Auto Roll Screen
M_edit.replacesel (snewstring+ "\ r \ n"); Wrap Line
UpdateData (TRUE);

This method can be used to wrap and automatically scroll to the last line.

Above, M_string, M_edit. The member variable to add to the edit box, respectively, snewstring the string to display
Note the difference between the updatadata parameters in the two method.
I found that modifying the properties of the edit box: Auto_hscroll is not very useful.

Summary of Edit control usage in VC

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.