WM_CLOSE and UnloadMode 
Author Message
 WM_CLOSE and UnloadMode

Hi,

I'm trying to properly close another VB application (any application, so
it's generic).

I'm sending the WM_CLOSE message to all forms, but... if the other app
has a confirmation message before closing, it doesn't work.

Of course I can close the app anyway by others means, but if the app is
properly designed, it should check the Unload mode parameter before
asking for confirmation.

But... I didn't find a way to set this parameter.

I tried so far:
(The available parameters seems to be for other purposes, but anyway I
tried)

Call PostMessage(hwnd, WM_CLOSE, 0&, 0&)
Call PostMessage(hwnd, WM_CLOSE, 3&, 0&)
Call PostMessage(hwnd, WM_CLOSE, 0&, 3&)
Call PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0&)
Call PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 3&)

UnloadMode is always 0.

Any idea?
Thanks.



Wed, 14 Mar 2012 04:10:34 GMT  
 WM_CLOSE and UnloadMode
Off the top of my head, add a command line to the other app that would
specifically close it with no prompt and shell out to that app with the
command line when you want to close it.

Of course, to do this, you will need to properly handle a new instance of
that app and have it feed the command line to the original instance.  Not a
real chore.

--
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=43606237254
| Hi,
|
| I'm trying to properly close another VB application (any application, so
| it's generic).
|
| I'm sending the WM_CLOSE message to all forms, but... if the other app
| has a confirmation message before closing, it doesn't work.
|
| Of course I can close the app anyway by others means, but if the app is
| properly designed, it should check the Unload mode parameter before
| asking for confirmation.
|
| But... I didn't find a way to set this parameter.
|
| I tried so far:
| (The available parameters seems to be for other purposes, but anyway I
| tried)
|
| Call PostMessage(hwnd, WM_CLOSE, 0&, 0&)
| Call PostMessage(hwnd, WM_CLOSE, 3&, 0&)
| Call PostMessage(hwnd, WM_CLOSE, 0&, 3&)
| Call PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0&)
| Call PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 3&)
|
| UnloadMode is always 0.
|
| Any idea?
| Thanks.



Wed, 14 Mar 2012 05:00:23 GMT  
 WM_CLOSE and UnloadMode
Kevin Provance escribi:

Quote:
> Off the top of my head, add a command line to the other app that would
> specifically close it with no prompt and shell out to that app with the
> command line when you want to close it.

> Of course, to do this, you will need to properly handle a new instance of
> that app and have it feed the command line to the original instance.  Not a
> real chore.

I have not control over the development of the other application.


Wed, 14 Mar 2012 05:47:48 GMT  
 WM_CLOSE and UnloadMode
| Kevin Provance escribi:
| > Off the top of my head, add a command line to the other app that would
| > specifically close it with no prompt and shell out to that app with the
| > command line when you want to close it.
| >
| > Of course, to do this, you will need to properly handle a new instance
of
| > that app and have it feed the command line to the original instance.
Not a
| > real chore.
| >
|
| I have not control over the development of the other application.

Okay, fair enough.  When you send the WM_CLOSE to the other app, does it
give you the prompt to close every time?



Wed, 14 Mar 2012 05:59:31 GMT  
 WM_CLOSE and UnloadMode
Kevin Provance escribi:

Quote:
> Okay, fair enough.  When you send the WM_CLOSE to the other app, does it
> give you the prompt to close every time?

It could be any VB application, it's for generic use.
(think it could be a program of yours)
May be it won't ask anything, but some applications asks before exiting.

If that application is properly designed, it should check the UnloadMode
parameter before asking for confirmation.
So, I would like to set this parameter to something else than zero in
order to allow such applications to close properly.

Because the next step is to close them by posting WM_QUIT messages.

And if it's still running, TerminateProcess.

But before that, I want to do all I have in my hands to allow them to
close properly.

That's why I would like to be able to set the UnloadMode parameter.



Wed, 14 Mar 2012 06:14:43 GMT  
 WM_CLOSE and UnloadMode
Eduardo escribi:

Quote:
> If that application is properly designed, it should check the UnloadMode
> parameter before asking for confirmation.

I could manage to click "Yes" if I see that it's a messagebox, but it
could be asking for anything, may be it's asking for saving a file or
whatever, so I can't assume that.

I just would like to set the UnloadMode parameter, anything more than
that would be a guess.



Wed, 14 Mar 2012 06:22:06 GMT  
 WM_CLOSE and UnloadMode

Quote:

> Kevin Provance escribi:

>> Okay, fair enough.  When you send the WM_CLOSE to the other app, does it
>> give you the prompt to close every time?

> It could be any VB application, it's for generic use.
> (think it could be a program of yours)
> May be it won't ask anything, but some applications asks before exiting.

> If that application is properly designed, it should check the UnloadMode
> parameter before asking for confirmation.

You can't set that parameter directly.  If you could it might be very bad;
what happens if an app knows that when the unload mode is "from code" it
means everything has been properly saved and you managed to simulate that?
The user could lose everything.

You can cause some different values to be set by your choice of method for
closing the app but not all and not all apps are going to differentiate
WM_Close from the task manager request from a system shutdown as far as what
prompt they may display.



Wed, 14 Mar 2012 06:35:00 GMT  
 WM_CLOSE and UnloadMode

Quote:

> I just would like to set the UnloadMode parameter, anything more than that
> would be a guess.

Setting that parameter would still be a guess and just as likely to be
wrong.

What would you set it to in order to maximize the chance of no confirmation
dialog?  No matter why a form is being asked to close there could be valid
reasons to ask a question and possibly cancel the unload.

For that matter there are many apps that use Form_Unload instead of
Form_QueryUnload for confirmation dialogs and that provides no unloadmode.
That's poor practice but not uncommon.



Wed, 14 Mar 2012 06:43:03 GMT  
 WM_CLOSE and UnloadMode

Quote:

> I just would like to set the UnloadMode parameter, anything more than that
> would be a guess.

UnloadMode parameter is a VB thing. Try posting WM_QUERYENDSESSION or
WM_ENDSESSION to the app's window. It will make it think that the computer
is about to be restarted, but the app could show a save prompt.

Also, avoid using PostQuitMessage or WM_QUIT. This ends the application
without asking, and anything not saved is lost, but it works, and it's
better than using TerminateProcess.



Wed, 14 Mar 2012 06:48:46 GMT  
 WM_CLOSE and UnloadMode
Bob Butler escribi:

Quote:


>> Kevin Provance escribi:

>>> Okay, fair enough.  When you send the WM_CLOSE to the other app, does
>>> it give you the prompt to close every time?

>> It could be any VB application, it's for generic use.
>> (think it could be a program of yours)
>> May be it won't ask anything, but some applications asks before exiting.

>> If that application is properly designed, it should check the
>> UnloadMode parameter before asking for confirmation.

> You can't set that parameter directly.  If you could it might be very
> bad; what happens if an app knows that when the unload mode is "from
> code" it means everything has been properly saved and you managed to
> simulate that? The user could lose everything.

I don't want to tell it's "from code", but may be from taskbar (value = 3).

Quote:
> You can cause some different values to be set by your choice of method
> for closing the app but not all and not all apps are going to
> differentiate WM_Close from the task manager request from a system
> shutdown as far as what prompt they may display.

I don't care, I just want the parameter not to be 0 (user) or 1 (code).


Wed, 14 Mar 2012 06:53:25 GMT  
 WM_CLOSE and UnloadMode
Bob Butler escribi:

Quote:


>> I just would like to set the UnloadMode parameter, anything more than
>> that would be a guess.

> Setting that parameter would still be a guess and just as likely to be
> wrong.

No. It's not a guess. I know that I'm closing the application and it's
done whithout user interaction.

Quote:
> What would you set it to in order to maximize the chance of no
> confirmation dialog?

I was thinking in UnloadMode = 3 (from taskbar)

Quote:
> No matter why a form is being asked to close there
> could be valid reasons to ask a question and possibly cancel the unload.

No. If is's rebooting there is no choice to ask anything.
That could be another possibility (unload code = rebooting).

Quote:
> For that matter there are many apps that use Form_Unload instead of
> Form_QueryUnload for confirmation dialogs and that provides no
> unloadmode. That's poor practice but not uncommon.

Then I have to close all anyway by other means.
But if they designed properly, in that case my code would also work
properly.


Wed, 14 Mar 2012 06:58:09 GMT  
 WM_CLOSE and UnloadMode
Nobody escribi:

Quote:

>> I just would like to set the UnloadMode parameter, anything more than that
>> would be a guess.

> UnloadMode parameter is a VB thing. Try posting WM_QUERYENDSESSION or
> WM_ENDSESSION to the app's window. It will make it think that the computer
> is about to be restarted, but the app could show a save prompt.

I was going to investigate what the systems sends to the APP while
rebooting spying the window's messages.

Thanks, I'll check those messages.

Quote:
> Also, avoid using PostQuitMessage or WM_QUIT. This ends the application
> without asking, and anything not saved is lost, but it works, and it's
> better than using TerminateProcess.

Yeah, I first try to close with WM_CLOSE, I wait a litlle, then if it's
still running, I send WM_QUIT, I wait again, and if it's still running
TerminateProcess.

But before all this, I bring the App to front and ask the user to close
it manually. If the user didn't close it then I do all the other stuff
to close it automatically.



Wed, 14 Mar 2012 07:04:12 GMT  
 WM_CLOSE and UnloadMode

Quote:

> Bob Butler escribi:
<cut>
>> No matter why a form is being asked to close there could be valid reasons
>> to ask a question and possibly cancel the unload.

> No. If is's rebooting there is no choice to ask anything.
> That could be another possibility (unload code = rebooting).

That's not true; even when doing a reboot an app can prompt, and potentially
cancel the action.


Wed, 14 Mar 2012 07:09:48 GMT  
 WM_CLOSE and UnloadMode
Bob Butler escribi:

Quote:


>> Bob Butler escribi:
> <cut>
>>> No matter why a form is being asked to close there could be valid
>>> reasons to ask a question and possibly cancel the unload.

>> No. If is's rebooting there is no choice to ask anything.
>> That could be another possibility (unload code = rebooting).

> That's not true; even when doing a reboot an app can prompt, and
> potentially cancel the action.

Now yes, but in olders Windows I think I recall that it closed anyway.

I don't know if with the EWX_FORCE flag set it asks even now (I think it
doesn't), but anyway it should not be used in normal situations.



Wed, 14 Mar 2012 07:41:31 GMT  
 WM_CLOSE and UnloadMode

Quote:

> I don't want to tell it's "from code", but may be from taskbar (value =
> 3).

Is it a VB6 app you are trying to close ?  If so, the trick there is to
close the hidden parent form that VB6 creates. If you send a message to that
window telling it to close, VB assumes it had to come from task manager.


Wed, 14 Mar 2012 07:59:30 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. unloadmode (vb6)

2. UnloadMode - QueryUnload

3. QueryUnload and UnloadMode Replacement

4. Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

5. What does UnloadMode = 5 mean?

6. UnloadMode Variable

7. UnloadMode = 5 ????

8. Send WM_Close event to application with Process ID

9. SendMessage API and WM_CLOSE constant?

10. Ignoring WM_CLOSE

11. WM_CLOSE API function ?

12. WM_CLOSE in COleControl from a VB contrainer????

 

 
Powered by phpBB® Forum Software