Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Form bring to front 3

Status
Not open for further replies.

SYTEK

Programmer
Apr 26, 2002
17
0
0
GB
I have a form that resides off screen until activated by an incomming phone call. If another application is in front of the vb form then the form slides out under the foreground application.

How can i make my form the foreground application.

Thanks in anticipation
 
Drop this code into a module

#If Win16 Then
Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal X As Integer, _
ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer)

#Else
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

#End If


Global Const SWP_NOMOVE = 2
Global Const SWP_NOSIZE = 1
Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2

Sub Make_Window_TopMost(ByRef rfrmForm As Form, _
ByVal vboolOn As Boolean)


#If Win32 Then
Dim lngReturn As Long
#End If

If (vboolOn = True) Then
'make window topmost
#If Win16 Then

'16 bit
SetWindowPos rfrmForm.hWnd, HWND_TOPMOST, _
0, 0, 0, 0, FLAGS
#Else

'32 bit
lngReturn = SetWindowPos(rfrmForm.hWnd, HWND_TOPMOST, _
0, 0, 0, 0, FLAGS)
#End If

Else
'turn off topmost effect
#If Win16 Then

'16 bit
SetWindowPos rfrmForm.hWnd, HWND_NOTOPMOST, _
0, 0, 0, 0, FLAGS
#Else

'32 bit
lngReturn = SetWindowPos(rfrmForm.hWnd, HWND_NOTOPMOST, _
0, 0, 0, 0, FLAGS)
#End If
End If

End Sub


Call the 'Make_Window_TopMost' function with the form name when you need to. Hope this helps Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Foada - Would there be anything wrong with using BringWindowToTop (from API) on the form's hwnd property?
 
mmilan,

No, this was just some code that I had laying around so I just copied and pasted it quick. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
mmilan,

Let me restate that. The code I posted keeps the window on top of everything regardless of the other activity. I assumed that it was a third party app that was on top of the desired form. If all the apps running are yours you can control the positions with the BringWindowToTop. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Yes it was a 3rd party App

Well presumed

thanks for the help
 
Well normally assumption is the mother of all screw ups but there always has to be the one exception! [cannon][dazed] Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top