Ok, I searched VBWORLD, and I know how to make one form stay on top. Now if my program has more than one form, how do I make both of the forms be on top(not at the same time)
Printable View
Ok, I searched VBWORLD, and I know how to make one form stay on top. Now if my program has more than one form, how do I make both of the forms be on top(not at the same time)
what do you mean by not at the same time???
and if you want to make both of them stay on top, just do the same function again but change the name of the form, thats it
ok, I guess I didn't explain it clearly, I need one form to be visible at a time, and the form that is visible to be on top of all the other programs. Only problem is that in the code that I got, only had room for one name, if I write the code 2 times, an error message comes up
What code are you using? I think you could set several window on top but they will block each other as they all are on the same level. use setforegroundwindow api to put your window topmost
I'm using the code that I found in a
Visual Basic Programmer's Journal
'paste this into a module:
Private Declare Function SetWindowPos Lib _
"user32" (ByVal hWnd As Long, ByVal _
hWndIsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy _
As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOActivate = &H10
Public Enum WindowPos
vbtopmost = -1&
vbnottopmost = -2&
End Enum
Public Sub SetFormPosition(hWnd As Integer, _
Position As WindowPos)
Const wFlags As Long = SWP_NOMOVE Or _
SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOActivate
If Position = vbtopmost Or Position = vbnottopmost Then
SetWindowPos hWnd, Position, 0, 0, 0, 0, wFlags
End If
End Sub
'Paste this into the form load procedure for it to stay on top
SetFormPosition Me.hWnd, vbTopMost
'paste this into a command for the form not to be on top
SetFormPosition Me.hWnd, vbNotTopMost
I'm surprised they put hwnd as integer instead of long. Other than that, i would say it should work fine with multiple windows, just put their handle in the hwnd argument.
Can you please tell me what code to write? I'm not very smart
Shoudn't be that hard, just pass them like this:
Code:SetFormPosition form1.hwnd, vbtopmost
SetFormPosition form2.hwnd, vbtopmost
THANKS ALOTTTTTTT that helped me ALOT!!!