|
-
May 5th, 2006, 09:21 AM
#1
Thread Starter
Fanatic Member
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?
-
May 5th, 2006, 09:59 AM
#2
Hyperactive Member
Re: a form control question
try this
VB Code:
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Public Sub FormOnTop(hWindow As Long, bTopMost As Boolean)
' Example: Call FormOnTop(me.hWnd, True)
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
wFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
Select Case bTopMost
Case True
Placement = HWND_TOPMOST
Case False
Placement = HWND_NOTOPMOST
End Select
SetWindowPos hWindow, Placement, 0, 0, 0, 0, wFlags
End Sub
'on load of form 2
Private Sub Form_Load()
Call FormOnTop(Me.hWnd, True)
End Sub
-
May 5th, 2006, 10:18 AM
#3
Thread Starter
Fanatic Member
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?
-
May 5th, 2006, 10:20 AM
#4
Hyperactive Member
Re: a form control question
-
May 5th, 2006, 10:21 AM
#5
Addicted Member
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:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
'MakeFormTop Form2,True
'MakeFormTop Form2,False
Sub MakeFormTop(FormName As Form, WindowState As Boolean)
Dim wFlags As Long
Dim posFlag As Long
Const Swp_Nosize = &H1
Const SWP_Nomove = &H2
Const Hwnd_TopMost = -1
Const Hwnd_NoTopMost = -2
wFlags = SWP_Nomove Or Swp_Nosize
If WindowState = True Then
SetWindowPos FormName.hwnd, Hwnd_TopMost, 0, 0, 0, 0, wFlags
Else
SetWindowPos FormName.hwnd, Hwnd_NoTopMost, 0, 0, 0, 0, wFlags
End If
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]
-
May 5th, 2006, 10:59 AM
#6
Thread Starter
Fanatic Member
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?
-
May 5th, 2006, 12:29 PM
#7
Thread Starter
Fanatic Member
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:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Dim Msg ' Declare variable.
'Set the message text.
Msg = "Do you really want to exit?"
'If user clicks the No button, stop QueryUnload.
If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
Call closeAllForms
'Unload frmIntro
Cancel = False
Else
Cancel = True
End If
End If
End Sub
He who never made a mistake never made a discovery?
-
May 5th, 2006, 01:07 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|