|
-
April 8th, 2008, 05:59 PM
#1
[Solved]Adding a CWnd child window
Hi all
I am a newbie with CWnd classes and I would like to know how I can implement a little child window inside another one using the CWnd class (I don't want the resource template)
I created a normal mfc dialog based project and added a CWnd class to my project, then added a member variable to the main dialog class and initialized the CWnd's constructor with a pointer to main dialog (parent) 'this'
The constructor of the CWnd class is:
CProp::CProp(CWnd* pParent)
{
//int x = CWnd::CreateEx(NULL, AfxRegisterWndClass(NULL), NULL, WS_CHILD|WS_VISIBLE|WS_DLGFRAME,0, 0, 120, 120, pParent, (HMENU)NULL);
UINT nID = 1234;
CWnd* pWnd = new CWnd;
LPCTSTR ClassName = (LPCTSTR)AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,NULL,(HBRUSH)COLOR_BACKGROUND + 1,NULL);
pWnd->CreateEx(0, ClassName, "Win", WS_CHILD | WS_CAPTION|WS_VISIBLE|WS_DLGFRAME,
0, 0, 580, 100, pParent->m_hWnd, (HMENU)NULL);
pWnd->ShowWindow(SW_SHOWNORMAL);
pWnd->CenterWindow();
}
I am always getting Warning: Window creation failed: GetLastError returns 0x0000057E that Lookup says: "Cannot create a top-level child window."
If you'd be so kind to solve this problem and maybe linking me a guide or something to learn (after shown the child window) how to use pDX data exchanges and handlers with a CWnd window like above, I will be extremely grateful
Any help appreciated, thanks again
Last edited by NasterMain; April 9th, 2008 at 05:51 AM.
Reason: Problem Solved
-
April 8th, 2008, 06:07 PM
#2
Re: Adding a CWnd child window
Since the error is telling you that you can't create a top level child window, have you tried to set its parent hwnd to a non-null value?
Code:
pWnd->CreateEx(this, ClassName, "Win", WS_CHILD | WS_CAPTION|WS_VISIBLE|WS_DLGFRAME,
0, 0, 580, 100, pParent->m_hWnd, (HMENU)NULL);
-
April 8th, 2008, 06:21 PM
#3
Re: Adding a CWnd child window
uh?
First member is extended style, and pParent->m_hWnd is a valid handle to parent
-
April 8th, 2008, 07:36 PM
#4
Re: Adding a CWnd child window
Ok, my mistake. Did you check the value of pParent->m_hWnd in the debugger?
-
April 9th, 2008, 02:19 AM
#5
Re: Adding a CWnd child window
Maybe there is a problem with your styles.
According to MSDN:
 Originally Posted by MSDN
WS_CAPTION Creates a window that has a title bar (implies the WS_BORDER style). Cannot be used with the WS_DLGFRAME style
.
So try to remove the WS_DLGFRAME flag.
-
April 9th, 2008, 05:51 AM
#6
Re: Adding a CWnd child window
You're both right, the CWnd value of pParent was right, but pParent->m_hWnd was null (i was calling the child creation before the parent was created) and there was the WS_DLGFRAME style
Thanks very much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|