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!

output to a multiline edit box

Status
Not open for further replies.

Mechy

Programmer
Sep 29, 2003
11
0
0
US
Hi Guys,

I want to get an output to a multiline edit box just like printing to the screen using cout command.

What I need to do is to get the int or float variables of an instance of a class and print them to the multiline edit box.

Let's say the class has two float variables like LX=2.0 and LY=1.0.

I need to print these to the edit box in the following format:

LX = 2
LY = 1

Can anybody help me?

Thanks.
 
Ok. Just make a generic method that just adds a line
Code:
void TheDialog::printToBox(const CString& s)
{
  CString sOut;
  theEditBox.GetWindowText(sOut);
  sOut += s + "\r\n";
}

Then, adding labeled floats is simple
Code:
void TheDialog::printToBox(const CString& label, const float& value)
{
  CString sOut;
  sOut.Format("%s = %f", label, value);
  printToBox(sOut);
}
just make a new printToBox(const CString& label, const SomeType& value) for whatever type you with to handle.
----
If you're determined to get it working like cout, ie like
myOut << &quot;LX = &quot; << 2.0 << &quot;\r\n&quot;;

you'd make a separate class that
1) holds a reference to the CEditBox (given in the constructor)
2) has a bunch of << operators and let the operators add whetever is inputted to the box (first GetWindowText then SetWindowText(resultFromGet + whatToInput)



/Per
[sub]
if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
[/sub]
 
Thanks PerFnurt,

I got it worked... :)

Mechy.
 
Great , especially since I forgot the somewhat important
Code:
theEditBox.SetWindowText(sOut);
part... :p

/Per
[sub]
if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
[/sub]
 
>If you're determined to get it working like cout, ie like

Scanned some old projects and found this:
Code:
class COut2Wnd
{
public:
	COut2Wnd(CWnd& wnd):mWnd(wnd) {}

	COut2Wnd& operator << (const CString& s)
	{
		Add(s);
		return *this;
	}

	COut2Wnd& operator << (const float& f)
	{
		CString s;
		s.Format(&quot;%f&quot;, f);
		Add(s);
		return *this;
	}

	COut2Wnd& operator << (const int& i)
	{
		CString s;
		s.Format(&quot;%i&quot;, i);
		Add(s);
		return *this;
	}

private:
	void Add(const CString& s)
	{
		CString sOut;
		mWnd.GetWindowText(sOut);
		sOut+=s;
		mWnd.SetWindowText(sOut);
	}
	COut2Wnd();
	COut2Wnd(const COut2Wnd&);

	CWnd& mWnd;
};

Usage:
Code:
  ...
  COut2Wnd o(m_SomeEditCtrl);
  o << &quot;Foo: &quot; << 42 << &quot;\r\n&quot;;
  o << &quot;Bar: &quot; << 3.14 << &quot;\r\n&quot;;


/Per
[sub]
if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top