| |

VerySource

 Forgot password?
 Register
Search
View: 684|Reply: 4

Error in dynamically creating controls, who will help me ???

[Copy link]

2

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-13 14:20:01
| Show all posts |Read mode
One of my programs is based on single document type SDI
Dynamically manage and call two videos in the main frame through a document template
CScrollView and CRichEditView

Views currently loaded are automatically destructed when switching views

I used a dynamically created CEdit * m_pEdit object in CScrollView
When used in view m_pEdit = new CEdit; m_pEdit-> Create (..)
Delete m_pEdit when not in use or CScrollView destruct; m_pEdit = NULL;
Do not switch views only in CScrollView constantly new and delete will not go wrong.

problem:
When switching from CScrollView to CRichEditView first,
By tracking, m_pEditCScrollView has been deleted
When switching back to CScrollView, use m_pEdit-> Create (..) in the program code
When I reported an error, I traced this error and found that the Create function of the CEdit class of MFC has an exception.
Click [Ignore] in the exception dialog box and find that this error does not affect the normal operation of the program
The m_pEidt control can also be used normally.

What is the reason, my brother is polite.
How to avoid this exception (you can eliminate the exception prompt box)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Unknown

Post time: 2020-1-19 11:09:01
| Show all posts
I think you should not delete the window before the delete object, causing the object to be destructed and the window still, so an exception occurs
Reply

Use magic Report

0

Threads

36

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-1-19 15:18:01
| Show all posts
It is recommended to learn to use boost :: shared_ptr, only use new, not delete
Smart pointers eliminate the hassle of object management.
www.boost.org/libs/smart_ptr/shared_ptr.htm
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-19 18:27:02
| Show all posts
When switching
The new object (CEdit object) is not released normally
Maybe just destructed m_pEdit
Call m_pEdit-> Create (..) again when switching back again
This pointer error may occur

A good way to use smart pointers
Reply

Use magic Report

2

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-8-5 13:30:01
| Show all posts
Strange thing, I added the code view->SendMessageBox(WM_SIZE,0,0); before new and solved it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list