From: FHDB on
I need a view class for outputting lines of text, in vertical sequence, as if
separated by carriage returns. It would be nice if the class could be
serialized as a text document.

A brief description of the app: It is a physical simulation. In one or more
windows, physical values are represented in false color. I have coded a
feature by which the user can click on a false color map in one window, to
cause another view class (not yet written), attached to a separate window, to
write the numerical values at the click point to that other window.

I could manually code to write into text boxes in a CScrollView, but this
would not provide a serializable document. I'm hoping to find some code that
can be reused.

Suggestions? TIA
From: Joseph M. Newcomer on
(a) why does it have to be "serializable"?
(b) why do you think writing
for(int i = 0; i < listbox.GetCount(); i++)
{
CString s;
listbox.GetText(i, s);
f.WriteString(s);
f.WriteString(_T("\n"));
}
represents an insurmountable challenge? This code is trivially reusable, because it takes
so little time to write. It is easily invertible; you can write
while(!f.ReadString(s))
listbox.AddString(s);
======
I think you are getting hung up on serialization, instead of saying "I want to be able to
read and write the data". Or maybe you just want to write it, which is even simpler. Or
maybe you want to edit it, which does not suggest that CScrollView is a good approach at
all. Instead of asking "how can I serialize my data", which assumes a solution, ask the
real question, which is probably "how can I capture data and display it reasonably, and
then write that captured data to a file?" Having a CSCrollView display it is certainly a
possibility, but it is not the best choice because now you have to handle the scrolling
yourself, the OnDraw yourself, and the serialization yourself (which would look like
CString s;
edit.GetWindowText(s);
ar << s;
which is admittedly simpler than the loop, but everything else is more complex. Using a
ListBox, your scrollling code looks like this:

and your display code looks like this:

so all that's left to do is the output loop shown above.

Note that you would not "write it into text boxes in a CSCrollView" but simply "write it
into a listbox in a CFormView", which is even simpler. It is a common beginner error to
think that the only valid representation of text is an edit control. Even if you need an
editable line, it is not necessarily a good choice (for example, you can use a CListCtrl
and the edit-in-place feature, or a grid control, either of which might be a better
choice, depending on what you want to do with the data once it is displayed). But you
didn't ask how to solve your problem; you assumed that the only possible solution was a
CScrollView and the only possible way to write out the data was serialization. There
could be a dozen other, probably better, solutions, if only we knew what problem(s) you
need to solve.

Edit controls are serializable. Rather trivially. But they are probably not the best
choice for displaying your data. Using your own hand-written CScrollView will create a
reusable view of data that probably didn't need to be written at all.
joe
On Fri, 11 Sep 2009 23:00:01 -0700, FHDB <FHDB(a)discussions.microsoft.com> wrote:

>I need a view class for outputting lines of text, in vertical sequence, as if
>separated by carriage returns. It would be nice if the class could be
>serialized as a text document.
>
>A brief description of the app: It is a physical simulation. In one or more
>windows, physical values are represented in false color. I have coded a
>feature by which the user can click on a false color map in one window, to
>cause another view class (not yet written), attached to a separate window, to
>write the numerical values at the click point to that other window.
>
>I could manually code to write into text boxes in a CScrollView, but this
>would not provide a serializable document. I'm hoping to find some code that
>can be reused.
>
>Suggestions? TIA
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Tom Serface on
Just to add to Joe's comments...

If it were me I'd use a standardized format (like XML) for persisting the
data as well. It will make the file larger in the long run, but much more
readable and transferrable between programs and systems. If you are just
storing lines to populate an edit control you could probably get away with
just storing each line in a text file (really simple), but I'd make the file
Unicode or UTF-8 so, in the future, if you want to add other languages to
the paradigm it is easier. If you use UTF-8 and English it will effectively
be the same as ANSI in size anyway.

Tom

"FHDB" <FHDB(a)discussions.microsoft.com> wrote in message
news:7C2C8A17-4D51-412B-A994-EDD3F15DDFB8(a)microsoft.com...
>I need a view class for outputting lines of text, in vertical sequence, as
>if
> separated by carriage returns. It would be nice if the class could be
> serialized as a text document.
>
> A brief description of the app: It is a physical simulation. In one or
> more
> windows, physical values are represented in false color. I have coded a
> feature by which the user can click on a false color map in one window, to
> cause another view class (not yet written), attached to a separate window,
> to
> write the numerical values at the click point to that other window.
>
> I could manually code to write into text boxes in a CScrollView, but this
> would not provide a serializable document. I'm hoping to find some code
> that
> can be reused.
>
> Suggestions? TIA

 | 
Pages: 1
Prev: _set_se_translator
Next: CRepeatButton