请到这里看一下:
http://expert.csdn.net/Expert/topic/2487/2487008.xml?temp=.880932

解决方案 »

  1.   

    你用单步跟踪一下就可以看清楚了,首先程序进入的你的这个CMainFrame中的PreCreateWindow()函数,当程序运行到return语句时又调用了基类CFrameWnd类的PreCreateWindow函数,所以这个函数调用了两次,你在TRACE宏中硬性的写上了TRACE("\nCMinFrame::PreCreateWindow ...
    所以从你的输出结果上看是调用了两次CMainFrame::PreCreateWindow()
      

  2.   

    经过调试可以发现PreCreateWindow被调用了两次,以下是两次执行时Call stack中的内容, 
        第一次: 
        CMainFrame::PreCreateWindow() line 81 
        CFrameWnd::GetIconWndClass() line 666 
        CFrameWnd::LoadFrame() line 692 + 16 bytes 
        CDocTemplate::CreateNewFrame() line 279 + 32 bytes 
        CSingleDocTemplate::OpenDocumentFile() line 132 + 17 bytes 
        CDocManager::OnFileNew() line 829 
        CWinApp::OnFileNew() line 29 
        _AfxDispatchCmdMsg() line 88 
        CCmdTarget::OnCmdMsg() line 302 + 39 bytes 
        CWinApp::ProcessShellCommand() line 31 + 30 bytes 
        CTestApp::InitInstance() line 88 + 12 bytes 
        AfxWinMain() line 39 + 11 bytes 
        WinMain() line 30 
        WinMainCRTStartup() line 330 + 54 bytes 
        KERNEL32! bff8b86c() 
        KERNEL32! bff8b71e() 
        KERNEL32! bff8a0e1() 
        第二次: 
        CMainFrame::PreCreateWindow() line 81 
        CWnd::CreateEx() line 685 + 15 bytes 
        CFrameWnd::Create() line 564 + 79 bytes 
        CFrameWnd::LoadFrame() line 695 + 45 bytes 
        CDocTemplate::CreateNewFrame() line 279 + 32 bytes 
        CSingleDocTemplate::OpenDocumentFile() line 132 + 17 bytes 
        CDocManager::OnFileNew() line 829 
        CWinApp::OnFileNew() line 29 
        _AfxDispatchCmdMsg() line 88 
        CCmdTarget::OnCmdMsg() line 302 + 39 bytes 
        CWinApp::ProcessShellCommand() line 31 + 30 bytes 
        CTestApp::InitInstance() line 88 + 12 bytes 
        AfxWinMain() line 39 + 11 bytes 
        WinMain() line 30 
        WinMainCRTStartup() line 330 + 54 bytes 
        KERNEL32! bff8b86c() 
        KERNEL32! bff8b71e() 
        KERNEL32! bff8a0e1()