15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Debug output using CEditView

Mark Foley -- meftech@concentric.net
Sunday, March 09, 1997

Environment: VC++ 1.52c, Win NT 3.51

I have a simple Server application which at some point will be made
into a Service. I wanted a way to display some periodic status info
on the app View window, similar to a console window. I am using a
CEditView now and that works, but it's kind of clumbsy.

I write new info to the view by getting the current text and
strcat'ing the new text and then doing a SetWindowText(). This
works but...

I can't seem to move the Cursor to the end of the line. It is always
at the start.

The CEditView has a maximum size, such that eventually my SetWindowText
will have too much info. 

What's the best way to implement a scrollable output window for 
status information, similar to the debug output windows. I don't
want to use the debug output window itself, it must be part
of the apps frame. Also, it must be able to run as a Service.


Any ideas appreciated...



Pesce Roberto -- roberto.pesce@elsag.it
Tuesday, March 11, 1997

[Mini-digest: 4 responses]

Environment: VC++ 4.0, Win NT 3.51

Hi,

I had the same problem to display a scrolling feedback to the user about
an app I developed; I looked in the VC samples and found this code piece
to position the cursor at the end of the messages :

void CEditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
CString line;

               line = "Test Message";

	   line = line + _T("\r\n");
	   int len = GetWindowTextLength();
  	   
  	   GetEditCtrl().SetSel(len,len);					   
	   GetEditCtrl().ReplaceSel(LPCTSTR(line));
}

This works on VC++ 4.0... don't know about VC++ 1.52

Hope this helps

bye

Roberto Pesce
Roberto.Pesce@elsag.it

-----From: Mark Johnson 

Environment: VC++ 4.2-flat, NT 4.0

I don't have any suggestion for your other questions, but for setting
the cursor
maybe you could try "void SetSel( DWORD dwSelection, BOOL bNoScroll =
FALSE );"

try setting both the hi and lo word of the DWORD param to the length of
the current
text in the CEditView control.





>----------
>From: 	meftech[SMTP:meftech@concentric.net]
>Sent: 	Sunday, March 09, 1997 11:57 AM
>To: 	mfc-l@netcom.com
>Subject: 	Debug output using CEditView
>
>Environment: VC++ 1.52c, Win NT 3.51
>
>I have a simple Server application which at some point will be made
>into a Service. I wanted a way to display some periodic status info
>on the app View window, similar to a console window. I am using a
>CEditView now and that works, but it's kind of clumbsy.
>
>I write new info to the view by getting the current text and
>strcat'ing the new text and then doing a SetWindowText(). This
>works but...
>
>I can't seem to move the Cursor to the end of the line. It is always
>at the start.
>
>The CEditView has a maximum size, such that eventually my SetWindowText
>will have too much info. 
>
>What's the best way to implement a scrollable output window for 
>status information, similar to the debug output windows. I don't
>want to use the debug output window itself, it must be part
>of the apps frame. Also, it must be able to run as a Service.
>
>
>Any ideas appreciated...
>
-----From: Regis NICOLAS 

At 09:57 AM 3/9/97 -0800, you wrote:
>Environment: VC++ 1.52c, Win NT 3.51
>
>I have a simple Server application which at some point will be made
>into a Service. I wanted a way to display some periodic status info
>on the app View window, similar to a console window. I am using a
>CEditView now and that works, but it's kind of clumbsy.
>
>I write new info to the view by getting the current text and
>strcat'ing the new text and then doing a SetWindowText(). This
>works but...
>
>I can't seem to move the Cursor to the end of the line. It is always
>at the start.
>
>The CEditView has a maximum size, such that eventually my SetWindowText
>will have too much info. 
>
>What's the best way to implement a scrollable output window for 
>status information, similar to the debug output windows. I don't
>want to use the debug output window itself, it must be part
>of the apps frame. Also, it must be able to run as a Service.
>
>
>Any ideas appreciated...
>
>
I did it. CEditView is scrollable of course.
You can use CEditView::GetEditCtrl() to get the underlying edit control and
then to work with it.
See what I did:
OnAddText is called to handle a WM_USER message WM_ADDTEXT posted by
another thread. LPARAM is a pointer to a CString allocated by the caller
and that must be deleted here.
A lot of staff is done to prevent scrolling the window is the user moved
the caret inside of it. In fact the window is scrolled only if the caret is
at the end of the window. You can see the value 131072 in the code that
means than the text will not exceed 128K. (Take care that you cannot store
more than 1MB in a CEditView: See ViewEdit.cpp)

// ---------------------------------------------------------------------------
LRESULT CAutoMailView::OnAddText(WPARAM aWP, LPARAM aLP)
{
	CString* theString = (CString*)aLP;
	CEdit& theEdit = GetEditCtrl();
	int theSelStart, theSelEnd, theLen = theEdit.GetWindowTextLength();
	
	theEdit.SetRedraw(FALSE);
	theEdit.GetSel(theSelStart, theSelEnd);
	BOOL thefMove = (theSelStart == theSelEnd && theSelStart == theLen);
	if (theLen > 131072)
	{
		thefMove = TRUE;
		theEdit.SetSel(0, theLen, TRUE);
	}
	else
		theEdit.SetSel(theLen, theLen, TRUE);

	theEdit.ReplaceSel(*theString);
	delete theString;

	if (thefMove)
	{
		theSelStart = theSelEnd = theEdit.GetWindowTextLength();
		theEdit.SetRedraw(TRUE);
	}
		
	theEdit.SetSel(theSelStart, theSelEnd);
	if (!thefMove)
	{
		theEdit.SetRedraw(TRUE);
		theEdit.Invalidate();
	}

	return 0;
}

Hope this helps...
Let me know if you get a problem...
Regis


------------------------------
Regis NICOLAS -    R&D Windows
Smartcode Technologie

mailto:nicolas@smartcode.fr
http://www.smartcode.fr/
http://www.smartcodesoft.com/
Tel.: (33) (0)4 67 59 30 16

-----From: Yun Chang 

meftech wrote:
> 
> Environment: VC++ 1.52c, Win NT 3.51
> 
> I have a simple Server application which at some point will be made
> into a Service. I wanted a way to display some periodic status info
> on the app View window, similar to a console window. I am using a
> CEditView now and that works, but it's kind of clumbsy.
> 
> I write new info to the view by getting the current text and
> strcat'ing the new text and then doing a SetWindowText(). This
> works but...
> 
> I can't seem to move the Cursor to the end of the line. It is always
> at the start.

Call SetSel(maxlength, maxlength);

> 
> The CEditView has a maximum size, such that eventually my SetWindowText
> will have too much info.

You have delete one line at a time like output debug window.
Under NT, you can use the virtual memory if you do not want
the memory limitation.


> 
> What's the best way to implement a scrollable output window for
> status information, similar to the debug output windows. I don't
> want to use the debug output window itself, it must be part
> of the apps frame. Also, it must be able to run as a Service.
> 
> Any ideas appreciated...



Mike Kurtinitis -- moosh@halcyon.com
Monday, March 17, 1997

Environment: VC++ 1.52c, Win NT 3.51
>
>I have a simple Server application which at some point will be made
>into a Service. I wanted a way to display some periodic status info
>on the app View window, similar to a console window. I am using a
>CEditView now and that works, but it's kind of clumbsy.
>
>I write new info to the view by getting the current text and
>strcat'ing the new text and then doing a SetWindowText(). This
>works but...
>
>I can't seem to move the Cursor to the end of the line. It is always
>at the start.
>
>The CEditView has a maximum size, such that eventually my SetWindowText
>will have too much info. 
>
>What's the best way to implement a scrollable output window for 
>status information, similar to the debug output windows. I don't
>want to use the debug output window itself, it must be part
>of the apps frame. Also, it must be able to run as a Service.
>
>
>Any ideas appreciated...

The following code snaps the cursor to the end of the text before appending
any new text. Note the "add return" boolean which may or may not suit your
needs. To get a carriage return to appear correctly in the view both a
carriage return and line-feed are necessary.

void CSomeEditView::Report(CString sStatus, BOOL bAddReturn)
{
	CString sLocal(sStatus);

	if (bAddReturn)
		sLocal += "\r\n"; // Need both escapes IN THAT ORDER
	GetEditCtrl().SetSel(32767, 32767);	// Moves the cursor to the end
	GetEditCtrl().ReplaceSel(sLocal);
}

Cheers,

Mike Kurtinitis
Mooshwerks
moosh@halcyon.com





Become an MFC-L member | Вернуться в корень Архива |