An MFC program(single document with form view) has some sub threads which access some controls on MFC GUI. The main thread is wished to quit after all sub threads quit. I tried notifying sub threads to quit and wait them in OnDestroy handler. However, there is a dilemma over here. Because sub threads might SendMessage GUI controls while main message loop is blocked in OnDestroy handler. That is a deadlock.
I have an idea to solve this: I hope there could be a way to handle MFC's WM_CLOSE or WM_QUIT and use a custom message like UDM_QUIT which is sent by sub threads to main thread to do the actual quitting, meanwhile I don't wait sub threads to quit in OnDestroy handler. But i'm not an MFC guru and don't know how to achieve that.