If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
OnInit did not fail. Other wise the app/frame would not show up.
The original issue is I met a dialog each time I run the app "Deleted stale lock file '/home/username/prog_name-username' ". Googled and found someone said the wxSingleInstanceChecker I used was not released/deleted while exiting, which I did it explicitly in OnExit.
However, I still met the issue after I changed the pointer to shared_ptr as shown in the code above. Looks the shared_ptr was also broken?
It worked well after I added Skip in my OnClose handler! Thanks a lot.
BTW, the issue of shared_ptr might introduced by the code of calling exit in OnClose. I tried to remove it and did not meet crash. So, I should remove the exit, right? And what about the Destroy? The code is used in the OnClose handler of my main frame.
#ifndef __WXMSW__
// it will crash randomly under linux.
// so we must call exit() to quit the app.
exit( 0 );
#else
Destroy(); // quit app normally.
#endif
}
Right.
You should never call exit() because it messes with the normal cleanup. That is valid for any c++ program, see shared_ptr. You normally don't need Destroy() either (unless you have an override that must be called or something like that).
You normally don't need Destroy() either (unless you have an override that must be called or something like that).
Does this apply to all? I mean the dialogs I created for my application. I simply do clean up and handle veto in the OnClose handler of the dialog and call Skip() if not veto able? Is this the correct way?
Windows are normally deleted when their parent gets deleted, or by the app in case of TLWs with no parent. If you want a window to be deleted earlier than its parent or app exit, then you can call Destroy() for it. Otherwise Destroy() is not needed when the window would already be on its way to being deleted.
The OnClose() handling sounds about right.
I can't really say, I've never used DeletePendingEvents in about 10 years of using wxW. But it does sound somewhat too drastic tu use it for such a reason.
Did you try to simply Disconnect()/Unbind() your OnActivate() handler in OnClose()?