Using 'SetParent' function in VB 2008
-
Hi all, I'm new into the forum and I have a question for you. How can I use the Win API 'SetParent' under VB 2008 to open a secondary form into a picturebox on a primary form? I need this because I want simulate a MDI form. For VB6 I used the following code and It works fine: '<> Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long '<> Public Function SetParentInRect(FormChild As Variant, FormParent As Variant) On Error GoTo ErrorHandler Dim lChild As Long Dim lParent As Long On Error Resume Next If IsObject(FormChild) Then lChild = CallByName(FormChild, "hwnd", VbGet) If lChild = 0 Then Err.Raise 1000, , "Cannot obtain handle from formchild" Else lChild = CLng(FormChild) End If If IsObject(FormParent) Then lParent = CallByName(FormParent, "hwnd", VbGet) If lParent = 0 Then Err.Raise 1000, , "Cannot obtain handle from formparent" If TypeName(FormParent) = "MdiMain" Then lParent = FindWindowEx(lParent, 0&, "MDIClient", vbNullString) End If If TypeName(FormParent) = "frmMain" Then lParent = FormParent.picContainer.hWnd End If Else lParent = CLng(FormParent) End If If Not IsWindow(lChild) Then Err.Raise 1000, , "Invalid form Handle : " & lChild If Not IsWindow(lParent) Then Err.Raise 1000, , "Invalid form Handle : " & lParent SetParent lChild, lParent If False Then ErrorHandler: Err.Raise Err.Number, IIf(Len(Err.Source) > 0, Err.Source & "->", "") & "clsParent", Err.Description End If End Function The sencondary form have the follwing property: startupposition = manual borderstyle = none windowsstate = maximized Is there anyone can help me (to translate this function in VB 2008)? Thanks a lot, Filippo
-
Hi all, I'm new into the forum and I have a question for you. How can I use the Win API 'SetParent' under VB 2008 to open a secondary form into a picturebox on a primary form? I need this because I want simulate a MDI form. For VB6 I used the following code and It works fine: '<> Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long '<> Public Function SetParentInRect(FormChild As Variant, FormParent As Variant) On Error GoTo ErrorHandler Dim lChild As Long Dim lParent As Long On Error Resume Next If IsObject(FormChild) Then lChild = CallByName(FormChild, "hwnd", VbGet) If lChild = 0 Then Err.Raise 1000, , "Cannot obtain handle from formchild" Else lChild = CLng(FormChild) End If If IsObject(FormParent) Then lParent = CallByName(FormParent, "hwnd", VbGet) If lParent = 0 Then Err.Raise 1000, , "Cannot obtain handle from formparent" If TypeName(FormParent) = "MdiMain" Then lParent = FindWindowEx(lParent, 0&, "MDIClient", vbNullString) End If If TypeName(FormParent) = "frmMain" Then lParent = FormParent.picContainer.hWnd End If Else lParent = CLng(FormParent) End If If Not IsWindow(lChild) Then Err.Raise 1000, , "Invalid form Handle : " & lChild If Not IsWindow(lParent) Then Err.Raise 1000, , "Invalid form Handle : " & lParent SetParent lChild, lParent If False Then ErrorHandler: Err.Raise Err.Number, IIf(Len(Err.Source) > 0, Err.Source & "->", "") & "clsParent", Err.Description End If End Function The sencondary form have the follwing property: startupposition = manual borderstyle = none windowsstate = maximized Is there anyone can help me (to translate this function in VB 2008)? Thanks a lot, Filippo
something like this?
PictureBox1.Controls.Add(New Form2 With {.TopLevel = False, .Visible = True, .Dock = DockStyle.Fill})
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
something like this?
PictureBox1.Controls.Add(New Form2 With {.TopLevel = False, .Visible = True, .Dock = DockStyle.Fill})
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
Yes! It works exactly as I need. Thank you wery much for you suggestion! Filippo