similar to when you choose exit, the application prompts you to save.
not sure how to get it to put up a save dialog before exiting.
On Aug 21, 9:37 am, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below....
On Mon, 20 Aug 2007 21:08:45 -0700, alexl <alexthebl...@gmail.com> wrote:
It didn't work in this test I tried.
The message box "Thread running" pops up, but if I quit the app from
file/quit, the end of message box never appears. I also tried deriving
a class from CWinThread and overrode ExitInstance but ExitInstance
never gets called.
Any ideas? (Ps I'm sure this has been solved thousands of times before
but I don't know where to look)
UINT MyControllingFunction( LPVOID pParam ) {
MSG msg;
BOOL bRet;
boolean done=false;
Sleep(2000);
AfxMessageBox(L"thread running");
****
Do not create message boxes in worker threads. Generally, avoid doing
ANYTHING that
interacts with the user from ANY thread.
Is there some purpose to the Sleep(2000)? What is it? Would removing
the Sleep() cause
your program to malfunction? If so, you have deep design problems.
****> while (!done && (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) {
switch (msg.message) {
default:
break;
}
}
****
You should seriously consider why you are putting a GetMessage loop
inside a worker
thread. This suggests you want a UI thread. Unfortunately, the loop is
far too late to
deal with the first message box, and it has already terminated by the
time you do the
second one. Rewrite this to use a UI thread by deriving a class from
CWinThread. Then
you can use message maps to dispatch your messages. You should still
avoid doing
AfxMessageBox from a thread (for example, these would have to appear in
InitInstance and
ExitInstance, again, outside the message pump, so they would be
inappropriate)
joe
****
AfxMessageBox(L"endofthread");
return 0;
}
On Aug 14, 3:37 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcp> wrote:
alexlwrote:
Hi,
if I have a mfc thread that spawns a com object, does my thread need
to intercept WM_QUIT in its message loop before passing it up the
chain, that is if I have clean up code that needs to execute before
shut down?
Thx
The CWinThread message loop takes care of WM_QUIT for you. It calls
ExitInstance, which is a good place for you to clean up thread
objects.
--
Scott McPhillips [MVP VC++]
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm