Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to show operator data 1

Status
Not open for further replies.

tmoody

Technical User
Oct 8, 2001
37
0
0
US
Sorry for the first year question, but I searched to forum and couldn't find an answer. I need to display test results(CString) to a user in my dialog based app. I would just like to have a simple window, with a vertical scroll bar, so the operator can scroll back looking at the results. This will be for verbosity to the operator. The test results will always be shown in a seperate area as pass or fail, so secondarily, it would be nice to have a "hide and unhide" button to bring this window up, but I first need to know how to display the data.
Thanks in advance
Tim Moody
 
Create a mulitiline edit control and it sounds like you might want to use "readonly" as well.

Then if your using MFC use the Class Wizard create a CEdit "control" variable mapped to the edit control.

Then when you want to append data use CEdit::SetSel() to set the selection to the end of the data then CEdit::ReplaceSel() to append the new data to the end.

-pete
 
Thanks, I'll give it a try, but I am still a little confused. The documentation for SetSel and ReplaceSel looks like it is for selecting or higlighting the text in an edit box. I just want to dump text into it and have the user be able to scroll back and lok at it.

Tim Moody
 
Normally I would set a line of text in a Static Text Box like this:
CWnd* pWnd;
CString TestString;
pWnd = GetDlgItem(IDC_TESTTEXT);
pWnd->SetWindowText(TestString);

But if I do this, only the last line is displayed.
CWnd* pWnd;
CString TestString;
CString TestString1;
CString TestString2;
CString TestString3;
pWnd = GetDlgItem(IDC_TESTTEXT);
pWnd->SetWindowText(TestString1);
pWnd->SetWindowText(TestString2);
pWnd->SetWindowText(TestString3);

So not fully understanding things, I did this and it didn't work:
CWnd* pWnd;
CEdit* myEdit;
CString TestString;
CString TestString1;
CString TestString2;
CString TestString3;
pWnd = GetDlgItem(IDC_TESTTEXT);
myEdit->SetSel(-1, FALSE);
myEdit->ReplaceSel(TestString, FALSE);
myEdit->SetSel(-1, FALSE);
myEdit->ReplaceSel(TestString1, FALSE);
myEdit->SetSel(-1, FALSE);
myEdit->ReplaceSel(TestString2, FALSE);
myEdit->SetSel(-1, FALSE);
myEdit->ReplaceSel(TestString3, FALSE);
So as you can see, I me and Bill are not getting along right now, and since this is such a simple problem, I feel there must be a smple solution.

I hope we'll all laughing lack of MFC knowledge.

Thanks
Tim Moody
 
If you just have a single string of text to display then SetWindowText will work. It replaces whatever was previously in the window with whatever you supply as the parameter. The description I provided was how to append data over time. That was how I interpreted your post.

Here is a small excerpt of code from an application that does just that. The code uses a local CString variable “slog” and a CEdit member variable “m_log” that is mapped to the Edit Control on the dialog as described in my first post.

Code:
slog.Format("Setting Timer to: %s", dtNow.Format());
m_log.SetSel( m_log.GetWindowTextLength(), m_log.GetWindowTextLength());
m_log.ReplaceSel( slog);

-pete
 
Pete,

Thanks, got it.

Tim Moody
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top