[VB6] Closing MSN messenger - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: [VB6] Closing MSN messenger (/showthread.php?tid=28042)
[VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 12:45 PM
I wrote a plugin in VB6, and now i'm trying to write a setup for it. It does work well, but there is one problem. Because the system message "MessengerPlus_PluginChange" doesn't seem to work for VB plugins, i decided to totaly close msn messenger + all the chat windows (after the user clicked yes of course). But i can't figure out how to do it... Anyone??
(sorry for my bad english...)
RE: [VB6] Closing MSN messenger by Wouter on 07-02-2004 at 12:59 PM
http://www.msnfanatic.com/index.php?module=announ...23002b7e59fedc8648
RE: [VB6] Closing MSN messenger by Dempsey on 07-02-2004 at 01:11 PM
MessengerPlus_PluginChange works fine for me from VB
RE: [VB6] Closing MSN messenger by Choli on 07-02-2004 at 01:32 PM
The MessengerPlus_PluginChange works, just be sure you "exetuce" it before you try to overwritte any DLL in use. (both VB and C ones).
RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 01:44 PM
Well i'll try to use MessengerPlus_PluginChange then another time...but i'm almost sure it didn't work for me...
@Wouter: Server not found...
RE: [VB6] Closing MSN messenger by CookieRevised on 07-02-2004 at 01:56 PM
quote: @Wouter: Server not found...
MSN Fanatic server is up an running atm
RE: RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 02:28 PM
quote: Originally posted by CookieRevised
quote: @Wouter: Server not found...
MSN Fanatic server is up an running atm
What do you mean?? I don't understand...sorry....
RE: [VB6] Closing MSN messenger by CookieRevised on 07-02-2004 at 02:31 PM
That the link that Wouter gave does work...
RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 02:33 PM
Well not with my provider... I think they've done a DNS change or something... Whatever.
But I can't visit that site, so would you be so kind as to copy the text to this forum?
RE: [VB6] Closing MSN messenger by CookieRevised on 07-02-2004 at 02:42 PM
Shutting Down MSN Messenger
Posted by daniel on 2003-09-16 05:57:20
At some point in most MSN Messenger applications, you may want to shut down Messenger, or restart it. This could be to apply a patch, or to make Messenger run its shut down routine, like updating the list cache, or removing the systray icon. MSN Messenger has a cross application window message method to make it exit, this is commonly used by its installer. When you install an update the current version is closed so it can overwrite the files.
An obvious method of shutting Messenger down would be to just use TerminateProcess, this method is very forceful and Messenger won't perform its shutdown routine. Before you perform this kind of termination, its best to try the cross application windows message method. This involves sending a custom window message to the Messenger system window "MSNHiddenWindowClass", which is just an always open window for things like receiving events for the systray icon.
You may have before seen a message pop up telling you that you need to close applications that are using MSN Messenger, like Hotmail in Internet Explorer, Outlook Express. The window message method cannot ignore this, therefore you WILL need to forcefully terminate Messenger. You should kill all instances of the Messenger typelib to prevent the message beforehand, otherwise you can get the user to close those applications.
First, lets look at the window message method. You need to register the message "TryMsnMsgrShutdown", and send it to the window with the class name "MSNHiddenWindowClass".
code: Private Sub GracefullShutdown(bShowCloseMsg As Boolean)
Dim hWnd As Long, lMsg As Long
hWnd = FindWindow("MSNHiddenWindowClass", vbNullString)
lMsg = RegisterWindowMessage("TryMsnMsgrShutdown")
Call SendMessage(hWnd, lMsg, CLng(bShowCloseMsg) + 1, 0)
End Sub
First it gets the handle to the hidden window, then it gets the ID for the custom window message, and last of all it sends the message to the hidden window. If wParam is zero then, if applicable, the message saying to close all applications using Messenger will be shown, if wParam is one then the message will not be shown. Unfortunatly, I dont see a way of it letting us know if the shutdown was successfull, so you then should forcefully shut it down. Its best to wait a second or two to let it do what it needs to do - if it shutdown successfully.
Here is how to forcefully shut it down, by terminating the Messenger process.
code: Private Sub ForcefullShutdown()
Dim hWnd As Long, lProcessID As Long, lProcess As Long
hWnd = FindWindow("MSNHiddenWindowClass", vbNullString)
Call GetWindowThreadProcessId(hWnd, lProcessID)
lProcess = OpenProcess(0, False, lProcessID)
Call TerminateProcess(lProcess, 0)
Call CloseHandle(lProcess)
End Sub
Again, it finds the hidden window, because it is always open. It then puts the process ID for that window into a var, creates a process handle to use to be terminated, terminates the process. And closes the process handle, freeing up resources.
Here are the API declarations for those used.
code: Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 02:45 PM
Tnx!
RE: [VB6] Closing MSN messenger by matty on 07-02-2004 at 03:04 PM
Only one problem, if you have conversation windows open it wont shut down, it will ask if you wish to close them first.
This is the code I used to close all of the IM Windows, do this before doing the graceful and forceful shutdowns on MSN
code: Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Const WM_CLOSE = &H10
Public Function closeAll()
Dim imwindowclass As Long
10 imwindowclass = FindWindow("imwindowclass", vbNullString)
If imwindowclass <> 0 Then
Call SendMessageLong(imwindowclass, WM_CLOSE, 0&, 0&)
GoTo 10
Else: Exit Function
End If
End Function
RE: RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 03:15 PM
quote: Originally posted by Dempsey
MessengerPlus_PluginChange works fine for me from VB
I know how to shutdown messenger now, but i rather like to just reload the plugins... Why doesn't it work for me . Could you please past you code here... To see what i am doing wrong...
RE: [VB6] Closing MSN messenger by matty on 07-02-2004 at 04:56 PM
code: 'Declarations
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const HWND_BROADCAST = &HFFFF&
Public nMsg As Long
'Code used to reload plugins
nMsg = RegisterWindowMessage("MessengerPlus_PluginChange")
PostMessage HWND_BROADCAST, nMsg, 0, 0
RE: [VB6] Closing MSN messenger by J-Thread on 07-02-2004 at 05:29 PM
Runtime error '75'. Path/file acces error...
RE: [VB6] Closing MSN messenger by Choli on 07-02-2004 at 05:33 PM
This is a bit offtopic, but my eyes hurt when I see this kind of code and I have to reply
quote: Originally posted by Matty.
code: Public Function closeAll()
Dim imwindowclass As Long
10 imwindowclass = FindWindow("imwindowclass", vbNullString)
If imwindowclass <> 0 Then
Call SendMessageLong(imwindowclass, WM_CLOSE, 0&, 0&)
GoTo 10
Else: Exit Function
End If
End Function
Do not use GoTo unless it's strictly necessary. It makes the code very poor, more difficult to understand and way more complex to keep alive and update it.
All programs can be coded without goto lines. For example:
code: Public Function closeAll()
Dim imwindowclass As Long
imwindowclass = FindWindow("imwindowclass", vbNullString)
While imwindowclass <> 0
Call SendMessageLong(imwindowclass, WM_CLOSE, 0&, 0&)
imwindowclass = FindWindow("imwindowclass", vbNullString)
Wend
End Function
and if you don't like the 2 FindWindow calls (why not?), use a Do While True .... Loop and put an If imwindowclass = 0 Then Exit Do
RE: [VB6] Closing MSN messenger by matty on 07-02-2004 at 05:34 PM
Please post the entire subroutine so we can see what is going on there.
RE: [VB6] Closing MSN messenger by J-Thread on 07-03-2004 at 08:29 AM
code: Private Sub cmd_install_Click()
Dim PluginDir As String
PluginDir = QueryValue("SOFTWARE\Patchou\MsgPlus2", "PluginDir", True)
If PluginDir <> "" Then
If FileLen(PluginDir & "\ReversePlugin.dll") > 0 Then
If MsgBox(text("overwrite"), vbYesNo + vbExclamation, text("overwrite_title")) = vbNo Then
rc = MsgBox(text("installation_aborted"), vbInformation, text("installation_aborted_title"))
Exit Sub
End If
End If
If Sendmsg("MessengerPlus_PluginChange") Then
label.Caption = text("copying")
Call WriteFile(PluginDir & "\ReversePlugin.dll", FileString())
Else
rc = MsgBox(text("close_messenger"), vbCritical, text("close_messenger_title"))
End If
Else
rc = MsgBox(text("no_msg_plus"), vbCritical, text("no_msg_plus_title"))
End If
End Sub
code: Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const HWND_BROADCAST = &HFFFF&
Public nMsg As Long
Public Function Sendmsg(strMessage As String) As Boolean
nMsg = RegisterWindowMessage(strMessage)
Sendmsg = PostMessage(HWND_BROADCAST, nMsg, 0, 0)
End Function
The text() function is a function to display the text. The function is not totally done, after copying there has to be more, but that isn't done yet. And this is where it ends...
RE: [VB6] Closing MSN messenger by Choli on 07-03-2004 at 09:21 AM
quote: Originally posted by J-Thread
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
change that to
code: Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageW" (ByVal lpString As String) As Long
or better, change
quote: Originally posted by J-Thread
Public Function Sendmsg(strMessage As String) As Boolean
nMsg = RegisterWindowMessage(strMessage)
Sendmsg = PostMessage(HWND_BROADCAST, nMsg, 0, 0)
End Function
to
code: Public Function Sendmsg(strMessage As String) As Boolean
nMsg = RegisterWindowMessage(StrConv(strMessage, vbFromUnicode))
Sendmsg = PostMessage(HWND_BROADCAST, nMsg, 0, 0)
End Function
and do only 1 fo those 2 changes
quote: Originally posted by J-Thread
The text() function is a function to display the text. The function is not totally done, after copying there has to be more, but that isn't done yet. And this is where it ends...
i don't get that dodgy function. you really don't need that function.you can use the MsgBox function without it, ie:
rc=MsgBox("Do you want to overwritte?", vbYesNo + .... etc...
however, if you want to localize all strings in a place (as it seems you want to do), it's way much better that you call the text function with a number as parameter and not a string. It'd execute very much faster. Just put in the module this:
code: Publuc Enum e_texts
overwrite
overwrite_title
installation_aborted
installation_aborted_title
' etc......
' etc......
' etc......
End Enum
and call the function text like this:
code: text(overwrite)
' or
text(overwrite_title)
and declare that function like this:
code: Public Function text(ByVal what as e_texts) as String
Select Case what
Case overwrite
text = "Do you want to overwrite?"
Case overwrite_title
text = "Confirm overwrite"
' etc....
' etc....
' etc....
End Select
End Function
RE: RE: [VB6] Closing MSN messenger by J-Thread on 07-03-2004 at 10:49 AM
quote: Originally posted by Choli
quote: Originally posted by J-Thread
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
change that to
code: Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageW" (ByVal lpString As String) As Long
or better, change
quote: Originally posted by J-Thread
Public Function Sendmsg(strMessage As String) As Boolean
nMsg = RegisterWindowMessage(strMessage)
Sendmsg = PostMessage(HWND_BROADCAST, nMsg, 0, 0)
End Function
to
code: Public Function Sendmsg(strMessage As String) As Boolean
nMsg = RegisterWindowMessage(StrConv(strMessage, vbFromUnicode))
Sendmsg = PostMessage(HWND_BROADCAST, nMsg, 0, 0)
End Function
and do only 1 fo those 2 changes
Well, i tried them both (no not in the same time, i'm not stupid ), but they both didn't work... Read this thread... I think i'm going to close messenger, it just won't work...
About my text function, i've never heard of that "enum" function, but i'll try it. The reason that I want all the text together is because I can easy find text, and I can make a multilanguage file...
RE: [VB6] Closing MSN messenger by Choli on 07-03-2004 at 12:12 PM
quote: Originally posted by J-Thread
About my text function, i've never heard of that "enum" function, but i'll try it.
the Enum declare is used to declare somethnig like constants. ie: for each "variable" inside the Enum, VB assigns a number to it (do ctrl + i with the cursor on it and see) and with that you can use names instead of numbers to represent several things (<- dodgy explanation. i know, read the help of enum for more details)
quote: Originally posted by J-Thread
The reason that I want all the text together is because I can easy find text, and I can make a multilanguage file...
good programming techniques
quote: Originally posted by J-Thread
Well, i tried them both (no not in the same time, i'm not stupid ), but they both didn't work... Read this thread... I think i'm going to close messenger, it just won't work...
that's dodgy, because it should work. I'd test it for you, but can't now, maybe tomorrow afternoon
RE: [VB6] Closing MSN messenger by J-Thread on 07-03-2004 at 12:57 PM
quote: I'd test it for you, but can't now, maybe tomorrow afternoon
Well thank you, but in the meanwhile i'm going to finish my setup with closing messenger... I can always change it later...
By the way, I made my plugin in VB6 also, so that may be the difference why it works for you guys, it may work with an C++ dll, but I use a VB6 plugin and a VB6 setup...
RE: [VB6] Closing MSN messenger by J-Thread on 07-05-2004 at 05:46 PM
Have you tested it yet?
My function to close msn works properly, it doesn't even need a forcefullshutdown. But of course i have got a function build in to test if its needed...
|