Sheen Space

MFC GetParentFrame() returns NULL

leave a comment »

I write this little post to record a small fact that you may have to pay attention to when you create your new CView inside your CFrameWnd.

By default, when you use Visual Studio’s resource editor to add a new dialog template for your CView class, the window style of that dialog template includes WS_POPUP. This normally doesn’t crash your program. However, we may want to call GetParentFrame() function within our CView from time to time, and if WS_POPUP is present, the function will return NULL pointer, causing memory access violation exception.

So, whenever you create CView within a frame window, pay attention to window style given by Visual Studio, and change WS_POPUP to WS_CHILD if needed.


Written by Ying

18/03/2011 at 10:14

Posted in C++, Programming, Technology, Windows

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: