Results 1 to 10 of 10

Thread: Make a window always on top?

  1. #1

    Thread Starter
    Junior Member Jaded's Avatar
    Join Date
    May 2001
    Posts
    17

    Make a window always on top?

    I am making a password program. I already have the code to disable ctrl+alt+del and alt+tab, but I am having the problem that the start menu still shows up over the window, and any programs you open after that show up over the window too, so the password window is nothing but a small nuisance. How do I make the window always on top, or fix this problem some other way? Thank you in advance!

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    you can use the following code

    Declarations
    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
    'this code makes the window stay on top
    rtn = SetWindowPos(OnTop.hwnd, -2, 0, 0, 0, 0, 3)
    'window will not stay on top with this code
    rtn = SetWindowPos(OnTop.hwnd, -1, 0, 0, 0, 0, 3)


    Josep Mª

  3. #3
    Hyperactive Member schuurke28's Avatar
    Join Date
    Feb 2001
    Posts
    402
    don't have vb 6 on this computer but i think this is done by setting your form to vbmodal.
    something like form_load(vbmodal)

  4. #4
    DaoK
    Guest
    modal and always on top is not the same.

  5. #5
    Megatron
    Guest
    A modal form will not let to focus on the owner form without closing it first. An always on top window will remain on top of all other windows (unless it's another top-most window) even when it does not have focus.

  6. #6
    Hyperactive Member schuurke28's Avatar
    Join Date
    Feb 2001
    Posts
    402
    well, like i said, i never used it and have no vb6 or msdn on this pc...

  7. #7
    DaoK
    Guest
    modal is on VB6 only???

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i think he was talking to megatron...

  9. #9
    Hyperactive Member schuurke28's Avatar
    Join Date
    Feb 2001
    Posts
    402
    just ment that i only have vb.net on this pc no vb6 or earlier version

  10. #10
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    ALways on Top

    Well, i patched up JoiJo's code for you, Jaded. Just plop the following in a module.
    VB Code:
    1. '====================================================
    2. '====This code was written by joijo and macai=======
    3. '====Use this code freely, but please leave the=======
    4. '====comments. And credit would be nice, too. *wink*====
    5. '====================================================
    6.  
    7. 'Declarations
    8. Declare Function SetWindowPos& Lib "user32" (ByVal hwnd As Long, _
    9. ByVal hWndInsertAfter As Long, _
    10. ByVal x As Long, ByVal y As Long, _
    11. ByVal cx As Long, _
    12. ByVal cy As Long, _
    13. ByVal wFlags As Long)
    14.  
    15. 'Actual Code
    16. Public Sub KeepOnTop(F As Form, Enabled As Boolean)
    17. If Enabled Then 'If the programmer wants the form on top.
    18.  SetWindowPos F.hwnd, -2, 0, 0, 0, 0, 3
    19. Else 'If the programmer does want the form on top.
    20.  SetWindowPos(F.hwnd, -1, 0, 0, 0, 0, 3)
    21. End If
    22. End Sub
    OK, i agree this is simple code. But it works. OK, now, all we need to figure out is how to startmenu toolbar thingy is controlled... bet its an API call. Ill go check and if i find something, ill post it.
    Luke

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