Jun 20th, 2005, 03:00 PM
#1
Thread Starter
Addicted Member
[resoloved]Always on top?
How to make a program always on top with a click on a command button?
Last edited by n00b scripter; Jun 22nd, 2005 at 09:29 AM .
Jun 20th, 2005, 03:06 PM
#2
Re: Always on top?
Here is a quick sample:
VB Code:
Option Explicit
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
Private Sub Command1_Click()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW _
Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Jun 20th, 2005, 03:06 PM
#3
Re: 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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
'To "turn off" always on top use
'SetWindowPos Me.Hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Jun 20th, 2005, 03:20 PM
#4
Thread Starter
Addicted Member
Jun 20th, 2005, 04:10 PM
#5
Thread Starter
Addicted Member
Re: Always on top?
well how to make it not on top? i want to turn it on and off
Jun 20th, 2005, 05:35 PM
#6
Re: Always on top?
use the constants provided:
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Jun 21st, 2005, 04:13 PM
#7
Thread Starter
Addicted Member
Re: Always on top?
I dont aunderstand how to bind that to a command button?
Jun 21st, 2005, 04:18 PM
#8
Re: Always on top?
The same way the other const was used but don't forget to declare it first:
VB Code:
Private Sub Command2_Click()
SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW _
Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Jun 21st, 2005, 07:34 PM
#9
Thread Starter
Addicted Member
Re: Always on top?
whit this script my whole application disappear
Jun 21st, 2005, 07:38 PM
#10
Re: Always on top?
Originally Posted by
[LGS]Static
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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
[B]'To "turn off" always on top use
'SetWindowPos Me.Hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS[/B]
End Sub
did you read this post?
Jun 21st, 2005, 07:44 PM
#11
Thread Starter
Addicted Member
Re: Always on top?
Yeah i did and now the turn on thing works but now it dissapears when i try the switch of button i have made it
VB Code:
Private Sub Command2_Click()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub
Jun 21st, 2005, 07:47 PM
#12
Hyperactive Member
Re: Always on top?
Because of this right here:
Originally Posted by
n00b scripter
VB Code:
Private Sub Command2_Click()
SetWindowPos Me.hwnd, [B]HWND_TOPMOST,[/B] 0, 0, 0, 0, FLAGS
End Sub
Don't use HWND_TOPMOST again. That's a NoNo
Base 2
Fcnncu"Nqxgu"Lguug##
Jun 21st, 2005, 07:57 PM
#13
Re: Always on top?
Heck knows what you're doing, though ...
The following sample simply toggles between "regular" and "topmost" modes - all you need is ONE command button so just copy and paste this code:
VB Code:
Option Explicit
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
Private Sub Command1_Click()
'============================
Static blnTopMost As Boolean
Dim lngPos As Long
blnTopMost = Not blnTopMost
If blnTopMost Then
lngPos = HWND_TOPMOST
Command1.Caption = "Make Regular Window"
Else
lngPos = HWND_NOTOPMOST
Command1.Caption = "Make Topmost Window"
End If
SetWindowPos Me.hWnd, lngPos, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or _
SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Form_Load()
Command1.Caption = "Make Topmost Window"
End Sub
Jun 21st, 2005, 08:18 PM
#14
Thread Starter
Addicted Member
Re: Always on top?
Whata... that script made the application fill out the screen!
Jun 21st, 2005, 08:29 PM
#15
Hyperactive Member
Re: Always on top?
Originally Posted by
n00b scripter
Whata... that script made the application fill out the screen!
If you're talking about RhinoBull's script, it worked just fine for me ?????
Base 2
Fcnncu"Nqxgu"Lguug##
Jun 21st, 2005, 08:31 PM
#16
Thread Starter
Addicted Member
Jun 21st, 2005, 08:32 PM
#17
Hyperactive Member
Re: Always on top?
Post your project maybe someone can see if there is something besides your code
Base 2
Fcnncu"Nqxgu"Lguug##
Jun 21st, 2005, 08:51 PM
#18
Thread Starter
Addicted Member
Re: Always on top?
Ok here it is. I dont think you will understand whats it is for
Attached Files
Last edited by n00b scripter; Jun 21st, 2005 at 09:17 PM .
Jun 22nd, 2005, 07:51 AM
#19
Thread Starter
Addicted Member
Jun 22nd, 2005, 09:07 AM
#20
Re: Always on top?
Your "problem" noob is setting form's windowstate to maximized, so simply comment it (as shown below):
VB Code:
Private Sub Command1_Click()
'InitializeRes
'''[b]Me.WindowState = 2[/b]
...
Jun 22nd, 2005, 09:29 AM
#21
Thread Starter
Addicted Member
Re: Always on top?
Ty so much for helping me and excuse me for my noobness
Jun 22nd, 2005, 09:30 AM
#22
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