Timer from a form |
Author: |
Message: |
TheCodeSmith
Junior Member
Posts: 15
Joined: Jul 2004
|
O.P. Timer from a form
I have a form that is called from my plugin in VB6 (thanks guys), how can i put a timer on the form that is able to trigger every 5 seconds, that will be able to use msgplus functions/commands such as /nick or /brb?
This post was edited on 07-10-2004 at 08:39 PM by TheCodeSmith.
|
|
07-10-2004 08:32 PM |
|
|
dotNorma
Veteran Member
Posts: 1745 Reputation: 17
33 / / –
Joined: May 2003
|
RE: Timer from a form
Make a timer.
Set the interval to "5000" (Its in miliseconds)
Make sure you enable the timer.
Make the timer code be
code: Private Sub Timer1_Timer()
sResult = "/nick NoName"
End Sub
|
|
07-10-2004 08:53 PM |
|
|
Stigmata
Veteran Member
Posts: 3520 Reputation: 45
21 / /
Joined: Jul 2003
|
RE: Timer from a form
code: private sub form_load()
timer1.invertal = 5000
end sub
private sub timer1_timer ()
send message /nick
timer1.interval = 5000
end sub
or along the lines of
This post was edited on 07-10-2004 at 09:07 PM by Stigmata.
|
|
07-10-2004 08:54 PM |
|
|
Millenium_edition
Veteran Member
Posts: 1787 Reputation: 57
Joined: Apr 2003
|
RE: Timer from a form
noname, read what he asked. Changing a variable sResult will not change a thing
jwb, your code is *excuse me for the word* crap
TheCodeSmith, you can't just trigger commands. You have to wait for msgplus to call events. Only then you can use them, unless you do it manually
|
|
07-10-2004 10:53 PM |
|
|
TheCodeSmith
Junior Member
Posts: 15
Joined: Jul 2004
|
O.P. RE: Timer from a form
quote: Originally posted by Millenium_edition
TheCodeSmith, you can't just trigger commands. You have to wait for msgplus to call events. Only then you can use them, unless you do it manually
Ah right, so i can't even use an API to trigger something every X seconds?
I'm beginning to think i should just start making my own pure MSN plugin, rather than a plugin that is run through MSN plus events and restrictions.
What i need is, something that you can start by typing for example "/xblah", then at an interval of 5 seconds i'd need to call one of the MSN functions, i.e change nick.
I'll try and find out how to use the MSN API directly from a VB app, i've tried before but haven't ever been able to get it working, not even slightly.
This post was edited on 07-11-2004 at 01:48 AM by TheCodeSmith.
|
|
07-11-2004 01:46 AM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
TheCodeSmith
Junior Member
Posts: 15
Joined: Jul 2004
|
O.P. RE: Timer from a form
Matty, that's a great help mate, but whilst it's doing the sleep call, it hangs MSN completely for the 5000ms to elapse, then it continues. That's one reason why i've never liked using the Sleep API call.
Isn't there any other way to perform a 5 second delay, after which some code is executed, which is then triggered every 5 seconds? Not just once.
|
|
07-11-2004 03:36 AM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Timer from a form
A do while loop with doevents in the middle
|
|
07-11-2004 04:01 AM |
|
|
Mnjul
forum super mod
plz wub me
Posts: 5396 Reputation: 58
– / /
Joined: Nov 2002
Status: Away
|
RE: Timer from a form
quote: Originally posted by Matty.
A do while loop with doevents in the middle
That doesn't sound good Matty...
Well, TheCodeSmith, search for APIs about SetTimer and callback functions
For example...
code: Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Public TimerEvent As Long
code: TimerEvent = SetTimer(0, 0, 5000, AddressOf TimerProc_Process) 'Set a timer to fire after 5 seconds - it calls TimerProc_Process on firing
code: Public Sub TimerProc_Process(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
'Do something you want
End Sub
You need to kill the timer using this when you no longer needs it.
code: KillTimer 0, TimerEvent
TimerProc_Process will be triggered every 5 seconds.
This post was edited on 07-11-2004 at 04:37 AM by Mnjul.
|
|
07-11-2004 04:27 AM |
|
|
TheCodeSmith
Junior Member
Posts: 15
Joined: Jul 2004
|
O.P. RE: Timer from a form
Mnjul, that works great.
Now, inside that timerproc, am i able to send/post a /nick Blah command to an Msn plus chat window?
This post was edited on 07-11-2004 at 05:21 AM by TheCodeSmith.
|
|
07-11-2004 05:19 AM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|
|