|
-
April 27th, 1999, 09:37 PM
#1
for an MDI application, how can I have 2 separate and distinct child areas popup
I created a MDI application. When I execute the program, how can
I have 2 separate and distinct child areas popup in the beginning of
the program?
I am going to have 2 functions calls to ...Create(WS_CHILD | WS_VISIBLE ...
and I need to change WS_CHILD to something, but what?
I am in desperate need of help. I have searched everywhere. Please, any
response anyone can give me will be greatly appreciated.
-
April 28th, 1999, 03:10 AM
#2
Re: for an MDI application, how can I have 2 separate and distinct child areas popup
I'm not quite sure what you mean - do you want something like this when the app starts:
+--------------------------------+
| MDI Frame window |
+--------------------------------+
| |
| +------------+ +------------+ |
| | MDI Child | | MDI Child | |
| +------------+ +------------+ |
| | | | | |
| | | | | |
| | | | | |
| +------------+ +------------+ |
| |
+--------------------------------+
I.e., two MDI child windows open to begin with instead of just the one?
If this is the case, in your app's InitInstance() method, AFTER the main MDI frame has been shown with ShowWindow() and UpdateWindow(), call your CMultiDocTemplate's CreateNewFrame() and InitialUpdateFrame() methods, something like this:
---
BOOL CMyMDIApp::InitInstance()
{
BOOL bMaximised ;
CFrameWnd *pWndFirstChild, *pWndSecondChild ;
.
.
.
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
// Create a second frame immediately. If you want it to have the same
// document as the first (two views of the same document), you should
// get hold of this document's pointer and pass it instead of NULL as
// the parameters to the doc template methods.
pWndFirstChild = pMainFrame->MDIGetActive();
pWndSecondChild = pDocTemplate->CreateNewFrame(NULL, pWndFirstChild);
pDocTemplate->InitialUpdateFrame(pWndSecondChild, NULL, TRUE);
return TRUE;
}
---
Does this help?
-
April 28th, 1999, 07:20 AM
#3
Re: for an MDI application, how can I have 2 separate and distinct child areas popup
When I add that code, 2 windows pop-up, both blank. How can I print
text on one window and print different text on the other window? My
OnDraw() function looks like the following
void TextEditView::OnDraw(CDC* pDC)
{
pDC->TextOut(10,10,"window1");
}
I don't know how to get pDC to point to the first window
and later, pDC to point to the other window?
-
April 28th, 1999, 08:40 AM
#4
Re: for an MDI application, how can I have 2 separate and distinct child areas popup
In proper doc-view architecture, each view draws its own data, whether it be from the same document or from different documents. Therefore, if you want two different views of the same data then you should define two different view classes and add the second to your multi doc template as well. This, however, becomes tricky because when the MFC tries to create a new view, it does not know which to use and therefore asks the user at run time. Aaaarrgggghhh!
There are two ways round this: (1) Create a second multidoc template within your app, the second having the second type of view in it, and then use this second template to create the second child frame. I'm not sure how well this will work if you create a new child frame based on a frame with a different view class, though. (2) Use different document classes and CDocument's SetTitle() and GetTitle() methods to distinguish between the two in your OnDraw() method.
Don't forget that OnDraw() is called once for each view (= each child frame), so the DC swaps between the two each time it is called. You ARE getting both DCs alternately as your code currently stands. The two multi doc template / view classes combo would help separate the two OnDraw() functions, as they would be from different classes and so each class can use different code, even if they share the same document.
I ought to point out that if you intend to have two views every time you start a new document or load one, the fix I gave will not work, because it is done manually after the first frame is loaded and so only occurs at startup; you would have to call CreateNewFrame() and InitialUpdateFrame() from within OnNewDocument() instead - if both views share the same document, then this method will work OK as it only gets called once.
If this has confused you, e-mail me at [email protected] and I will try to get a demo running for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|