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
Re: a form control question
Does the first part of your code gon in the first form, or in a module?
Re: a form control question
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
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 :)
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
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.)