Results 1 to 11 of 11

Thread: form above form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Location
    Sesimbra, Portugal
    Posts
    145

    form above form

    hey guys, i need some basic help. i've the main form and when i click a buttom a small form is displayed. But when i accidently click on the main form the smallest form hides behind the main. My main form is fixed and not moveble, because i want it like that. How can i do to set the small form above the main form until i press cancel button.???

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form above form

    show the small form modally:
    VB Code:
    1. frmSmall.Show vbModal

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Location
    Sesimbra, Portugal
    Posts
    145

    Re: form above form

    One problem.. the small form is mdichild....

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Location
    Sesimbra, Portugal
    Posts
    145

    Re: form above form

    solved, i set it to not show in taskbar and remove MDIChild
    thks alot

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form above form

    no probs, an alternative would have been to use the SetParent API, and place the small form inside the "main" form (i presume that is also a MDIChild)

  6. #6
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: form above form

    This is exactly what I want but can someone explain to me what I need to do to get it happening? I would like a form to be restricted to (or is inside) the main form so that when I press the minimise button the child form goes with it?

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form above form

    VB Code:
    1. Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4.     SetParent frmChild.hWnd, frmMain.hWnd
    5. End Sub

  8. #8
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: form above form

    Nice. Thankyou.

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962

    Re: form above form

    If you use the SetParent API, the forms will not high-light properly when selected. If you want to fix this, you have to sub-class out the forms. I can provide the code, however I will also warn you that if you do so, you can no longer debug the program while using the VB IDE, or you will almost always lock-up VB. This means you can not use the pause or step buttons or breakpoints once you begin the sub-classing. All debugging MUST be done though logs (and I would recommend that you compile to an EXE and execute the EXE instead of using the VB run command to make sure you don't accidently pause the program).
    Involved in: Sentience

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form above form

    here's a class from vbAccelerator which (in collaboration with the SSubTmr6.dll) can sort out the active titlebar thing

  11. #11
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962

    Re: form above form

    Or you can just use this code:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    6. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    7.  
    8. Private mdiChildren As New Collection
    9.  
    10. Private Const WM_ACTIVATE = &H6
    11. Private Const GWL_WNDPROC = (-4)
    12.  
    13. Private lngMasterWindowProc As Long
    14. Private lngMasterWindowHWnd As Long
    15.  
    16. Public Function WindowProc_Child(ByVal hWnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    17.     'Handle the messages that Windows sends
    18.     Select Case MSG
    19.         Case WM_ACTIVATE
    20.             'When Windows tells us the window is activated, notify the parent window of the activation
    21.             CallWindowProc lngMasterWindowProc, hWnd, MSG, wParam, lParam
    22.     End Select
    23.  
    24.     'Call the standard Windows procedure of the child
    25.     WindowProc_Child = CallWindowProc(mdiChildren.Item("x" & hWnd), hWnd, MSG, wParam, lParam)
    26. End Function
    27.  
    28. Public Sub InitializeSubclassing(MasterWindowHWnd As Long)
    29.     'Get the Windows Proc of the master window
    30.     lngMasterWindowProc = GetWindowLong(MasterWindowHWnd, GWL_WNDPROC)
    31.  
    32.     'Store the HWND for our usage later
    33.     lngMasterWindowHWnd = MasterWindowHWnd
    34. End Sub
    35.  
    36. Public Sub MakeMDIChild(ChildWindowHWnd As Long)
    37.     'Record the old windows proc for the MDI child.
    38.     mdiChildren.Add GetWindowLong(ChildWindowHWnd, GWL_WNDPROC), ("x" & ChildWindowHWnd)
    39.  
    40.     'Begin subclassing the new child window
    41.     SetWindowLong ChildWindowHWnd, GWL_WNDPROC, AddressOf WindowProc_Child
    42.  
    43.     'Set the parent of the child, making it a MDI child window
    44.     SetParent ChildWindowHWnd, lngMasterWindowHWnd
    45. End Sub
    46.  
    47. Public Sub RemoveMDIChild(ChildWindowHWnd As Long)
    48.     'Reset the child window's windows proc to its default, removing our subclassing
    49.     SetWindowLong ChildWindowHWnd, GWL_WNDPROC, mdiChildren.Item(("x" & ChildWindowHWnd))
    50.  
    51.     'Remove the record of the MDI child
    52.     mdiChildren.Remove ("x" & ChildWindowHWnd)
    53. End Sub

    It must be placed into a non-class module (although it could be adapted to a class module, if you wanted to).

    The first call should be to the InitializeSubclassing function. Once that is called, any number of calls may be made to the MakeMDIChild and RemoveMDIChild functions. The forms must be loaded prior to the calls, and the forms must be unloaded after a call to the RemoveMDIChild function.

    I could continue to improve the code, but the main program I am using it in has a ton of other functions required for the calls anyways.
    Involved in: Sentience

Posting Permissions

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



Click Here to Expand Forum to Full Width