-
Hi, I need to kill another app, but I want to "ask" it to close so that it can generate its save prompt if needed, instead of just "killing" it. I tried SendMessage which kills it, but the other app's save prompt won't appear, even if it should.
Thanks in advance,
-
What message did you send to it? Kill? or WM_Destroy? or what? because from what I learned in VC++ is if I send a message WM_Destroy, it'll close the application, ofcourse, if the application has a routine where it does it saving funtions to save your work before closing, then it will do that before it gets "destroyed".... I may not be getting it right, but try WM_Destroy if you haven't already...
-
WildGhost is correct, WM_DESTROY triggers the Unload method of a Form, which is where most of the cleanup functionality is provided (such as prompting to save). Beyond this there is not a whole lot you can do, it all depends on how the app was coded. For example, if the code to prompt for save is placed in the menu item's click event then it may never be called, or the app may not even have a Form, hence there may not even be an Unload event.
Just wanted to elaborate.
-
Well, I think there's acctually a couple of different closing methods, where you can BRUTLY shutdown the program where, the program just shuts down, and yea it all depends on the program, many programs that I've made, and many that I've seen, use the message WM_Destroy, there's 2 other, or may be 3 other, but they slipped out of memory some how, if I see them I'll recognize them, but basically WM_Destroy was used for closing an app, many times they use it, so if you send it WM_Destroy, then it should close the way the person had originally intended it to close...
-
I was using WM_Close. WM_Destroy isn't doing anything for me.
Here's what I'm trying:
Code:
Public Const WM_DESTROY = &H2
Public Const WM_CLOSE = &H10
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Call SendMessage(ghwnd, WM_CLOSE, 0&, 0&) 'Kills Other App, But No Save Prompt
Call SendMessage(ghwnd, WM_DESTROY, 0&, 0&) 'No Action
Debug.Print "Error After Sending WM_Destroy: " & GetLastError 'Returns 0
What am I doing wrong? Thanks
-
Try this one...
Public Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long
I haven't tried it but it should close a window like it says...
-
Looks like it just minimizes it (disappears but shows in the task list). What else can I try?
Thanks again
-
There is another way, I've never tried it personally, but I've seen code for it before. It kind of ressembles SendKeys <shudder> but you use APIs to do it instead. What you need to do is get a handle to the Window, from there you get a handle to Window's Menu, and then you find the menu item for Exit and envoke it.
Sorry to be so vague, but like I said I've never tried it myself. If I find the code I'll post it.
-
You just jogged my memory. The other app is a child window without any menus and is meant to be closed via the toolbar. However, in its parent, a submenu exists to close the child and I do know how to select that menu item. Thanks for the help :):)