Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    from VB to VBA (2000)

    ... how to change this command line from VB in VBA?

    ....
    'make the session a child window to the frame on the form...
    hPreviousParent = SetParent(hSession, Frame1.hWnd)
    ....


    Complete code:
    'Option Explicit
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''
    ' SetParent.vbp
    ' Visual Basic 5.0 demonstration of using the Windows API "SetParent"
    ' to make an EXTRA! session appear as a child window on a form.
    '
    ' Attachmate Developer Support 9/14/1999 (ng)
    ' Copyright 1989-1999, Attachmate Corporation. All Rights Reserved.
    ' This code is provided as an example only. It is provided as-is,
    ' without warranty or support from Attachmate Corporation.
    '
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''
    Private Sub cmdOpenSession_Click()

    'This function allows a user to choose a session to open, then uses
    'FindWindow to get the handle of the session, and then SetParent to
    'make the session a child of the frame control on the form.

    Dim SessionTitleBar As String
    Dim hSession As Long, hPreviousParent As Long
    Dim sys As Object, sess As Object

    Set sys = CreateObject("extra.system")
    If sys Is Nothing Then Exit Sub 'Yikes! EXTRA! is not installed!

    Set sess = sys.Sessions.Open() 'allow user to choose a session
    If sess Is Nothing Then Exit Sub 'User canceled file-open dialog

    'this is the default scheme EXTRA! uses to fill a session's titlebar...
    SessionTitleBar = sess.Name & " - " & sys.Name

    'get the handle to the window of the session we just opened
    hSession = FindWindow(vbNullString, SessionTitleBar)

    If hSession = 0 Then
    MsgBox "Either the requested session is already opened here, or " & vbCrLf & _
    "somehow the titlebar for the requested session was " & vbCrLf & _
    "changed from the default EXTRA! uses...", , "FindWindow failed..."
    Exit Sub
    End If

    'make the session a child window to the frame on the form...
    hPreviousParent = SetParent(hSession, Frame1.hWnd)

    'show no toolbars...unfortunately there is no API available right now
    'for hiding the menu and title bar as well...
    'sess.Toolbars.HideAll
    sess.WindowState = 2 'maximized
    sess.Visible = True

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    Where do you want to use this? In a userform, or ...?

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    In effect this is a VB code to show a 3270 terminal session in a Frame1 of the Form1... and work fine.
    Now i want to convert the code in VBA, but go in error only in line:

    'make the session a child window to the frame on the form...
    hPreviousParent = SetParent(hSession, Frame1.hWnd)

    i think because in VBA hWnd statement not existis...?!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    Do you want to use the code in a userform or in a general macro?

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    in userform...

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    Try this:

    hPreviousParent = SetParent(hSession, FindWindow("ThunderDFrame", "UserForm1"))

    Replace UserForm1 with the caption of your userform (the name in the title bar of the userform).

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    Hummmm....
    I dont know if is correct????
    Please see my new code, tks for patience.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    It looks OK, but I cannot test it because I don't have EXTRA! installed.

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    ok now work....
    But the 3270 terminal session fill entire userform...
    I want to open in frame1, is possible?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    I don't know how to get the handle of a control of a userform. It would probably involve EnumChildWindows, but that is beyond me.

  11. #11
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: from VB to VBA (2000)

    I think the controls are windowless until they have the focus, so you should be able to use something like this to get the handle:

    <pre>Private Declare Function GetFocus Lib "user32" () As Long
    Private Sub CommandButton1_Click()
    Me.Frame1.SetFocus
    FrameHandle = GetFocus
    Debug.Print FrameHandle

    End Sub
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  12. #12
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    Hi Rory but in wich part of code?

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: from VB to VBA (2000)

    Put the line

    Private Declare Function GetFocus Lib "user32" () As Long

    at the top of the userform module.

    Change the line

    hPreviousParent = SetParent(hSession, Frame1.hWnd)

    from the original code to

    Me.Frame1.SetFocus
    hPreviousParent = SetParent(hSession, GetFocus)

  14. #14
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    GENIUS!!!!!
    now work fine!
    tks too Rory!

  15. #15
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: from VB to VBA (2000)

    Hi Hans...
    But if i drag and move the terminal session in frame i can move tath.. is possible to lock that?
    tks.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •