Board index » Visual Studio » document - view

document - view

Visual Studio199
In an MFC, MDI, document-view application, is it possible to close all the

views on a document and keep the document open? If so, how would I go about

opening a new view on a document when I need to? If so, is the default

doc-view app setup by the new project wizard supposed to allow it? If not,

is there a workaround, like an invisible window?



Is there something like a OnCloseView() that I could override to hide the

view rather than close it if it is the last one? I looked but couldn't find

this. I could add an entry in the View menu to unhide the view.



Also, whenever I execute the application, a blank document and view are

opened by default. Is there any way to prevent this? I looked in the code in

my project and did not find a call to OnNewDocument() or anything like that,

so it must be buried somewhere inside MFC or the OS.



Any suggestion?


-
 

Re:document - view

Can't answer all your queries (not sure why you need the document to stay

open, it can be reloaded very easily using

CWinApp::OpenDocumentFile(filename)), but here's some.



Quote
If so, how would I go about

opening a new view on a document when I need to?

On an existing document, or a new blank doc based on a doc template?

The former I've never done, but CFrameWnd::Create(..., CCreateContext*)

where the CCreateContext's m_pCurrentDoc or m_pLastView may be a starting

point.

The latter can be done by create a new frame from the doc template - it will

open a new view:

CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument, NULL);

pTemplate->InitialUpdateFrame(pFrame, pDocument);





Quote
Also, whenever I execute the application, a blank document and view are

opened by default. Is there any way to prevent this?

In InitInstance(), after the CCommandLineInfo is created but before it's

parsed, set:

cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;



-AS-

-

Re:document - view

Hi Bill,



I've never tried to do this (I.E., my programs always have a view open), but

here's my two cents. You can process information in the document and not

show it on the view until you are ready. In the view's OnUpdate() routine

you cau use hints from the document to tell the view how to handle the

information...



"Bill Brehm>" <<don't want any spam>wrote in message

Quote
In an MFC, MDI, document-view application, is it possible to close all the

views on a document and keep the document open? If so, how would I go

about

opening a new view on a document when I need to? If so, is the default

doc-view app setup by the new project wizard supposed to allow it? If not,

is there a workaround, like an invisible window?



You can close any window, but you will wantto remove (RemoveView) any views

from the document's view list when you close it just so the document object

knows it is gone. The document and view work well together, but I don't

think the document needs a view to exist. You could create a new view and

use AddView to assign it to a document just about any time or you can assign

a document to the view when a view is created. It would be more trouble to

have a view without a document since the view relies on the document for

it's data t display (in the typical model).



Quote
Is there something like a OnCloseView() that I could override to hide the

view rather than close it if it is the last one? I looked but couldn't

find

this. I could add an entry in the View menu to unhide the view.



You can use ShowWindow(SW_HIDE) on the frame window the frame or you could

simply minimize it as well.



Quote
Also, whenever I execute the application, a blank document and view are

opened by default. Is there any way to prevent this? I looked in the code

in

my project and did not find a call to OnNewDocument() or anything like

that,

so it must be buried somewhere inside MFC or the OS.



Add the folloing line to the InitInstance of the application:



cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;



After the CCommandLineInfo object is created:



CCommandLineInfo cmdInfo;



And before the ParseCommandLine() function is called:



ParseCommandLine(cmdInfo);



This will replace the default behavior (CCommandLineInfo::FileNew) and a new

document will not be created. This is also handy when you have more than

one document type and you don't want to display the little dialog that asks

the user what kind of document to open.



HTH,



Tom





-

Re:document - view

My document is more than the data in a file. The data in the file is

configuration data abuo tthe document. But the document is a video stream

from a frame grabber card. That is why I want the document to stay open even

if I am hiding a view, so the video stream can still be processed.



This line [cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;] solved

that problem.



I'll need more time to experiment with your other suggestions.



"ASmall" <ASmall@discussions.microsoft.com>wrote in message

Quote
Can't answer all your queries (not sure why you need the document to stay

open, it can be reloaded very easily using

CWinApp::OpenDocumentFile(filename)), but here's some.



>If so, how would I go about

>opening a new view on a document when I need to?

On an existing document, or a new blank doc based on a doc template?

The former I've never done, but CFrameWnd::Create(..., CCreateContext*)

where the CCreateContext's m_pCurrentDoc or m_pLastView may be a starting

point.

The latter can be done by create a new frame from the doc template - it

will

open a new view:

CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument, NULL);

pTemplate->InitialUpdateFrame(pFrame, pDocument);





>Also, whenever I execute the application, a blank document and view are

>opened by default. Is there any way to prevent this?

In InitInstance(), after the CCommandLineInfo is created but before it's

parsed, set:

cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;



-AS-





-