i have a program, the thing is i need it to always be on top no matter what other programs are launched! there will be no minimise option, the only time it will not be on screen is when it is closed!
how do i do this??
thanx in advance
Printable View
i have a program, the thing is i need it to always be on top no matter what other programs are launched! there will be no minimise option, the only time it will not be on screen is when it is closed!
how do i do this??
thanx in advance
You can accomplish this using the SetWindowPos API...
In a module place the following code:
Then in a function or, as in my example, the form_load event place the following code:Code:Public Const HWND_TOPMOST& = -1
Const SWP_NOMOVE& = &H2
Const SWP_NOSIZE& = &H1
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)
Code:Private Sub Form_Load()
Dim lFlags As Long
Dim lStay As Long
lFlags = SWP_NOSIZE Or SWP_NOMOVE
lStay = SetWindowPos(Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, lFlags)
End Sub
adim that question was asked a lot in the past so you can always use the Search engine in VBForums who is located to the top of that screen. Next time just search before posting and you will have a answer very fast,
Daok
Quote:
Originally posted by DaoK
adim that question was asked a lot in the past so you can always use the Search engine in VBForums who is located to the top of that screen. Next time just search before posting and you will have a answer very fast,
Daok
Lesson: (I'm sorry that I'm aiming this to you again DaoK, I know I've treated you badly before ;))Quote:
This answer has been used before.
Before you answer a question please use the search engine of these forums.
Next time you consider answering a question please make sure this answer hasn't been posted before
There is no such thing as a stupid question only stupid answers! :)
I know, I do not yell to him it's just because he is new to VBforums and I want to tell you some "feature" to optimize vbforums.com
I was only joking DaoK ;)Quote:
Originally posted by DaoK
I know, I do not yell to him it's just because he is new to VBforums and I want to tell you some "feature" to optimize vbforums.com
try this ,
Private Declare Function SetWindowPos Lib "user32" Alias "setwindowpos" (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 FormAlwaysOnTop(frm As Form, ontop As Boolean)
If ontop Then
SetWindowPos frm.hwnd, -1, (frm.Left / Screen.TwipsPerPixelX), (frm.Top / Screen.TwipsPerPixelY), (frm.Width / Screen.TwipsPerPixelX), (frm.Height / Screen.TwipsPerPixelY), 1
Else
SetWindowPos frm.hwnd, -2, (frm.Left / Screen.TwipsPerPixelX), (frm.Top / Screen.TwipsPerPixelY), (frm.Width / Screen.TwipsPerPixelX), (frm.Height / Screen.TwipsPerPixelY), 1
End If
End Sub
'frmresult is the form that 1 want to diplay it on top always and u can put your form name
Private Sub Command1_Click()
FormAlwaysOnTop frmresult, True
End Sub
;)