Results 1 to 7 of 7

Thread: always on the top

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    HUNGARY, Pécs
    Posts
    17

    Question 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?

  2. #2
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    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.


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    HUNGARY, Pécs
    Posts
    17
    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

  4. #4
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    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?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    HUNGARY, Pécs
    Posts
    17
    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.

  6. #6
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    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


  7. #7
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width