首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

pApp->InitInstance()里的有关问题

2012-06-17 
pApp-InitInstance()里的问题深入浅出MFC,关于程序流程里InitInstance函数,它说的是由于CMainFrame* pMai

pApp->InitInstance()里的问题
深入浅出MFC,关于程序流程里InitInstance函数,它说的是由于CMainFrame* pMainFrame = new CMainFrame;
构造一个对象,然后引起其基类CFrameWnd()构造函数调用Create函数,可是我在CFrameWnd()也没看见有Create函数啊
另外如果是单文档的话,也没有在InitInstance里看见new一个对象出来啊。。下面是构造函数CFrameWnd()

CFrameWnd::CFrameWnd()
{
ASSERT(m_hWnd == NULL);

m_nWindow = -1; // unknown window ID
m_bAutoMenuEnable = TRUE; // auto enable on by default
m_lpfnCloseProc = NULL;
m_hMenuDefault = NULL;
m_hAccelTable = NULL;
m_nIDHelp = 0;
m_nIDTracking = 0;
m_nIDLastMessage = 0;
m_pViewActive = NULL;

m_cModalStack = 0; // initialize modality support
m_phWndDisable = NULL;
m_pNotifyHook = NULL;
m_hMenuAlt = NULL;
m_nIdleFlags = 0; // no idle work at start
m_rectBorder.SetRectEmpty();

m_bHelpMode = HELP_INACTIVE; // not in Shift+F1 help mode
m_dwPromptContext = 0;

m_pNextFrameWnd = NULL; // not in list yet

m_bInRecalcLayout = FALSE;
m_pFloatingFrameClass = NULL;
m_nShowDelay = -1; // no delay pending

AddFrameWnd();
}

[解决办法]
应该是LoadFrame那里根据文档模板创建的
[解决办法]
深入浅出MFC中的代码是对实际代码的模拟.
实际代码如下:
1.if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;

2.BOOL CMDIFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
{
if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
pParentWnd, pContext))
return FALSE;

......
}

3.BOOL CFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
{
......
if (!Create(lpszClass, lpszTitle, dwDefaultStyle, rectDefault,
pParentWnd, MAKEINTRESOURCE(nIDResource), 0L, pContext))
{
return FALSE; // will self destruct on failure normally
}

......
}

4.BOOL CFrameWnd::Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
LPCTSTR lpszMenuName,
DWORD dwExStyle,
CCreateContext* pContext)
{
......
if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle,
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext))
{
TRACE0("Warning: failed to create CFrameWnd.\n");
if (hMenu != NULL)
DestroyMenu(hMenu);
return FALSE;
}

return TRUE;
}

5.BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
......

HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);

}

6.int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

......
}

7.int CFrameWnd::OnCreate(LPCREATESTRUCT lpcs)
{
CCreateContext* pContext = (CCreateContext*)lpcs->lpCreateParams;
return OnCreateHelper(lpcs, pContext);
}

8.int CFrameWnd::OnCreateHelper(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
......
if (!OnCreateClient(lpcs, pContext))
{
TRACE0("Failed to create client pane/view for frame.\n");
return -1;
}
......
}

9.BOOL CMDIFrameWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*)


{
......

return CreateClient(lpcs, pMenu);
}


[解决办法]
同意楼上的,看了一下代码:
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
应该是在LoadFrame中进行了资源的处理比如说菜单什么的.

热点排行