Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Using 'SetParent' function in VB 2008

Using 'SetParent' function in VB 2008

Scheduled Pinned Locked Moved Visual Basic
questionhelpjsoncareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Filippo1974
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • F Filippo1974

      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

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      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

      F 1 Reply Last reply
      0
      • N nlarson11

        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

        F Offline
        F Offline
        Filippo1974
        wrote on last edited by
        #3

        Yes! It works exactly as I need. Thank you wery much for you suggestion! Filippo

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups