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. Creating and Deleting a New Window

Creating and Deleting a New Window

Scheduled Pinned Locked Moved C / C++ / MFC
c++
3 Posts 3 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.
  • B Offline
    B Offline
    BobInNJ
    wrote on last edited by
    #1

    I am currently writing an application using C++ and MFC. For displaying the results of a certain operation, a new window is created. The window is represented by a class I created called COutputWindow. The base class of COutputWindow is CFrameWnd. I create the output window by doing the following operations: 1) Creating a new instance of COutputWindow by calling new. 2) Calling the member functions of COutputWindow: ShowWindow and UpdateWindow. Actually these member functions are defined in the base class. 3) A define COutputWindow::OnPaint to display the results. In my main window, I save a pointer to the output window. In addition, when the output window (window of type COutputWindow) is closed, I want the objected created by new in step 1 to be deleted. However, I cannot do this until the window is completely closed. Therefore, I believe that the pointer cannot be deleted on COutputWindow::OnClose. Therefore, where should I delete the pointer that represnets the object to the closed window. Thanks Bob

    M _ 2 Replies Last reply
    0
    • B BobInNJ

      I am currently writing an application using C++ and MFC. For displaying the results of a certain operation, a new window is created. The window is represented by a class I created called COutputWindow. The base class of COutputWindow is CFrameWnd. I create the output window by doing the following operations: 1) Creating a new instance of COutputWindow by calling new. 2) Calling the member functions of COutputWindow: ShowWindow and UpdateWindow. Actually these member functions are defined in the base class. 3) A define COutputWindow::OnPaint to display the results. In my main window, I save a pointer to the output window. In addition, when the output window (window of type COutputWindow) is closed, I want the objected created by new in step 1 to be deleted. However, I cannot do this until the window is completely closed. Therefore, I believe that the pointer cannot be deleted on COutputWindow::OnClose. Therefore, where should I delete the pointer that represnets the object to the closed window. Thanks Bob

      M Offline
      M Offline
      Mauro Leggieri
      wrote on last edited by
      #2

      You should set the pointer to the output window to NULL in the OnDestroy callback and override the PostNcDestroy function in order to add a "delete this;" statement. Best regards, Mauro H. Leggieri

      1 Reply Last reply
      0
      • B BobInNJ

        I am currently writing an application using C++ and MFC. For displaying the results of a certain operation, a new window is created. The window is represented by a class I created called COutputWindow. The base class of COutputWindow is CFrameWnd. I create the output window by doing the following operations: 1) Creating a new instance of COutputWindow by calling new. 2) Calling the member functions of COutputWindow: ShowWindow and UpdateWindow. Actually these member functions are defined in the base class. 3) A define COutputWindow::OnPaint to display the results. In my main window, I save a pointer to the output window. In addition, when the output window (window of type COutputWindow) is closed, I want the objected created by new in step 1 to be deleted. However, I cannot do this until the window is completely closed. Therefore, I believe that the pointer cannot be deleted on COutputWindow::OnClose. Therefore, where should I delete the pointer that represnets the object to the closed window. Thanks Bob

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        You are not doing any polymorphic operations. Also you do not need any runtime information for creating the window. So I suggest you go for a stack variable instead of using new and simply show/hide the window. This will also work faster.

        «_Superman_» I love work. It gives me something to do between weekends.

        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