How do you programatically instantiate a new MIDI child window?
I have looked for threads on programatically starting a new MIDI child window (from the Doc class) without success, although I seem to recall seeing something in this forum.
Anyway, Ive tried:
1 - OnNewDocument();
2 - CDocument::OnNewDocument();
3 -
CMainFrame *mf = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CRuntimeClass* pCRTC = mf->GetRuntimeClass()
CMIDIChildWnd* pChild = mf->CreateNewChild(pCRTC, IDR_DBITYPE);
pChild->ShowWindow(SW_SHOW);
None of these work and the 3rd option wont compile because it doesnt recognize the CMIDIChildWnd type (even though the ChildFrm.h header is included).
Can someone please help me with this problem. Thanks.
Mike
[755 byte] By [
Mike Pliam] at [2007-11-18 20:30:02]

# 1 Re: How do you programatically instantiate a new MIDI child window?
You need to get the proper doc template (that you registed in your apps InitInstance function). Then, just call:
// The params are:
// filename to open, if you have one
// show the opened/new doc
CMyDoc *pNewDoc = (CMyDoc *)pMyDocTemplate->OpenDocumentFile(NULL, TRUE);
CWinApp does have an 'OpenDocumentFile' function as well, however if you have an MDI app, you'll need to pass it a filename (otherwise, I assume it pops up a dialog for the user to choose what type of new document they want).
Viggy
# 2 Re: How do you programatically instantiate a new MIDI child window?
MrViggy,
Your code seems to work nicely, except for one problem:
void CMyDoc::Load(char * filepath)
{
//...
// Get the info stuff here
// open a new document
CDocTemplate *pDocTemplate = GetDocTemplate();
pDocTemplate->OpenDocumentFile(NULL);
//...
// update the new child view with the info
}
At first, I couldnt seem to update the new child window with the info. Just got blank windows. But when I eliminated my own cumbersome 'update' stuff, and simply changed some parameters in the OpenDocumentFile function call, it seems to work pretty well. (Still some bugs, but I dont think theyre directly related.)
For anyone that wants to know:
// open a new document
CDocTemplate *pDocTemplate = GetDocTemplate();
pDocTemplate->OpenDocumentFile(csTBPath, 1);
where csTBPath is the file pathname and 1 is the boolean for show the window which otherwise defaults to 0.
Thanks for your kind help.
Mike