|
-
May 9th, 2001, 06:19 AM
#1
Thread Starter
Junior Member
always on the top
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 the "always on the top" property...
Has anybody met this problem?
-
May 9th, 2001, 07:26 AM
#2
Addicted Member
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.
-
May 9th, 2001, 07:39 AM
#3
Thread Starter
Junior Member
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
-
May 9th, 2001, 08:00 AM
#4
Addicted Member
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?
-
May 9th, 2001, 09:32 AM
#5
Thread Starter
Junior Member
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.
-
May 9th, 2001, 10:27 AM
#6
Addicted Member
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
-
May 9th, 2001, 12:10 PM
#7
You can shorten it down to this:
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 Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
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
|