Click here to Skip to main content
Rate this: bad
good
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:
    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 4-Apr-13 1:09am
Comments
nv3 at 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 at 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 at 4-Apr-13 7:03am
   
I would debug into the CreateEx call and see what goes wrong.
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  
v2
Comments
thomas_wingfield at 4-Apr-13 6:44am
   
Hello
 
I have to create Pop up :(
If I do WS_CHILD everything is ok
Rate this: bad
good
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
  Permalink  
Comments
nv3 at 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 at 4-Apr-13 10:46am
   
About id of resource 7th ( start count from 1:) )
nv3 at 4-Apr-13 11:15am
   
Ok, so a duplicate id.
thomas_wingfield at 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
good
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
  Permalink  
v2

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



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