Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Close particular program(.exe)
Message
From
27/11/2000 22:48:22
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00445134
Message ID:
00446009
Views:
9
>>Mike, I tend to use PostMessage() or PostThreadMessage() (depends on if I have an hWnd or a ThreadId) and a WM_QUIT rather than SendMessage() and a WM_CLOSE; it has the advantage that the message is added to the tail of the message queue, so pending events do get fired before the app shuts down.
>
>Though I'll agree that PostMessage() is a better choice than SendMessage() in most circumstances, why WM_QUIT instead of WM_CLOSE? I ask because WM_QUIT seems to be more suitable for use with PostQuitMessage() (notice that wParam is the PostQuitMessage() exit code). My reasoning for WM_CLOSE is that it tells the app "hey, you need to shut down", and the app still has the chance to ask for user confirmation.

PostQuitMessage() is strictly a self-termination mechanism; the thread typically issues it as a response to a request to quit, queuing a WM_QUIT at the tail of the present thread message queue to be acted on in order with any already pending messages in the thread queue, rather than instantly invoking an ExitThread() call which would perform an orderly shutdown, but which does nothing about handling any events that were received before the shutdown was declared. WM_QUIT terminates the event loop directly.

In the current MSDN docs, it's recommended that a thread issue itself a PostQuitMessage() instead of queuing a WM_QUIT; WM_CLOSE is the recommended message to send to the application's primary thread message queue, so I'm probably wrong here, although the general approach of using PostMessage() rather than SendMessage() to issue a WM_CLOSE, ensuring that the thread queue rather than the Window queue receives the message still seems right, especially if it's possible that the hWnd belongs to a child Window which might close without closing the parent thread is an issue. In the case of the revised API_APPRUN that I'm working on, I rely on using the PostThreadMessage() to close a child process, so that I don't have to rely on a known hWnd to request a shutdown, without the reliance on the TerminateProcess() call which has some potentially serious side-effects.

I'll try to put up an interrim update to API_APPRUN that uses the PostThreadMessage() shutdown mechanism tonight.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform