CWnd dynamic creation and deletion problem
-
I want to create, show, and delete various CWnd or CWnd derived Windows:
void MyFoo(CRuntimeClass *pWndClass,...) { CWnd* pWnd = pWndClass->CreateObject(); pWnd->Create(..); // Create the Window associated with pWnd; // The actual Create will be based on the type of Window ... pWnd->ShowWindow(SW_SHOW); ... pWnd->DestroyWindow(); //Destroy the Window delete (pWnd) // Delete the CWnd or CWnd derived object }
pWnd can be any type of windows (e.r., CDialog, CFormView, CView,...). The problem is: if pWnd is a dialog or CDialog-derived object, it works ok. But if pWnd is derived from CView or CWnd but not from CDialog, the delete statement in the above function doesn't work with an error message as access denied (0xc0000005). So why doing that? // -
I want to create, show, and delete various CWnd or CWnd derived Windows:
void MyFoo(CRuntimeClass *pWndClass,...) { CWnd* pWnd = pWndClass->CreateObject(); pWnd->Create(..); // Create the Window associated with pWnd; // The actual Create will be based on the type of Window ... pWnd->ShowWindow(SW_SHOW); ... pWnd->DestroyWindow(); //Destroy the Window delete (pWnd) // Delete the CWnd or CWnd derived object }
pWnd can be any type of windows (e.r., CDialog, CFormView, CView,...). The problem is: if pWnd is a dialog or CDialog-derived object, it works ok. But if pWnd is derived from CView or CWnd but not from CDialog, the delete statement in the above function doesn't work with an error message as access denied (0xc0000005). So why doing that? //CView objects delete themselves using a
delete this
So you should not delete CView and CView derived classes. I am confused about your CWnd problem though. Nish CPUA # 0x0666 Sonork ID 100.9786 voidmain www.busterboy.org -
CView objects delete themselves using a
delete this
So you should not delete CView and CView derived classes. I am confused about your CWnd problem though. Nish CPUA # 0x0666 Sonork ID 100.9786 voidmain www.busterboy.orgDo you mean that every CView type class dynamically created should be deleted by itself within its class? In my original example, the pWnd has a valid memory address, but the members of pWnd are not "valid", e.g., pWnd->hWnd = 0xddddddddd. I don't know how comes that.