Reg - Edit Box
-
Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,
CString str1 = "Some String";
GetDlgItemText(IDC_EDIT1, str);
str2 = str+str1;
SetDlgItemText(IDC_EDIT1, str2);Please tell me is there any otherway....
G.Paulraj
-
Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,
CString str1 = "Some String";
GetDlgItemText(IDC_EDIT1, str);
str2 = str+str1;
SetDlgItemText(IDC_EDIT1, str2);Please tell me is there any otherway....
G.Paulraj
You can try EM_REPLACESEL message. CString cs; GetDlgItemText(IDC_EDIT1, cs); SendDlgItemMessage(IDC_EDIT1, EM_SETSEL, cs.GetLength(), cs.GetLength()); SendDlgItemMessage(IDC_EDIT1, EM_REPLACESEL, 0, (LPARAM)_T("Some String"));
modified on Wednesday, December 23, 2009 5:34 AM
-
Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,
CString str1 = "Some String";
GetDlgItemText(IDC_EDIT1, str);
str2 = str+str1;
SetDlgItemText(IDC_EDIT1, str2);Please tell me is there any otherway....
G.Paulraj
Use a control type member variable for the edit control. Then do something like
m_Edit.GetWindowText(szTemp );
szTemp += _T("Whatever");
m_Edit.SetWindowText(szTemp);“Follow your bliss.” – Joseph Campbell
-
You can try EM_REPLACESEL message. CString cs; GetDlgItemText(IDC_EDIT1, cs); SendDlgItemMessage(IDC_EDIT1, EM_SETSEL, cs.GetLength(), cs.GetLength()); SendDlgItemMessage(IDC_EDIT1, EM_REPLACESEL, 0, (LPARAM)_T("Some String"));
modified on Wednesday, December 23, 2009 5:34 AM
Good suggestion. :)
“Follow your bliss.” – Joseph Campbell
-
Good suggestion. :)
“Follow your bliss.” – Joseph Campbell
Thank you! :)
-
Thank you! :)
OK you modified that post. While I thought the
EM_REPLACESEL
itself was a great idea, I wouldn't have liked the usage ofGetDlgItem()
call. But hey, different people, different ways. (why I don't likeGetDlgItem()
? Because I'm a terrific fan of Dr. Joseph Newcomer, and his philosophies and I take 'em seriously). Added: Look at my second answer to the OP. :)“Follow your bliss.” – Joseph Campbell
modified on Wednesday, December 23, 2009 5:48 AM
-
Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,
CString str1 = "Some String";
GetDlgItemText(IDC_EDIT1, str);
str2 = str+str1;
SetDlgItemText(IDC_EDIT1, str2);Please tell me is there any otherway....
G.Paulraj
Hi, You might want to try this (thanks to Rejeesh for his
EM_REPLACESEL
suggestion, which triggered this idea)int len = m_Edit.GetWindowTextLength(); //find the length of text in the control
m_Edit.SetSel(len, len, 0); //select nothing (but the cursor goes to the end)
m_Edit.ReplaceSel(szNewText); //new text will be printed at the end now!“Follow your bliss.” – Joseph Campbell
-
OK you modified that post. While I thought the
EM_REPLACESEL
itself was a great idea, I wouldn't have liked the usage ofGetDlgItem()
call. But hey, different people, different ways. (why I don't likeGetDlgItem()
? Because I'm a terrific fan of Dr. Joseph Newcomer, and his philosophies and I take 'em seriously). Added: Look at my second answer to the OP. :)“Follow your bliss.” – Joseph Campbell
modified on Wednesday, December 23, 2009 5:48 AM
Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV. I thought I would provide an answer which resembles the sample code segment in the post :). Thanks for the comment.
-
Hi, You might want to try this (thanks to Rejeesh for his
EM_REPLACESEL
suggestion, which triggered this idea)int len = m_Edit.GetWindowTextLength(); //find the length of text in the control
m_Edit.SetSel(len, len, 0); //select nothing (but the cursor goes to the end)
m_Edit.ReplaceSel(szNewText); //new text will be printed at the end now!“Follow your bliss.” – Joseph Campbell
This is the MFC way. Now the code looks cleaner :)
-
This is the MFC way. Now the code looks cleaner :)
-
Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV. I thought I would provide an answer which resembles the sample code segment in the post :). Thanks for the comment.
Rejeesh.T.S wrote:
Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV.
You do realize, of course, that DDX_ macros internally call GetDlgItem? Newcomer's screed on the subject overlooks that fact. It really comes down to personal preference in coding style; one way is no more evil than another. Personally I try to avoid MFC-specific API's where possible - it makes porting code between frameworks a little less painful.
L u n a t i c F r i n g e