简体   繁体   中英

MFC OnInitialUpdate never gets called

I have a CFormView that is dynamically created at runtime. However, something really weird is going on, because OnInitialUpdate never gets called for that view. I set a breakpoint in the function and it never gets hit once, even though I can see the view being displayed onscreen. This is a problem because whenever I try to work with the view's member controls, the program crashes because they aren't initialized. What gives?

EDIT: You can just call OnInitialUpdate manually; you don't necessarily need to override it.

I think I might be a victim of this bug. My workaround was to override OnInitialUpdate() and call it manually, immediately after my view is dynamically created. This only worked if the very first line in the overridden function was a call to the parent CFormView::OnInitialUpdate() .

I'm currently working round this issue by using CFormView::OnActivateView() instead, then testing/setting a member variable flag (m_bInitialised) so that I can ensure the code I wanted in CFormView::OnInitialUpdate() only gets run the first time.

Seems slightly more self-contained than manually calling OnInitialUpdate() from outside, but at best only slightly less icky :-/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM