Close/exit a program: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.) |
m (Updated author links.) |
||
Line 1: | Line 1: | ||
{|align=right | |||
|<small>Author: [[{{ns:2}}:virtlink|virtlink]] ([[{{ns:3}}:virtlink|talk]], [[{{ns:-1}}:Contributions/virtlink|contrib]])</small> | |||
|} | |||
<br style="clear:both;"> | |||
== Description == | == Description == | ||
You can close or exit any program by using this code. | You can close or exit any program by using this code. | ||
Line 33: | Line 37: | ||
See also the following threads: [http://forums.winamp.com/showthread.php?s=&threadid=114777&highlight=FindWindow+SendMessage Windows Messaging] and [http://forums.winamp.com/showthread.php?threadid=107947 Need "SendMessage"-Command Help] | See also the following threads: [http://forums.winamp.com/showthread.php?s=&threadid=114777&highlight=FindWindow+SendMessage Windows Messaging] and [http://forums.winamp.com/showthread.php?threadid=107947 Need "SendMessage"-Command Help] | ||
Revision as of 23:15, 29 April 2005
Author: virtlink (talk, contrib) |
Description
You can close or exit any program by using this code.
This code won't work with all programs, but it will with most of them. If the code doesn't work as it is written here, try uncommenting the 'SendMessage $0 ${WM_DESTROY} 0 0' and comment the 'SendMessage $0 ${WM_CLOSE} 0 0' line. Winamp 2 (and propably Winamp 3 too) can be closed with the 'SendMessage $0 ${WM_CLOSE} 0 0' line.
To use this function push the window's class name and call the function.
Example
Push "Winamp v1.x" Call CloseProgram
This piece of code will close down Winamp 2. To find out other windows' classes ("Winamp v1.x" in Winamp 1/2's case) use a program such as Win32Spy (open source).
The Function
!include WinMessage.nsh Function CloseProgram Exch $1 Push $0 loop: FindWindow $0 $1 IntCmp $0 0 done #SendMessage $0 ${WM_DESTROY} 0 0 SendMessage $0 ${WM_CLOSE} 0 0 Sleep 100 Goto loop done: Pop $0 Pop $1 FunctionEnd
See also the following threads: Windows Messaging and Need "SendMessage"-Command Help