Click here to Skip to main content
11,921,889 members (39,970 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC
I created class CSurfaceWnd from CWnd by Class Wizard. I tried to create window but getting error. That's my code of creating:
        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;
    VERIFY(m_pSurfaceWnd->CreateEx(WS_EX_CLIENTEDGE, m_NameClass, NULL, WS_POPUP | WS_VISIBLE, rcTemp, mpWnd, 1));
    //DWORD dw =GetLastError();

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 4-Apr-13 1:09am
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
thomas_wingfield 4-Apr-13 6:44am

I have to create Pop up :(
If I do WS_CHILD everything is ok
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

VERIFY(m_pSurfaceWnd->CreateEx(0, m_NameClass, NULL,WS_VISIBLE, rcTemp, NULL, NULL));

It shuld be like this

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

  Print Answers RSS
0 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 3 Apr 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100