Matt,
Further to the subclassing issue eventually I got it to work and managed to kill my usercontrol.
Unfortunately MJ is still in the background
For example:
1) Starting from a clean copy of the BusyBox sample create a new usercontrol and paste in the following into it's code section:
Option Explicit
Dim m_oObject As Object
Public Property Set MyObject(ctl As Object)
Set m_oObject = ctl
End Property
Private Sub UserControl_Initialize()
MsgBox UserControl.Name & "::Initialize"
End Sub
Private Sub UserControl_Terminate()
Set m_oObject = Nothing
MsgBox UserControl.Name & "::Terminate"
End Sub
2) Paste the control onto the busybox control.
3) In the busybox code remove the existing Init function and add in the following code:
Public Sub Unload()
MsgBox "BusyBox::Unload Before"
Set UserControl11.MyObject = Nothing
MsgBox "BusyBox::Unload After"
End Sub
Public Function Init(ByVal MediaJukebox As Object)
Set g_MJ = MediaJukebox
Set g_Interface = Me
window_Subclass UserControl.hWnd
Set UserControl11.MyObject = frmMixer
End Function
4) Create a new module and add in the following code:
Option Explicit
Public g_Interface As BusyBox.BusyBoxCtrl
Dim hWndNew As Long
Dim pfnOldProc As Long
Public Const WM_DESTROY = &H2
Public Const GWL_WNDPROC = (-4)
Public Declare Function SetWindowLongApi Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" _
(ByVal dwExStyle As Long, _
ByVal lpClassName As String, _
ByVal lpWindowName As String, _
ByVal dwStyle As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hWndParent As Long, _
ByVal hMenu As Long, _
ByVal hInstance As Long, _
lpParam As Any) As Long
Public Function CallbackWindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_DESTROY
MsgBox "WM_DESTROY"
g_Interface.Unload
Set g_Interface = Nothing
End Select
CallbackWindowProc = CallWindowProc(pfnOldProc, hWnd, wMsg, wParam, lParam)
End Function
Public Sub window_Subclass(ByVal hWnd As Long)
Dim hWndMJ As Long
hWndNew = CreateWindowEx(0, "STATIC", "", 0, 0, 0, 0, 0, hWnd, 0, App.hInstance, ByVal 0)
If hWndNew <> 0 Then
MsgBox "hWndNew=" & hWndNew
pfnOldProc = SetWindowLongApi(hWndNew, GWL_WNDPROC, AddressOf CallbackWindowProc)
If pfnOldProc <> 0 Then
MsgBox "Subclassed"
End If
End If
End Sub
Now when you run the sample, open up busybox and terminate MJ you will see that WM_DESTROY is called and the usercontrol's terminate function is called but still the MJ process is in the background.
Am I doing something wrong?
Rhino.