Results 1 to 8 of 8

Thread: a form control question

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    a form control question

    I have two forms, the first form has a Drive, Dir and File box. When I click inside the File box, it loads the 2nd form. The second form is now on top of the first in a space that I have provided for on the 1st form.

    If I click inside the File box on the 1st form again, the 2nd form gets placed behind the 1st form.

    How can I have the 1st form maintian focus and have the 2nd form always visible?
    He who never made a mistake never made a discovery?

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: a form control question

    try this
    VB Code:
    1. Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
    2.     ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
    3.     ByVal cy As Long, ByVal wFlags As Long) As Long
    4.  
    5.  
    6. Public Sub FormOnTop(hWindow As Long, bTopMost As Boolean)
    7. ' Example: Call FormOnTop(me.hWnd, True)
    8.     Const SWP_NOSIZE = &H1
    9.     Const SWP_NOMOVE = &H2
    10.     Const SWP_NOACTIVATE = &H10
    11.     Const SWP_SHOWWINDOW = &H40
    12.     Const HWND_TOPMOST = -1
    13.     Const HWND_NOTOPMOST = -2
    14.    
    15.     wFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
    16.    
    17.     Select Case bTopMost
    18.     Case True
    19.         Placement = HWND_TOPMOST
    20.     Case False
    21.         Placement = HWND_NOTOPMOST
    22.     End Select
    23.    
    24.  
    25.     SetWindowPos hWindow, Placement, 0, 0, 0, 0, wFlags
    26. End Sub
    27.  
    28. 'on load of form 2
    29. Private Sub Form_Load()
    30. Call FormOnTop(Me.hWnd, True)
    31. End Sub

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: a form control question

    Does the first part of your code gon in the first form, or in a module?
    He who never made a mistake never made a discovery?

  4. #4
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: a form control question

    in a module

  5. #5
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: a form control question

    Hey Navarone,

    Having 1 form always over another form seems a bit unusual. Is there a reason why you don't have everything on one form and then just make the Form2 stuff visible ?

    If what you are doing requires 2 forms, then here's the code I use to make a form always on top.
    VB Code:
    1. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
    2. ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
    3.  ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    4.  
    5. 'MakeFormTop Form2,True
    6. 'MakeFormTop Form2,False
    7.  
    8. Sub MakeFormTop(FormName As Form, WindowState As Boolean)
    9.     Dim wFlags As Long
    10.     Dim posFlag As Long
    11.  
    12.     Const Swp_Nosize = &H1
    13.     Const SWP_Nomove = &H2
    14.     Const Hwnd_TopMost = -1
    15.     Const Hwnd_NoTopMost = -2
    16.    
    17.     wFlags = SWP_Nomove Or Swp_Nosize
    18.  
    19.     If WindowState = True Then
    20.         SetWindowPos FormName.hwnd, Hwnd_TopMost, 0, 0, 0, 0, wFlags
    21.     Else
    22.         SetWindowPos FormName.hwnd, Hwnd_NoTopMost, 0, 0, 0, 0, wFlags
    23.     End If
    24.  
    25. End Sub
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  6. #6

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: a form control question

    Form 2 has a shockwave component in it. Having 2 forms is the only method I found for loading more then one movie into the shockwave component. Reference this thread: http://www.vbforums.com/showthread.php?t=402914
    He who never made a mistake never made a discovery?

  7. #7

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: a form control question

    hey guys

    I managed with both of your codes to keep the 2nd frm on top, however when I go to close the main form I have issue. The 2nd frm border style is set to none. When I close the application I use the following code but I never see the message box.

    If I set the 2nd form border to "fixed single", and I close the application, the message box shows up.

    What's happening here. Does anyone know?

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     If UnloadMode = 0 Then
    3.             Dim Msg   ' Declare variable.
    4.             'Set the message text.
    5.             Msg = "Do you really want to exit?"
    6.             'If user clicks the No button, stop QueryUnload.
    7.             If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
    8.                 Call closeAllForms
    9.                 'Unload frmIntro
    10.                 Cancel = False
    11.             Else
    12.                 Cancel = True
    13.             End If
    14.         End If
    15.        
    16. End Sub
    He who never made a mistake never made a discovery?

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: a form control question

    Form2 is topmost. Either close Form2 first, or make it not topmost before displaying the message box. (Or use any of the many custom message boxes that can be set to be on top.)

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