Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CWnd dynamic creation and deletion problem

CWnd dynamic creation and deletion problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yellowine
    wrote on last edited by
    #1

    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? //

    N 1 Reply Last reply
    0
    • Y yellowine

      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? //

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      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

      Y 1 Reply Last reply
      0
      • N Nish Nishant

        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

        Y Offline
        Y Offline
        yellowine
        wrote on last edited by
        #3

        Do 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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups