Click to See Complete Forum and Search --> : CWnd::CreateEx issue


revof11
March 19th, 2003, 12:29 PM
[FONT=arial]
I am working on creating an application that requires a full-screen window. In order to do this I am using MFC's CWnd::CreateEx within a class that inherits from CWnd. However, when I attempt to create a window over 640x480 (more specifically using the system metrics), it creates the window for a brief second and then just flashes away!!! :confused:

Here is the code i am using (this is in CMyWindow::Create):
[FONT=courier new]
// get system metrics
nScreenX = GetSystemMetrics(SM_CXSCREEN);
nScreenY = GetSystemMetrics(SM_CYSCREEN);

// create (for DEBUG mode, we don't want it to be on top, because then it will show up over our DEBUG windows)
#ifdef _DEBUG
bRes = CWnd::CreateEx(0,pszClassName,"",WS_POPUP|WS_VISIBLE,20,20,nScreenX,nScreenY,NULL,NULL);
#else
bRes = CWnd::CreateEx(WS_EX_TOPMOST,pszClassName,"",WS_POPUP|WS_VISIBLE,0,0,nScreenX,nScreenY,NULL,NULL);
#endif

[FONT=arial]
Can anyone tell me what I am doing wrong? Thank you.

Mike Harnad
March 19th, 2003, 03:53 PM
From the looks of your code, you're creating the window on the stack (locally). You have not defined a CWnd or HWND to hold the result of the create method. When the code is out of scope, the window is destroyed.

revof11
March 19th, 2003, 07:23 PM
I was assuming the CWnd-derived class would handle that by itself. Do you have any immediate recommentations on how to go about that?

The reason I ask is because when the window size is under or at 640 by 480 (example below) the window WILL stay and operate properly. I would guess that you are suggesting using the internal this->CreateEx for creation.

I attempted running the code with my screen size down to 640 x 480 (as horrifying as it was) and everything worked just fine, which is what has me so baffled.

Functional code example:
bRes = CWnd::CreateEx(0,pszClassName,"",WS_POPUP|WS_VISIBLE,20,20,400,400,NULL,NULL);

Mike Harnad
March 20th, 2003, 07:27 AM
Can you post more of the relevant code that creates the window. It's hard to determine the cause from the snippet you have provided.