What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » Timer from a form

Timer from a form
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Timer from a form
You don't NEED to use the Messenger Plus! API.

Code to call the event in the plugin.
code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
    If (StrComp(LCase(sCommand), "/xsample", vbTextCompare) = 0) Then
        sResult = ""
        DoEvents
        Sleep 5000
        SendText "/nick " & MyNickName, True, True
        If SendText = True then
                Sleep 5000
                SendText "/brb", True, True
        End If

        ParseCommand = True
        Exit Function
    End If
    ParseCommand = False
End Function

Declarations in the Module
code:
Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 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 Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Const VK_RETURN = &HD
Public Const WM_CHAR = &H102
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101

Public hDirectUI As Long
Public hPrevWnd As Long
Public i As Integer
Public imwindowclass As Long

Module Code
code:
Public Sub SendText(sText As String, Optional bSend As Boolean = False, Optional bKeepFocus As Boolean = True) As Boolean

imwindowclass = FindWindow("imwindowclass", vbNullString)
If imwindowclass = 0 Then MsgBox "A conversation window needs to be open before setting text.", vbInformation + vbOKOnly, "Error:": SendText = False: Exit Sub
hDirectUI = FindWindowEx(imwindowclass, 0, "DirectUIHWND", vbNullString)
hPrevWnd = GetForegroundWindow
   
'This bit idles code execution until the window is in focus
'the IM window must be in focus to recieve WM_CHAR notifications
    Do
        Call SetForegroundWindow(hDirectUI)
    Loop Until GetForegroundWindow = hDirectUI
   
'Post each character
    For i = 1 To Len(sText)
        Call PostMessage(hDirectUI, WM_CHAR, Asc(Mid(sText, i, 1)), 0)
    Next i

'Simulate the enter key being pressed if necessary
    If bSend Then
        Call PostMessage(hDirectUI, WM_KEYDOWN, VK_RETURN, 0&)
        Call PostMessage(hDirectUI, WM_KEYUP, VK_RETURN, 0&)
       
    End If

'If the window is not wanted to be kept in focus then bring back the previous
    If Not bKeepFocus Then
        Call SetForegroundWindow(hPrevWnd)
    End If
        SendText = True
End Sub

Yes I know its a lot of code but it would do the job, unless they dont have any conversation windows open
07-11-2004 02:14 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Timer from a form - by TheCodeSmith on 07-10-2004 at 08:32 PM
RE: Timer from a form - by dotNorma on 07-10-2004 at 08:53 PM
RE: Timer from a form - by Stigmata on 07-10-2004 at 08:54 PM
RE: Timer from a form - by Millenium_edition on 07-10-2004 at 10:53 PM
RE: Timer from a form - by TheCodeSmith on 07-11-2004 at 01:46 AM
RE: Timer from a form - by matty on 07-11-2004 at 02:14 AM
RE: Timer from a form - by TheCodeSmith on 07-11-2004 at 03:36 AM
RE: Timer from a form - by matty on 07-11-2004 at 04:01 AM
RE: Timer from a form - by Mnjul on 07-11-2004 at 04:27 AM
RE: Timer from a form - by TheCodeSmith on 07-11-2004 at 05:19 AM
RE: Timer from a form - by Mnjul on 07-11-2004 at 05:32 AM
RE: Timer from a form - by Mike on 07-11-2004 at 08:10 AM
RE: Timer from a form - by Stigmata on 07-11-2004 at 08:28 AM
RE: Timer from a form - by Millenium_edition on 07-11-2004 at 08:53 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On