Click here to Skip to main content
13,050,429 members (79,074 online)
Rate this:
Please Sign up or sign in to 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:
        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 0: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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 3 Apr 2014
Copyright © CodeProject, 1999-2017
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