Rocco
29-09-2010, 21:14
I'm trying to use the Windows Media Player in ThinBasic (beta 1.8.6.0), I based my script on "ThinGames", also in this forum.
I know that COM/ActiveX support is not complete, but I'm trying to understand why this script doesn't work with the latest Media Player. When I try to call any method or set property, the application crashes. Maybe it's a problem with threading or other...
Any help?
Uses "UI"
Uses "COM"
Declare Function UnregisterClass Lib "USER32.DLL" Alias "UnregisterClassA" (ByVal lpClassName As Asciiz, ByVal hInstance As DWord) As Long
Declare Function GetModuleHandle Lib "KERNEL32.DLL" Alias "GetModuleHandleA" (ByVal lpModuleName As Asciiz) As DWord
Declare Function AtlAxWinInit Lib "ATL.DLL" Alias "AtlAxWinInit" () As Long
Declare Function AtlAxGetControl Lib "ATL.DLL" Alias "AtlAxGetControl" (ByVal hControl As DWord, ByRef pObject As DWord) As Long
Function AtlAxWinTerm () As Long
UnregisterClass ("AtlAxWin", GetModuleHandle(%NULL))
End Function
Dim Msg As Long
Dim wParam As Long
Dim lParam As Long
Dim hDlg As Long
Dim wx, hy As Long
Dim hCtrl As Long
%Max_Param = 3
Dim vParam(%Max_Param) As Variant
%ID_OCX = 1001
%ID_BUTTON = 1002
Dim oMediaPlayer As DWord
$CLASS = "WMPlayer.OCX"
AtlAxWinInit
Dialog New 0, "Media Player", -1, -1, 220, 300, %DS_CENTER, 0 To hDlg
Control Add "AtlAxWin", hDlg, %ID_OCX, $CLASS, 10, 50, 200, 200, %WS_CHILD Or %WS_VISIBLE
Control Add Button hDlg, %ID_BUTTON, "Play", 10, 10, 50, 25, Call onClick
Dialog Get Client hdlg To wx, hy
Control Set Resize hDlg, %ID_OCX, 1, 1, 1, 1
Control Handle hDlg, %ID_OCX To hCtrl
AtlAxGetControl(hCtrl, oMediaPlayer)
Dialog Show Modeless hDlg
While IsWindow(hDlg)
Msg = GetMessage(hDlg, wParam, lParam)
Select Case Msg
Case %WM_INITDIALOG
Case %WM_COMMAND
Case %WM_SYSCOMMAND
Select Case wParam
Case %SC_CLOSE
Exit While
End Select
Case Else
End Select
Wend
Dialog End hDlg
AtlAxWinTerm
CallBack Function onClick()
If CBMSG = %WM_COMMAND Then
Select Case CBCTLMSG
Case %BN_CLICKED
If CBCTL = %ID_BUTTON Then
vParam(1) = "http://www.mididatabase.com/20100702/punk/ramones/I_Wanna_Be_Sedated.mid"
COM_EXECUTE(oMediaPlayer, "Url", %TB_DISPATCH_PROPERTYPUT, 1, vParam, 0)
End If
End Select
End If
End Function
I know that COM/ActiveX support is not complete, but I'm trying to understand why this script doesn't work with the latest Media Player. When I try to call any method or set property, the application crashes. Maybe it's a problem with threading or other...
Any help?
Uses "UI"
Uses "COM"
Declare Function UnregisterClass Lib "USER32.DLL" Alias "UnregisterClassA" (ByVal lpClassName As Asciiz, ByVal hInstance As DWord) As Long
Declare Function GetModuleHandle Lib "KERNEL32.DLL" Alias "GetModuleHandleA" (ByVal lpModuleName As Asciiz) As DWord
Declare Function AtlAxWinInit Lib "ATL.DLL" Alias "AtlAxWinInit" () As Long
Declare Function AtlAxGetControl Lib "ATL.DLL" Alias "AtlAxGetControl" (ByVal hControl As DWord, ByRef pObject As DWord) As Long
Function AtlAxWinTerm () As Long
UnregisterClass ("AtlAxWin", GetModuleHandle(%NULL))
End Function
Dim Msg As Long
Dim wParam As Long
Dim lParam As Long
Dim hDlg As Long
Dim wx, hy As Long
Dim hCtrl As Long
%Max_Param = 3
Dim vParam(%Max_Param) As Variant
%ID_OCX = 1001
%ID_BUTTON = 1002
Dim oMediaPlayer As DWord
$CLASS = "WMPlayer.OCX"
AtlAxWinInit
Dialog New 0, "Media Player", -1, -1, 220, 300, %DS_CENTER, 0 To hDlg
Control Add "AtlAxWin", hDlg, %ID_OCX, $CLASS, 10, 50, 200, 200, %WS_CHILD Or %WS_VISIBLE
Control Add Button hDlg, %ID_BUTTON, "Play", 10, 10, 50, 25, Call onClick
Dialog Get Client hdlg To wx, hy
Control Set Resize hDlg, %ID_OCX, 1, 1, 1, 1
Control Handle hDlg, %ID_OCX To hCtrl
AtlAxGetControl(hCtrl, oMediaPlayer)
Dialog Show Modeless hDlg
While IsWindow(hDlg)
Msg = GetMessage(hDlg, wParam, lParam)
Select Case Msg
Case %WM_INITDIALOG
Case %WM_COMMAND
Case %WM_SYSCOMMAND
Select Case wParam
Case %SC_CLOSE
Exit While
End Select
Case Else
End Select
Wend
Dialog End hDlg
AtlAxWinTerm
CallBack Function onClick()
If CBMSG = %WM_COMMAND Then
Select Case CBCTLMSG
Case %BN_CLICKED
If CBCTL = %ID_BUTTON Then
vParam(1) = "http://www.mididatabase.com/20100702/punk/ramones/I_Wanna_Be_Sedated.mid"
COM_EXECUTE(oMediaPlayer, "Url", %TB_DISPATCH_PROPERTYPUT, 1, vParam, 0)
End If
End Select
End If
End Function