Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Multiple Views 1

Status
Not open for further replies.

sparafucile17

Programmer
Apr 5, 2002
40
0
0
US
I have a MDI that I would like to use with multiple views. For the most part the views will be CFormViews. What I'd like my app to do is to load a different view for each menu item.

In my app, I have a Menu titled "Membership". Under this menu I have two items: Add New, View All. I want each item to launch it's own specific CFormView as a child window. There will be a DB thread running all the time to add/view the data, so I'm not really concerned about using any documents at this time. (perhaps later for reporting...)

I found the way to add multiple view to my app similar to the following method (MSDN Example):

m_pBookViewTemplate = new CMultiDocTemplate(IDR_BOOKFRAME,
RUNTIME_CLASS(CChkBookDoc),
RUNTIME_CLASS(CCheckBookFrame),
RUNTIME_CLASS(CBookView));
AddDocTemplate(m_pBookViewTemplate);

m_pCheckViewTemplate = new CMultiDocTemplate(IDR_CHECKFRAME,
RUNTIME_CLASS(CChkBookDoc),
RUNTIME_CLASS(CCheckBookFrame),
RUNTIME_CLASS(CCheckView));
AddDocTemplate(m_pCheckViewTemplate);


But here's the catch: It always loads a dialog box that makes you select which view you want! But I already know what view I want, because the user already selected it by choosing the appropriate menu item!

Is there anyway to bypass this view-selection dialog? Or other suggestion for how to use multiple views? Any help would be greatly appreciated.

Jeff
 
>> It always loads a dialog box that makes you select which view you want!

What dialog box? I don't beleive i have ever seen that.

-pete
 
The Dialog is AFX_IDD_NEWTYPEDLG. Apparently, if there is only one CDocTemplate the CWinApp::OnFileNew will create a new doucment of that type using it's associated view.

However, when there are multiple CDocTemplate's the CWinApp::OnFileNew will prompt the user with the dialog listed above and force them to select which document type to use.

In my case I'm really not so concerned about selecting documents, I just want a bunch of CFormViews floating around as child windows. Really, if I could just find a way to launch Views directly (not using framework calls) as child windows, thats all I really like to do. But adding multiple CDocTemplate's seems to be the only way to accomplish this?

Or is it?

Thanks,
Jeff
 
>> But adding multiple CDocTemplate's seems to be the only way to accomplish this?

umm... no, you can add views to the existing template


-pete
 
Ok...

How do you add views to existing templates? Is there a member function of CMultiDocTemplate that can be used to add views? Or something else?

Also, when the view is added to the MDI, how do you launch it?

Thanks for the help so far,
Jeff
 
Opps sorry, AddView() is a member of CDocument, there is sample code for multiple views in the SDK of CDocument::AddView()

-pete
 
Hello, I have my own MDI question, but at least this solution I do know.

In the CWinApp derived class InitInstance there are some lines

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if(!ProcessShellCommand(cmdInfo)
....

Take out those lines. The ProcessShellCommand will call OpenDocumentFile of the CMulitDocTemplate class and if cmdInfo is empty (in this case it is), then the dialog box will show up. Instead, before the LoadFrame of the MainFrame write in

m_pBookViewTemplate->OpenDocumentFile(NULL);
m_pCheckViewTemplate->OpenDocumentFile(NULL);

The will be no more dialog box.

The AddDocTemplate does not create the view, it adds the information to the DocTemplate list.

My question is sort of related. It involves adding views to the view list. I will post a new thread.
 
Kudos, pdunncs!

That definitley did the trick! :) I probably wasted about 20 hours reading other methods and this was the quickest and easiest way! You definitely earned that star!

But on a side note, using this method above.... How would you control the view after using:

m_pBookViewTemplate->OpenDocumentFile(NULL);

Basically, how would how you control the view placement, size, window name (i.e text at the top of child view) ? I think that this would have been originally controlled via the CFormView inherited class: CBookView (could be wrong though)

Does CMultiDocTemplate have member function to do this? Or do I have to invoke another class to control these aspects of each child window?

Thx
Jeff
 
I am sorry, I just now looked at this.

In the following code the Frame windows will set the size of the frame that the view will be in.

So one would be Frame1 with a specific size and another frame2
m_pBookViewTemplate = new CMultiDocTemplate(IDR_BOOKFRAME,
RUNTIME_CLASS(CChkBookDoc),
RUNTIME_CLASS(CFrame1),
RUNTIME_CLASS(CBookView));
AddDocTemplate(m_pBookViewTemplate);

m_pCheckViewTemplate = new CMultiDocTemplate(IDR_CHECKFRAME,
RUNTIME_CLASS(CChkBookDoc),
RUNTIME_CLASS(CFrame2),
RUNTIME_CLASS(CCheckView));
AddDocTemplate(m_pCheckViewTemplate);

In the frame classes, they are inherited from CMDIChildWnd.

here is one of my frames, write this in the PreCreateWindow of your frame class


BOOL CProgFrame::preCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIChildWnd::preCreateWindow(cs) )
return FALSE;

cs.style = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP;


// Size the width of the window to 1/3 screen size
cs.cy = (GetSystemMetrics(SM_CYSCREEN)/ 1.17) / 2;
cs.cx = ::GetSystemMetrics(SM_CXSCREEN) * .3;

//offset to the top right
cs.y = 0; //((cs.cy * 3) - cs.cy) / 2;
cs.x = GetSystemMetrics(SM_CXSCREEN) * .7;

return TRUE;
}

Thanks for the star, it was my first reply ever.

I don't know about the name of the child window though, sorry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top