Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SDI w/multiple simultaneous views?

119 views
Skip to first unread message

ols...@sbcglobal.net

unread,
Dec 10, 2008, 3:01:34 AM12/10/08
to
I know this Q has come up before, but I haven't been able to find the
answer applicable to my situation.

I have a working SDI doc/view pgm which I want to modify so it
displays several views of the same document simultaneously. The
display should be in the form of independent windows arrangeable and
resizable, such as MDI provides for multiple documents.

When the user opens a document, all of the views will appear at once,
tiled or cascaded according to a user-set preference. The data is read-
only; the user does not change it or have the ability to save it.

Splitter windows are not appropriate, because there are more than 4
windows, and they are of greatly differing sizes.

Is there a simple way I can modify my SDI (VS6 under XP) so it behaves
as desired? Or is there a way to modify the MDI version so it only
allows a single document to be open, while automatically displaying
multiple views?

Thanks for your assistance

David Lowndes

unread,
Dec 10, 2008, 3:32:13 AM12/10/08
to
>I have a working SDI doc/view pgm which I want to modify so it
>displays several views of the same document simultaneously. The
>display should be in the form of independent windows arrangeable and
>resizable, such as MDI provides for multiple documents.

Perhaps the VSWAP sample may help:

"VSWAP32 demonstrates methods of switching between multiple views on a
single document in a single-document interface (SDI) application.
VSWAP32 displays two form views and a normal view that displays the
list of data collected in the two form views.
"

Dave

Daniel James

unread,
Dec 10, 2008, 4:55:11 AM12/10/08
to
In article
news:<25880f02-32ef-4216...@v5g2000prm.googlegroups.com>

, Ols...@sbcglobal.net wrote:
> I have a working SDI doc/view pgm which I want to modify so it
> displays several views of the same document simultaneously. The
> display should be in the form of independent windows arrangeable and
> resizable, such as MDI provides for multiple documents.

The best/easiest way to achieve that is to write your app as an MDI app
with multiple view types but only one document type. MFC's SDI classes
don't easily support simultaneous views.

> When the user opens a document, all of the views will appear at once,

Override the document's OnOpen to create multiple views (of whatever
flavours you like).

> Or is there a way to modify the MDI version so it only
> allows a single document to be open, while automatically displaying
> multiple views?

The magic is all in the DocTemplates that you define. If you only
define one document type you will only have one document type.

Cheers,
Daniel.

AliR (VC++ MVP)

unread,
Dec 10, 2008, 10:46:08 AM12/10/08
to
As Daniel pointed out, your best bet is to switch to a MDI application, and
then create new views passing in the pointer of the document that the
original view is using.

This post here should help you get started.
http://groups.google.com/group/microsoft.public.vc.mfc.docview/browse_thread/thread/26b7ea0ef2959a9a/67e04f827b32641a?lnk=gst&q=Multiple+views+per+document#67e04f827b32641a
And Somemore:
http://www.gamedev.net/community/forums/topic.asp?topic_id=131372


This is also a good read on what you can and cannot do with doc/view
http://msdn.microsoft.com/en-us/library/0dyc0e53.aspx


AliR.


<ols...@sbcglobal.net> wrote in message
news:25880f02-32ef-4216...@v5g2000prm.googlegroups.com...

Ajay Kalra

unread,
Dec 10, 2008, 11:27:30 AM12/10/08
to

As already been pointed out, just move to MDI. SDI doesnt make a whole
lot of sense in cases like this. As a rule of thumb, always go to MDI
by default.

--
Ajay

ols...@sbcglobal.net

unread,
Dec 10, 2008, 2:20:21 PM12/10/08
to
On Dec 10, 12:32 am, David Lowndes <Dav...@example.invalid> wrote:
> "VSWAP32 demonstrates methods of switching between multiple views on a
> single document in a single-document interface (SDI) application.

I need the views to be visible in separate windows simultaneously.
Switching views is trivial, since I just have my OnDraw function
display the view I want.

ols...@sbcglobal.net

unread,
Dec 10, 2008, 2:22:46 PM12/10/08
to
On Dec 10, 1:55 am, Daniel James <wastebas...@nospam.aaisp.org> wrote:
> The best/easiest way to achieve that is to write your app as an MDI app
> with multiple view types but only one document type.

My problem with MDI is that it allows the user to open more than one
doc, and this is not acceptable.

> Override the document's OnOpen to create multiple views (of whatever
> flavours you like).

That looks like part of the soln.

> The magic is all in the DocTemplates that you define. If you only
> define one document type you will only have one document type.

There is only one doc type, but I also have to restrict number open to
one.

ols...@sbcglobal.net

unread,
Dec 10, 2008, 2:24:31 PM12/10/08
to
On Dec 10, 7:46 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
> As Daniel pointed out, your best bet is to switch to a MDI application, and
> then create new views passing in the pointer of the document that the
> original view is using.

Need to have only single doc open at once. So if the user does Open,
the current doc closes and new one opens.

> This post here should help you get started.http://groups.google.com/group/microsoft.public.vc.mfc.docview/browse...
> And Somemore:http://www.gamedev.net/community/forums/topic.asp?topic_id=131372

I will check these posts; the third I already saw.

AliR (VC++ MVP)

unread,
Dec 10, 2008, 2:23:46 PM12/10/08
to
Or use this to actually switch the view object.

http://www.codeguru.com/cpp/w-d/doc_view/viewmanagement/article.php/c3341

AliR.


<ols...@sbcglobal.net> wrote in message
news:de66307a-8372-47c9...@w39g2000prb.googlegroups.com...

ols...@sbcglobal.net

unread,
Dec 10, 2008, 2:26:43 PM12/10/08
to
On Dec 10, 8:27 am, Ajay Kalra <ajayka...@yahoo.com> wrote:
> As already been pointed out, just move to MDI. SDI doesnt make a whole
> lot of sense in cases like this. As a rule of thumb, always go to MDI
> by default.

In my particular situation, I cannot allow user to open more than one
doc. The reasons are complicated, but that is why I didn't use MDI. I
need the logic of SDI with respect to documents, and the screen layout
of MDI.

AliR (VC++ MVP)

unread,
Dec 10, 2008, 2:26:17 PM12/10/08
to
That won't be a problem. You can reistrict the app to only one open doc.
You will have to catch the open menu item, and if there is one already open
close it (ask to save changes).

AliR.

<ols...@sbcglobal.net> wrote in message
news:9396c1a1-66d7-4c9c...@l33g2000pri.googlegroups.com...

Ajay Kalra

unread,
Dec 10, 2008, 2:58:40 PM12/10/08
to
On Dec 10, 2:26 pm, ols6...@sbcglobal.net wrote:
> On Dec 10, 8:27 am, Ajay Kalra <ajayka...@yahoo.com> wrote:
>
> > As already been pointed out, just move to MDI. SDI doesnt make a whole
> > lot of sense in cases like this. As a rule of thumb, always go to MDI
> > by default.
>
> In my particular situation, I cannot allow user to open more than one
> doc.

That can be done with MDI as well. You can restrict thru menu and/or
create more views on the one document itself. For example,
CreateNewFrame will create another view on the document.

--
Ajay

ols...@sbcglobal.net

unread,
Dec 11, 2008, 2:23:01 AM12/11/08
to
OK, I have successfully created multiple views on opening a new
document, using the following (from one of the links above):

void CAnalyzeDoc::CreateAdditionalView(char viewName[])
{
CMDIFrameWnd* pMainFrame = reinterpret_cast<CMDIFrameWnd*>
(AfxGetMainWnd());
CMDIChildWnd* pActiveChild = pMainFrame->MDIGetActive();
CDocTemplate* pTemplate = GetDocTemplate();
CFrameWnd* pFrame = pTemplate->CreateNewFrame(this,
pActiveChild);


pTemplate->InitialUpdateFrame(pFrame, this);
pActiveChild = pMainFrame->MDIGetActive();
CView* pView = pActiveChild->GetActiveView();
}

This is called multiple times from OnNewDocument to create extra
views, and it works.
Now I need to title each view differently. At the moment, each view is
titled [doc name]:n, where n=1,2,... . I need to display my own title.
SetWindowText and SetTitle apparently do nothing.

In the OnDraw, I need to know which view window I am drawing. I
suppose there is some way to determine that, but it would be most
convenient if I could set (or get) an ID number when I create the view.

ols...@sbcglobal.net

unread,
Dec 11, 2008, 2:38:25 AM12/11/08
to
I found out how to set the title, in MS "How to change an MFC-Based
MDI Child Window's Frame Text", Article 99182 (hard to find because
they don't use "title" in their title!). Now I just need to know how
to tell which view I have in the view's OnDraw function.

Daniel James

unread,
Dec 11, 2008, 8:50:00 AM12/11/08
to
In article
news:<a21a825f-91da-4063...@b38g2000prf.googlegroups.com

>, Ols...@sbcglobal.net wrote:
> My problem with MDI is that it allows the user to open more than one
> doc, and this is not acceptable.

The framework supports it, but you don't ave to allow it in your app.
Just have OnOpen fail if a document is already open.

Cheers,
Daniel.

Ajay Kalra

unread,
Dec 11, 2008, 9:51:06 AM12/11/08
to

What does this mean? "this" pointer will give you the view itself? I
dont understand what you are trying to do.

--
Ajay


AliR (VC++ MVP)

unread,
Dec 11, 2008, 10:47:33 AM12/11/08
to
What I would do is have a different view class that does the different
things. If they have something in common then they can all inherit from a
base class which encapsulates all the common functionality.

And when you want to create a new view of a certain type then you simply
tell that particular doc template to create a its view using your doc.

If you need a sample project let me know.

AliR.

<ols...@sbcglobal.net> wrote in message
news:3fd4a14f-51bb-458a...@w24g2000prd.googlegroups.com...

AliR (VC++ MVP)

unread,
Dec 11, 2008, 10:48:06 AM12/11/08
to
Why are you creating the same exact view again?

AliR.

<ols...@sbcglobal.net> wrote in message
news:ed33ce81-2f6a-4213...@n33g2000pri.googlegroups.com...

ols...@sbcglobal.net

unread,
Dec 11, 2008, 2:40:36 PM12/11/08
to
On Dec 11, 7:48 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
> Why are you creating the same exact view again?

The document contains data. The various views display the same data in
different ways. I have one OnDraw function, one view class, and one
document type. I suppose I could create different view classes
somehow, but that seems like overkill. Much simpler is to just have a
switch in OnDraw, and one view class.

David Wilkinson

unread,
Dec 11, 2008, 3:02:30 PM12/11/08
to

The OOP paradigm is polymorphism, not switch.

--
David Wilkinson
Visual C++ MVP

ols...@sbcglobal.net

unread,
Dec 11, 2008, 3:56:55 PM12/11/08
to
On Dec 11, 12:02 pm, David Wilkinson <no-re...@effisols.com> wrote:
> The OOP paradigm is polymorphism, not switch.

What do you mean by this? Are you saying my code will not be elegant
if I use switch instead of creating another class?

AliR (VC++ MVP)

unread,
Dec 11, 2008, 4:03:19 PM12/11/08
to
By OOP standards, I would have to say no.

By creating seperate classes you are killing two birds with one stone, first
you will know exactly what you have to draw in that view, and second it will
be good oop design.

Think of this way, if you have 100 different drawings, would you want a case
statement with 100 entries and 100 functions inside of one class or 100
different classes?


AliR.


<ols...@sbcglobal.net> wrote in message
news:cb296539-803a-463d...@f40g2000pri.googlegroups.com...

Ajay Kalra

unread,
Dec 11, 2008, 4:28:24 PM12/11/08
to

I would create a base class for your view and let each specific type
of view override OnDraw and any other view specific behavior. I would
not do it in one class. It defeats the purpose .

--
Ajay

ols...@sbcglobal.net

unread,
Dec 12, 2008, 1:09:05 AM12/12/08
to
On Dec 11, 1:28 pm, Ajay Kalra <ajayka...@yahoo.com> wrote:
> I would create a base class for your view and let each specific type
> of view override OnDraw and any other view specific behavior. I would
> not do it in one class. It defeats the purpose .

I'm not sure what "purpose" you're referring to. There is not even any
point in having one class; it's just MFC is set up to do things that
way.

So I will find another way to distinguish which view is being called
for.

Ajay Kalra

unread,
Dec 12, 2008, 9:04:02 AM12/12/08
to
On Dec 12, 1:09 am, ols6...@sbcglobal.net wrote:
> On Dec 11, 1:28 pm, Ajay Kalra <ajayka...@yahoo.com> wrote:
>
> > I would create a base class for your view and let each specific type
> > of view override OnDraw and any other view specific behavior. I would
> > not do it in one class. It defeats the purpose .
>
> I'm not sure what "purpose" you're referring to.

What I mean is you are not really using OOP at all. Its like using a
new technology to retrofit something obsolete because you have to. You
should have distinct view classes with possibly a common base class.

> There is not even any
> point in having one class;

But I thought you did have one class and then using a switch statement
to differentiate view types.

--
Ajay

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:31:40 AM12/14/08
to
See below...

On Wed, 10 Dec 2008 11:22:46 -0800 (PST), ols...@sbcglobal.net wrote:

>On Dec 10, 1:55 am, Daniel James <wastebas...@nospam.aaisp.org> wrote:
>> The best/easiest way to achieve that is to write your app as an MDI app
>> with multiple view types but only one document type.
>
>My problem with MDI is that it allows the user to open more than one
>doc, and this is not acceptable.

****
Why in the world would you call this "not acceptable"? MDI only does this by default; you
can always override what is going on and prohibit this, which is a whole lot easier than
trying to simulate MDI on your own.
****


>
>> Override the document's OnOpen to create multiple views (of whatever
>> flavours you like).
>
>That looks like part of the soln.
>
>> The magic is all in the DocTemplates that you define. If you only
>> define one document type you will only have one document type.
>
>There is only one doc type, but I also have to restrict number open to
>one.

****
So, restrict it. Why is this considered difficult?
joe
****
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:32:47 AM12/14/08
to
That is because you didn't understand that you can override the open handler to do what
you want. So you have made the wrong assumption, which has led you to reject the best
solution for the wrong reasons.
joe

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:35:36 AM12/14/08
to
That's right, because by default MFC manages the title. If you set the PreCreateWindow
handler to clear the FWS_ADDTOTITLE flag, it will allow you to manage the caption
yourself.

In the OnDraw handler, the way you know what window you are drawing is because you put
something in the window class to indicate what window you are drawing, and it would always
be inappropriate to do this by looking at the title (it is called "localization" and you
can't depend on the localized string in the caption). If you want an ID number, you would
set it at the point where you create that view.
joe

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:38:12 AM12/14/08
to
See below...

On Thu, 11 Dec 2008 11:40:36 -0800 (PST), ols...@sbcglobal.net wrote:

>On Dec 11, 7:48 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
>> Why are you creating the same exact view again?
>
>The document contains data. The various views display the same data in
>different ways. I have one OnDraw function, one view class, and one
>document type. I suppose I could create different view classes
>somehow, but that seems like overkill.

****
No, that is the EXPECTED way you will handle the problem! A good remedial course in
object-oriented programming might be appropriate at this point.
****


>Much simpler is to just have a
>switch in OnDraw, and one view class.

****
This is actually considered extremely poor style in object-oriented programming. In fact,
it is usually a dead giveway that is used by many of us to identify extremely poor design.
joe
****

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:39:15 AM12/14/08
to
I'm saying I would think it would be complete crap. In cases like you are describing, the
use of a switch statement is considered a newbie mistake.
joe

Joseph M. Newcomer

unread,
Dec 14, 2008, 1:50:08 AM12/14/08
to
No, it is not MFC, it is C++, and it is called "object oriented programming", and it is
considered the modern state-of-the-art. switch statements are, for such purposes,
considered the identifying mark of amateurs and programming wannabes. People who learned
C in 1975 and never outgrew it. One step beyond the computed-goto-statement of FORTRAN.

Of course, if you LIKE writing code that looks like it was written in the 1970s, feel
free, but it is going to be an overly complicated kludge for which the word "elegance" is
not only not in the ballpark, it is barely in the same galaxy.

In case you haven't heard, there is this little mechanism called "inheritance" that can be
used so common code can be in the parent class and specific code for each view is in the
subclass. The "purpose" is to use object-oriented programming for the purposes for which
it was created, to provide abstractions, commonality, and in general solve programming
problems by using mechanisms which are extensible.

Bottom line: you are making an exceptionally poor choice of implementation strategy, based
upon some bizarre notions of how to program that have been obsolete for probably twenty
years in the mainstream and longer in research environments (we were using OO languages in
the early 1970s in university environments, and the first really good one was called
"Simula-67" because it was designed in 1967, which is 41 years ago. But why should you
update your programming methodology just because it is a good idea to use state-of-the-art
programming techniques? If the switch statement [the computed GOTO of FORTRAN] was good
enough for John Backus in 1955, it should be good enough today...).
joe

RainMan

unread,
Dec 17, 2008, 9:46:44 AM12/17/08
to
I would suggest looking at two articles of mine:

http://www.codeguru.com/cpp/controls/controls/tabcontrols/article.php/c13085/
http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c13161/

--
RainMan


"ols...@sbcglobal.net" wrote:

> I know this Q has come up before, but I haven't been able to find the
> answer applicable to my situation.
>
> I have a working SDI doc/view pgm which I want to modify so it
> displays several views of the same document simultaneously. The
> display should be in the form of independent windows arrangeable and
> resizable, such as MDI provides for multiple documents.
>
> When the user opens a document, all of the views will appear at once,
> tiled or cascaded according to a user-set preference. The data is read-
> only; the user does not change it or have the ability to save it.
>
> Splitter windows are not appropriate, because there are more than 4
> windows, and they are of greatly differing sizes.
>
> Is there a simple way I can modify my SDI (VS6 under XP) so it behaves
> as desired? Or is there a way to modify the MDI version so it only
> allows a single document to be open, while automatically displaying
> multiple views?
>
> Thanks for your assistance
>

0 new messages