Archive: Windows Messaging


Windows Messaging
I found this piece of code elsewhere on this forum. (Commenting added by me, based on KiCHiK's WinMessages.NSH.)


Function CloseWinamp
Push $0
loop:
FindWindow $0 "Winamp v1.x"
IntCmp $0 0 done
SendMessage $0 "000E" 0 0 ; WM_GETTEXTLENGTH ????
SendMessage $0 "0002" 0 0 ; WM_DESTROY
SendMessage $0 "0082" 0 0 ; WM_NCDESTROY
;or thisone SendMessage $0 "16" 0 0 ; WM_CLOSE
Sleep 100
Goto loop
done:
Pop $0
FunctionEnd

I've been trying to understand it, but, not knowing how reliable the source is, I may be wasting my time. (If I am, could someone please let me know.)

What's puzzling me is the sequence of messages. Is the author just trying out a lot of alternatives in a "hit and miss" attempt to find one that works, or is this a recommended series of messages deliberately sent in a sequence in order to close a window gently? Experimentation reveals that WM_CLOSE (0x10) and WM_DESTROY (0x2) work on their own. The others don't.

Also:
(a) Is "close" preferrable to "destroy"?
(b) What is the difference between WM_DESTROY and WM_NCDESTROY?
(c) Why is WM_GETTEXTLENGTH relevant here????

To close Winamp 2 you need only WM_CLOSE. WM_CLOSE is usually better than WM_DESTROY but it really depends on how the application was programed.