PDA

Click to See Complete Forum and Search --> : always on the top


Konczos, Szilárd
May 9th, 2001, 06:19 AM
Hi!
I had made a little program inwich
a button toggles the "always on the
top" property with the SetWindowPos
API function.
Clicking on a few other application
windows (here & there) my application
loses :eek: the "always on the top" property...
Has anybody met this problem?

VB6Coder
May 9th, 2001, 07:26 AM
I've never had a problem with the SetWindowPos API.

It sounds like you could be passing HWND_TOP as the hWndInsertAfter parameter instead of HWND_TOPMOST.

:)

Konczos, Szilárd
May 9th, 2001, 07:39 AM
My code:

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

Private Sub cmdTop_Click()
If bolAOTT Then
bolAOTT = False
Command1.Picture = ImageList.ListImages.Item(1).Picture
SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
Else
bolAOTT = True
Command1.Picture = ImageList.ListImages.Item(2).Picture
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End If
End Sub

Szila

VB6Coder
May 9th, 2001, 08:00 AM
Your code works fine.

The only thing I did notice is that your code was inside the Click event of a command button called cmdTop, but inside the procedure you were setting the picture property of a different command button called Command1.

Is your button called Command1 instead of cmdTop?
:)

Konczos, Szilárd
May 9th, 2001, 09:32 AM
I wanted to change the code to be easier to understand.
And that is the reason why i left the button's name inside
the code coincidentally.

VB6Coder
May 9th, 2001, 10:27 AM
You said that your application loses the Always on Top state when your app loses focus.

Let's go right back to basics to see what is working.

Start a new VB project and insert the following code into Form1. Run the project and click on different applications like you did before. Does Form1 same "Always On Top"?


Option Explicit
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 SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Sub Form_Load()

SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS

End Sub

Megatron
May 9th, 2001, 12:10 PM
You can shorten it down to this:

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 Sub Form_Load()

SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3

End Sub