|
-
Aug 14th, 2011, 03:01 PM
#1
Thread Starter
PowerPoster
[VB6] - multimedia activex control complied error
i build a multimedia timer control. and in groupproject works fine. but compiled gives an error and closes.
Code:
Option Explicit
Private lTimerId As Long
Event Timer()
Dim lngInterval As Long
Dim blnTimer As Boolean
Public Property Get Enabled() As Boolean
Enabled = blnTimer
End Property
Public Property Let Enabled(ByVal vNewValue As Boolean)
If lngInterval < 1 Then Exit Property
blnTimer = vNewValue
If Ambient.UserMode = False Then Exit Property
If blnTimer = True Then
If lTimerId Then
'End Current Timer
If lTimerId Then
timeKillEvent lTimerId
'KillTimer lHwnd, lTimerId
lTimerId = 0
End If
End If
lHwnd = UserControl.hwnd
lTimerId = timeSetEvent(lngInterval, 0, AddressOf TimerRoutine, 0, TIME_CALLBACK_FUNCTION Or TIME_PERIODIC)
'lTimerId = SetTimer(lHwnd, 0, lngInterval, AddressOf TimerRoutine)
ElseIf blnTimer = False Then
If lTimerId Then
timeKillEvent lTimerId
'KillTimer lHwnd, lTimerId
lTimerId = 0
End If
End If
PropertyChanged "Enabled"
End Property
Public Property Get Interval() As Long
Interval = lngInterval
End Property
Public Property Let Interval(ByVal vNewValue As Long)
If vNewValue < 0 Then vNewValue = 0
If Enabled = True Then Exit Property
lngInterval = vNewValue
If lngInterval = 0 Then Enabled = False
PropertyChanged "Interval"
End Property
Private Sub UserControl_Initialize()
UserControl.MaskPicture = UserControl.Image
UserControl.MaskColor = UserControl.Point(0, 0)
End Sub
Public Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 1000 Then
RaiseEvent Timer
End If
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Interval = PropBag.ReadProperty("Interval", 0)
Enabled = PropBag.ReadProperty("Enabled", 0)
End Sub
Private Sub UserControl_Resize()
UserControl.Width = 240
UserControl.Height = 240
End Sub
Private Sub UserControl_Terminate()
If lTimerId <> 0 Then
timeKillEvent lTimerId
'KillTimer lHwnd, lTimerId
lTimerId = 0
End If
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Interval", Interval, 0
PropBag.WriteProperty "Enabled", Enabled, 0
End Sub
and in a module:
Code:
Option Explicit
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 Declare Function timeKillEvent Lib "winmm.dll" (ByVal uId As Long) As Long
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Public Const TIME_PERIODIC = 1 ' program for continuous periodic event
Public Const TIME_CALLBACK_FUNCTION = 0
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
Public lHwnd As Long
Public Function TimerRoutine( _
ByVal wTimerID As Long, ByVal iMsg As Long, _
ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long _
) As Long
'Place your code here...
On Error Resume Next
SendMessage lHwnd, WM_KEYDOWN, 1000, 0
End Function
heres the image error ziped: http://www.megaupload.com/?d=3NMNR5M6.
please tell me something. these error happens with compiled file
-
Aug 14th, 2011, 10:15 PM
#2
Re: [VB6] - multimedia activex control complied error
In a previously related thread, I suggested you not use SendMessage in your callback function. That may be the problem...
I would suggest removing that line, recompile & test again. If it doesn't crash -- probably SendMessage. I'd also suggest you return to that vbAccelerator link I gave you and read over the section that describes which API calls you can use in that callback function.
-
Aug 15th, 2011, 06:41 AM
#3
Thread Starter
PowerPoster
Re: [VB6] - multimedia activex control complied error
 Originally Posted by LaVolpe
In a previously related thread, I suggested you not use SendMessage in your callback function. That may be the problem...
I would suggest removing that line, recompile & test again. If it doesn't crash -- probably SendMessage. I'd also suggest you return to that vbAccelerator link I gave you and read over the section that describes which API calls you can use in that callback function.
i try use the PostMessage() api function(like they said that is more stable). but i must build a class\dll or even an activex exe for don't crash. i can build a class, but let me ask you 1 thing: how can i catch the Wnd property automatic(without put a property)?
-
Aug 15th, 2011, 09:59 AM
#4
Thread Starter
PowerPoster
Re: [VB6] - multimedia activex control complied error
the main objective is for call 1 new event that i'm put it in my control.
-
Aug 16th, 2011, 09:14 AM
#5
Re: [VB6] - multimedia activex control complied error
If you are going to use a class, simply add a Property Let statement to the class so you can assign an hWnd.
In that vbAcceleator link I gave you, there was a ready-made high-resolution timer project that could be downloaded.
P.S. You also must ask yourself whether a high resolution timer is absolutely needed.
-
Aug 16th, 2011, 09:23 AM
#6
Thread Starter
PowerPoster
Re: [VB6] - multimedia activex control complied error
 Originally Posted by LaVolpe
If you are going to use a class, simply add a Property Let statement to the class so you can assign an hWnd.
In that vbAcceleator link I gave you, there was a ready-made high-resolution timer project that could be downloaded.
P.S. You also must ask yourself whether a high resolution timer is absolutely needed.
you have right. but for that i need ask 1 thing: how can i have accuracy of 1 milllisecond(for build timers like tradicional Sonic games)?
-
Aug 16th, 2011, 09:48 AM
#7
Re: [VB6] - multimedia activex control complied error
 Originally Posted by joaquim
you have right. but for that i need ask 1 thing: how can i have accuracy of 1 milllisecond(for build timers like tradicional Sonic games)?
With a VB timer or API timer, you are not going to get that accuracy. Best case with those timers may be about 10 ms. Also standard timers are low priority; there is no guarantee every timer event will be triggered (some may be skipped depending on running code) and other timer events may be delayed for the same reason
-
Aug 16th, 2011, 01:47 PM
#8
Thread Starter
PowerPoster
Re: [VB6] - multimedia activex control complied error
 Originally Posted by LaVolpe
With a VB timer or API timer, you are not going to get that accuracy. Best case with those timers may be about 10 ms. Also standard timers are low priority; there is no guarantee every timer event will be triggered (some may be skipped depending on running code) and other timer events may be delayed for the same reason
but - only for ask- the directx can do it, right?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|