ActiveX generic fix

After reading my article on dealing with non-responding ActiveX controls, Carlos Alloatti came up with a generic fix for the problem:

*!* Enable ActiveX Windows


Define GW_CHILD 5

Define GW_HWNDNEXT 2

Declare Integer GetWindow In win32api As apiGetWindow ;
Integer nhWnd, ;
Integer uCmd

Declare Integer RealGetWindowClass In win32api ;
As apiRealGetWindowClass ;
Integer nhWnd, ;
String @pszType, ;
Integer cchType

Declare Integer EnableWindow In win32api As apiEnableWindow ;
Integer nhWnd, ;
Integer bEnable

Local ;
m.lnChildHWnd As Integer, ;
m.lnCmd As Integer, ;
m.lnEnable As Integer, ;
m.lcClassName As String, ;
m.lnBufferLen As Integer

*!* For testing, change m.lnEnable to 0 to
*!* disable OleControl windows
m.lnEnable = 1

If Thisform.ShowWindow = 2 Or Thisform.ScrollBars > 0 Then
m.lnChildHWnd = apiGetWindow(Thisform.HWnd, GW_CHILD)
Else
m.lnChildHWnd = Thisform.HWnd
Endif

m.lnCmd = GW_CHILD

Do While .T.
m.lnChildHWnd = apiGetWindow(m.lnChildHWnd, m.lnCmd)

If m.lnChildHWnd = 0 Then
Exit
Endif

m.lcClassName = Space(254)
m.lnBufferLen = apiRealGetWindowClass(m.lnChildHWnd, ;
@m.lcClassName, Len(m.lcClassName))
m.lcClassName = Left(m.lcClassName , m.lnBufferLen)

If m.lcClassName == "CtlFrameWork_ReflectWindow" Then
apiEnableWindow(m.lnChildHWnd, m.lnEnable)
Endif

m.lnCmd = GW_HWNDNEXT
Enddo