这个不会错吧,我把这里换成另外一个模板就没问题了
CTableDoc* m_pDoc;
CDMSApp* pApp = (CDMSApp*)AfxGetApp();
pApp->tablename.Format("%s",tablename);
pApp->m_pConn=m_pConn;
m_pDoc=(CTableDoc*)(pApp->m_pTableDocTemplate->OpenDocumentFile(NULL));
m_pDoc->SetTitle(tablename);下面是app initinstanceBOOL CDMSApp::InitInstance()
{ { // BLOCK: doc template registration
// Register the document template.  Document templates serve
// as the connection between documents, frame windows and views.
// Attach this form to another document or frame window by changing
// the document or frame class in the constructor below.
m_pTreeDocTemplate = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDMSDoc), // document class
RUNTIME_CLASS(CMDIChildWnd), // frame class
RUNTIME_CLASS(CTableSelectView)); // view class
AddDocTemplate(m_pTreeDocTemplate);
}
{ // BLOCK: doc template registration
// Register the document template.  Document templates serve
// as the connection between documents, frame windows and views.
// Attach this form to another document or frame window by changing
// the document or frame class in the constructor below.
m_pTableDocTemplate = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTableDoc), // document class
RUNTIME_CLASS(CNewChildFrame), // frame class
RUNTIME_CLASS(CTableView)); // view class
AddDocTemplate(m_pTableDocTemplate);
} AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
//  serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_DMSTYPE,
RUNTIME_CLASS(CDMSDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDMSView));
AddDocTemplate(pDocTemplate); // create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// 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(); return TRUE;
}实在想不通有什么问题
我是多文档模式的啊
前面用m_pTreeDocTemplate 新建了一个文档,然后想在此基础上用m_pTableDocTemplate 创建一个,结果出错了,如果仍然建m_pTreeDocTemplate 就对的
请问为什么?谢谢

解决方案 »

  1.   

    调试,再重试,是到这里出错
    void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
    {
    ASSERT(::IsWindow(m_hWnd)); if (m_pCtrlSite == NULL)
    ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
    else
    m_pCtrlSite->MoveWindow(x, y, nWidth, nHeight, bRepaint);
    }
      

  2.   

    最后定位在第一句:ASSERT(::IsWindow(m_hWnd));
      

  3.   

    CWnd::MoveWindow(int 0, int 0, int 480, int 280, int 1) line 279 + 36 bytes
    CTableView::OnSize(unsigned int 0, int 480, int 300) line 124
    CWnd::OnWndMsg(unsigned int 5, unsigned int 0, long 19661280, long * 0x0012e00c) line 1845
    CWnd::WindowProc(unsigned int 5, unsigned int 0, long 19661280) line 1585 + 30 bytes
    AfxCallWndProc(CWnd * 0x00443950 {CTableView hWnd=???}, HWND__ * 0x002a0ed6, unsigned int 5, unsigned int 0, long 19661280) line 215 + 26 bytes
    AfxWndProc(HWND__ * 0x002a0ed6, unsigned int 5, unsigned int 0, long 19661280) line 368
    AfxWndProcBase(HWND__ * 0x002a0ed6, unsigned int 5, unsigned int 0, long 19661280) line 220 + 21 bytes
    USER32! 77d18734()
    USER32! 77d18816()
    USER32! 77d1b4c0()
    USER32! 77d1b50c()
    NTDLL! 7c92eae3()
    USER32! 77d242e9()
    USER32! 77d24704()
    USER32! 77d39b0b()
    CWnd::CreateDlgIndirect(const DLGTEMPLATE * 0x001f7008, CWnd * 0x00443ad0 {CNewChildFrame hWnd=???}, HINSTANCE__ * 0x00400000) line 327 + 36 bytes
    CWnd::CreateDlg(const char * 0x00000066, CWnd * 0x00443ad0 {CNewChildFrame hWnd=???}) line 238 + 20 bytes
    CFormView::Create(const char * 0x00000000, const char * 0x00000000, unsigned long 1350565888, const tagRECT & {top=0 bottom=0 left=0 right=0}, CWnd * 0x00443ad0 {CNewChildFrame hWnd=???}, unsigned int 59648, CCreateContext * 0x0012f61c) line 88 + 19 bytes
    CFrameWnd::CreateView(CCreateContext * 0x0012f61c, unsigned int 59648) line 594 + 49 bytes
    CFrameWnd::OnCreateClient(tagCREATESTRUCTA * 0x0012ece8, CCreateContext * 0x0012f61c) line 615 + 17 bytes
    CFrameWnd::OnCreateHelper(tagCREATESTRUCTA * 0x0012ece8, CCreateContext * 0x0012f61c) line 633 + 22 bytes
    CMDIChildWnd::OnCreate(tagCREATESTRUCTA * 0x0012ece8) line 1050
    CWnd::OnWndMsg(unsigned int 1, unsigned int 0, long 1240296, long * 0x0012eac4) line 1811 + 13 bytes
    CWnd::WindowProc(unsigned int 1, unsigned int 0, long 1240296) line 1585 + 30 bytes
    AfxCallWndProc(CWnd * 0x00443ad0 {CNewChildFrame hWnd=???}, HWND__ * 0x00920ed2, unsigned int 1, unsigned int 0, long 1240296) line 215 + 26 bytes
    AfxWndProc(HWND__ * 0x00920ed2, unsigned int 1, unsigned int 0, long 1240296) line 368
    AfxWndProcBase(HWND__ * 0x00920ed2, unsigned int 1, unsigned int 0, long 1240296) line 220 + 21 bytes
    USER32! 77d18734()
    USER32! 77d1d05b()
    USER32! 77d1b4c0()
    USER32! 77d1f9fe()
    NTDLL! 7c92eae3()
    USER32! 77d1fecc()
    USER32! 77d1ff66()
    USER32! 77d30643()
    USER32! 77d4f74b()
    USER32! 77d18734()
    USER32! 77d18816()
    USER32! 77d1b4c0()
    USER32! 77d587b5()
    NTDLL! 7c92eae3()
    USER32! 77d2f3cc()
    CMDIChildWnd::Create(const char * 0x00142c38, const char * 0x004431fc, unsigned long 1087340544, const tagRECT & {top=-2147483648 bottom=0 left=-2147483648 right=0}, CMDIFrameWnd * 0x00441110 {CMainFrame hWnd=???}, CCreateContext * 0x0012f61c) line 557 + 27 bytes
    CMDIChildWnd::LoadFrame(unsigned int 128, unsigned long 1087340544, CWnd * 0x00000000 {CWnd hWnd=???}, CCreateContext * 0x0012f61c) line 629 + 57 bytes
    CDocTemplate::CreateNewFrame(CDocument * 0x00443eb0 {CTableDoc}, CFrameWnd * 0x00000000 {CFrameWnd hWnd=???}) line 279 + 32 bytes
    CMultiDocTemplate::OpenDocumentFile(const char * 0x00000000, int 1) line 128 + 17 bytes
    CTableSelectView::OnButtonBrowse() line 144 + 32 bytes这个是吗?最下面就是产生那个事件的开始处
      

  4.   

    我知道是OpenDocumentFile这里错,可是我实在不知道错在哪里。。