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