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
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
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.
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...
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
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.
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.
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.
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...
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.
<ols...@sbcglobal.net> wrote in message
news:9396c1a1-66d7-4c9c...@l33g2000pri.googlegroups.com...
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
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.
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.
What does this mean? "this" pointer will give you the view itself? I
dont understand what you are trying to do.
--
Ajay
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.
<ols...@sbcglobal.net> wrote in message
news:ed33ce81-2f6a-4213...@n33g2000pri.googlegroups.com...
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.
The OOP paradigm is polymorphism, not switch.
--
David Wilkinson
Visual C++ MVP
What do you mean by this? Are you saying my code will not be elegant
if I use switch instead of creating another class?
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...
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
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.
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
>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
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
>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
****
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
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
>