Discussion:
plz splain the underlying mechanism of a view
(too old to reply)
Heck
2010-05-10 05:11:26 UTC
Permalink
I understand the organization and mechanisms for establishing a
buffer, filling it with structured data and then sending it along,
whether to a device or merely to a program, for, say, display or
storage or for reinterpretation. The data has to be formatted or
delimited in accordance with the requirements of my target. Fine.

When I write an MFC app, let's say without resorting to CArchive and
serialization, I have data within a CDocument and CViews of various
sorts, targets for display and reinterpretation.

So, what do CViews want, in principle? The docs I've read seem to
want me to present the CView with all the data the window could
possibly show, so that a user has as complete an ability to examine
the data as he might ever want. Evidently I need to tell it how to
print the strings in its window. Giving it my buffer is not
sufficient. \n doesn't get me a newline.

Would someone please help me bridge the gap between the organization
and mechanisms of handling structured data and serving it up the way a
CView wants it?

Trying to learn a new trick, this old, cranky software developer is
getting very frustrated and irritated. Thanks.
David Lowndes
2010-05-10 07:29:48 UTC
Permalink
Post by Heck
So, what do CViews want, in principle?
The best way I've found to design what's the document and what's the
view is to consider your application as MDI even though it may not
need to be. That way you're forced to think what's essential to only a
specific view and almost everything else is common and ought to be in
the document.

Dave
Chris Becke
2010-05-10 15:04:34 UTC
Permalink
Post by David Lowndes
Post by Heck
So, what do CViews want, in principle?
The best way I've found to design what's the document and what's the
view is to consider your application as MDI even though it may not
need to be. That way you're forced to think what's essential to only a
specific view and almost everything else is common and ought to be in
the document.
I think the old, cranky, software developer wants a CView on which to
display "traditional" c/c++ program output.

i.e. How to get a CView as a kind of printf target equivalent.

In which case I would suggest deriving the CView from a CEdit. It sounds
like it should be really easy in MFC, I'm not familiar enough with it.
David Lowndes
2010-05-10 15:45:53 UTC
Permalink
Post by Chris Becke
I think the old, cranky, software developer wants a CView on which to
display "traditional" c/c++ program output.
i.e. How to get a CView as a kind of printf target equivalent.
In which case I would suggest deriving the CView from a CEdit. It sounds
like it should be really easy in MFC, I'm not familiar enough with it.
Aha, then yes, either a view derived from CEdit, or if the data is
line orientated, perhaps a list box, or even maybe a CFormView
(dialog) may be appropriate.

Dave
Heck
2010-05-11 16:19:22 UTC
Permalink
On Mon, 10 May 2010 16:45:53 +0100, David Lowndes
Post by David Lowndes
Post by Chris Becke
I think the old, cranky, software developer wants a CView on which to
display "traditional" c/c++ program output.
i.e. How to get a CView as a kind of printf target equivalent.
In which case I would suggest deriving the CView from a CEdit. It sounds
like it should be really easy in MFC, I'm not familiar enough with it.
Aha, then yes, either a view derived from CEdit, or if the data is
line orientated, perhaps a list box, or even maybe a CFormView
(dialog) may be appropriate.
Dave
I'll have a look at CFormView. In fact, I tried using a CListView,
but so far, unsuccessfully. And, to top it off, I couldn't get the
two scrollbars to appear, though I played around with
ShowScrollBar(SB_BOTH) till I was hopeless.

(You don't want to be hopeless.)

I want to make a status/debug window in my SDI app, in which I'll
output various strings in various colors, to describe the state of my
program's other operations. I want a window, not a dialog box, with
resizability, scrollbars and to be able to copy its contents to the
clipboard. So, it has the features of CEdit, CScrollView and maybe
CListView. I read multiple inheritance is problematic in MFC, so I've
avoided that. How should I concoct the class out of which I'll make
this view?

But, back to my initial, naive question, is there something like
printf() for a CView or one of its derivatives?

Thanks very much.
David Lowndes
2010-05-11 16:38:00 UTC
Permalink
Post by Heck
I want to make a status/debug window in my SDI app, in which I'll
output various strings in various colors, to describe the state of my
program's other operations.
In that case it sounds like you may need a rich edit control.
Post by Heck
I want a window, not a dialog box, with
resizability, scrollbars and to be able to copy its contents to the
clipboard. So, it has the features of CEdit, CScrollView and maybe
CListView. I read multiple inheritance is problematic in MFC, so I've
avoided that. How should I concoct the class out of which I'll make
this view?
As far as I recall, all the MFC view derived classes except for
CFormView will give you a single type of control view that meets your
visual criteria.
Post by Heck
But, back to my initial, naive question, is there something like
printf() for a CView or one of its derivatives?
If you want printf capability, you can use sprintf or wsprintf to
create the string, then move that string to the view.

Without a deeper understanding of your requirements it's difficult to
be specific. You usually just have to look at what other applications
do in similar situations and try to apply what you think works for
them.

Dave
Heck
2010-05-11 20:15:48 UTC
Permalink
On Tue, 11 May 2010 17:38:00 +0100, David Lowndes
Post by David Lowndes
Post by Heck
I want to make a status/debug window in my SDI app, in which I'll
output various strings in various colors, to describe the state of my
program's other operations.
In that case it sounds like you may need a rich edit control.
Post by Heck
I want a window, not a dialog box, with
resizability, scrollbars and to be able to copy its contents to the
clipboard. So, it has the features of CEdit, CScrollView and maybe
CListView. I read multiple inheritance is problematic in MFC, so I've
avoided that. How should I concoct the class out of which I'll make
this view?
As far as I recall, all the MFC view derived classes except for
CFormView will give you a single type of control view that meets your
visual criteria.
Post by Heck
But, back to my initial, naive question, is there something like
printf() for a CView or one of its derivatives?
If you want printf capability, you can use sprintf or wsprintf to
create the string, then move that string to the view.
Without a deeper understanding of your requirements it's difficult to
be specific. You usually just have to look at what other applications
do in similar situations and try to apply what you think works for
them.
It seemed to me also that all the classes derived from CView would
give me all I needed, but, lots wasn't evident to me, like where was
the capability to easily put text on the screen and account for the
window's RECT, with word-wrapping, scrolling and color. I see now
CEditView and CRichEditView have members that do what I need. I was
missing the easy, relatively high-level output capability.

I'll be able to use the apps and source provided on the CEditView and
CRichEditView pages, superpad and wordpad, to get over this hump.

Thanks.

Heck
2010-05-11 15:53:20 UTC
Permalink
On Mon, 10 May 2010 17:04:34 +0200, Chris Becke
Post by Chris Becke
Post by David Lowndes
Post by Heck
So, what do CViews want, in principle?
The best way I've found to design what's the document and what's the
view is to consider your application as MDI even though it may not
need to be. That way you're forced to think what's essential to only a
specific view and almost everything else is common and ought to be in
the document.
I think the old, cranky, software developer wants a CView on which to
display "traditional" c/c++ program output.
i.e. How to get a CView as a kind of printf target equivalent.
In which case I would suggest deriving the CView from a CEdit. It sounds
like it should be really easy in MFC, I'm not familiar enough with it.
Right, that's what I want. I see the functions for drawing points,
lines and arcs, but I don't understand what the general, basic text
output function is. I've managed to write strings to a CView, but the
output wasn't properly formatted and I couldn't get it into the form I
wanted. Is there something like a printf() for CViews?

So, now I'll have a look at CEdit, thanks.
Loading...