c++mfccwnd

How Create derived from CWnd POP UP Window?


I created class CSurfaceWnd from CWnd by Class Wizard. I tried to create window but getting error. That's my code of creating:

    if(!m_pSurfaceWnd)
    {
        CString m_NameClass = AfxRegisterWndClass(
            CS_VREDRAW | CS_HREDRAW,
            ::LoadCursor(NULL, IDC_ARROW),
            (HBRUSH) ::GetStockObject(WHITE_BRUSH),
            ::LoadIcon(NULL, IDI_APPLICATION));
    m_pSurfaceWnd = new CSurfaceWnd;

    CRect rcTemp;
    GetWindowRect(rcTemp);

    VERIFY(m_pSurfaceWnd->CreateEx(WS_EX_CLIENTEDGE, m_NameClass, NULL, WS_POPUP | WS_VISIBLE, rcTemp, mpWnd, 1));

    //DWORD dw =GetLastError();

    m_pSurfaceWnd->ShowWindow(SW_SHOW);
}
else
    m_pSurfaceWnd->ShowWindow(SW_SHOW);

How can You see I'm creating pop up window that's why I'm using CreateEx. I have registered class and in debug mode I see a number of new class in m_NameClass. But CreateEx returned false. Please help me. Probably you will see some error that I can't see.Please Don't send me to MSDN I have read it a lot of times. Thank you


Solution

  • First of all, you have to check whether mpWnd is valid object.

    BOOL isValid = ::IsWindow(mpWnd->GetSafeHwnd());
    

    If mpWnd is invalid value, CreateEx function will return 0 because of WS_POPUP style.