Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I created class CSurfaceWnd from CWnd by Class Wizard. I tried to create window but getting error. That's my code of creating:
C++
    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
Posted
Comments
nv3 4-Apr-13 6:20am    
Have you checked the result of AfxRegisterWndClass?
Also check that mpWnd is pointing to window that has a non-null m_hWnd.
And check that the id 1 (your last argument to CreateEx) is already being used, or simply try another id.
Ans has rcTemp some legal coordinate values in it?
thomas_wingfield 4-Apr-13 6:24am    
m_NameClass = L"Afx:00D80000:3:00010003:01900010:00010027"
rcTemp = {top=390 bottom=413 left=600 right=660}
mpWnd = 0x0045f878 {hWnd=0x001b047c {unused=??? }}
id not existed
nv3 4-Apr-13 7:03am    
I would debug into the CreateEx call and see what goes wrong.

From looking at the coordinates of mpWnd I assume that this is a child window. A child window, however, cannot be the owner of a popup window. See article:

Window Features[^]

The easiest way to solve that is to find the top-level parent of mpWnd (GetTopLevelParent) and use that in CreateEx as owner.
 
Share this answer
 
It would appear you are trying to create a child window of your mpWnd, so you should use WS_CHILD rather than WS_POPUP for the window style. Also, if the create fails, then you should check GetLastError for reason codes.
 
Share this answer
 
v2
Comments
thomas_wingfield 4-Apr-13 6:44am    
Hello

I have to create Pop up :(
If I do WS_CHILD everything is ok
Hello! Sorry for posting this question, I solved alone it.
The reason was in 7th parameter.It should be NULL and everything is ok
Thank you all for helping
 
Share this answer
 
Comments
nv3 4-Apr-13 8:36am    
Are you talking about the 7th or 6th parameter? I assume you replace mpWnd with NULL. That will mean that the desktop becomes the owner of your popup, which is undesirable, because your popup will not head, when your main application is minimized. Instead, get the top-level parent by GetTopLevelParent and use that as parent in CreateEx.
thomas_wingfield 4-Apr-13 10:46am    
About id of resource 7th ( start count from 1:) )
nv3 4-Apr-13 11:15am    
Ok, so a duplicate id.
thomas_wingfield 5-Apr-13 8:05am    
nv3. Do you think duplicate? Actually I checked it before solving and couldn't find some "holder" of 1. And actually I changed a few times on different numbers
VERIFY(m_pSurfaceWnd->CreateEx(0, m_NameClass, NULL,WS_VISIBLE, rcTemp, NULL, NULL));

It shuld be like this
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900