hola amigos perdon por revivir un tema de hace dos meses tengo una duda coco me hizo el grandisimo favor modificar el codigo para incrustar un form en picturebox y realizo el de limpiar dicho picture de los form incrustados, todo quedo perfecto, ahora tengo una duda es posible incrustar un form en el picturebox cuando desde el form desde donde se desea realizar dicha incrustacion ha sido mostrado en forma modal. agradecere cualquier opinion o sugerencias gracias de antemano saludos
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndParent As Long) As Long
Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function SetPropA Lib "user32.dll" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function GetPropA Lib "user32.dll" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long)
Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Function ObjFromPtr(ByVal pObj As Long) As Object
Dim obj As Object
' force the value of the pointer into the temporary object variable
CopyMemory obj, pObj, 4
' assign to the result (this increments the ref counter)
Set ObjFromPtr = obj
' manually destroy the temporary object variable
' (if you omit this step you'll get a GPF!)
CopyMemory obj, 0&, 4
End Function
Public Sub EmbeddForm(ByRef frmChild As Form, ByRef El_PictureBox As PictureBox)
With frmChild
Call SetPropA(.hwnd, "OldParent", GetParent(.hwnd))
'Lo metemos dentro del Picture1
Call SetParent(.hwnd, El_PictureBox.hwnd)
'Mostramos el Form2
Call .Show
'Maximizamos el Formualrio incrustado dentro del Picture
.WindowState = vbMaximized
End With
End Sub
Public Sub ReleaseForm(ByRef El_Formulario As Form)
Call SetParent(El_Formulario.hwnd, _
GetPropA(El_Formulario.hwnd, "OldParent"))
End Sub
Public Sub CloseAllForms(ByRef picContainer As PictureBox)
Call EnumChildWindows(picContainer.hwnd, _
AddressOf EnumChildProc, _
ObjPtr(picContainer))
End Sub
Private Function GetFormFromhWnd(ByVal lhWnd As Long, _
ByRef frmRes As Form) As Boolean
For Each frmRes In VB.Forms
If frmRes.hwnd = lhWnd Then
GetFormFromhWnd = True
Exit Function
End If
Next
End Function
Private Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim frmChild As Form
If GetFormFromhWnd(hwnd, frmChild) Then
Unload frmChild
End If
End Function