Results 1 to 6 of 6

Thread: keeping form on top

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    India
    Posts
    53

    Unhappy keeping form on top

    hello any one can tell me

    how i keep my form on the top of any application

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    VB Code:
    1. Const HWND_TOPMOST = -1
    2. Const HWND_NOTOPMOST = -2
    3. Const SWP_NOSIZE = &H1
    4. Const SWP_NOMOVE = &H2
    5. Const SWP_NOACTIVATE = &H10
    6. Const SWP_SHOWWINDOW = &H40
    7. 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)
    8.  
    9. Private Sub Form_Activate()
    10. 'Set the window position to topmost
    11.     SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    12. End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    I usually put it in Load event but that is by the by.
    also is good idea to add unload event
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     SetWindowPos hWnd, Hwnd_NoTopMost, 0, 0, 0, 0, _
    3. Swp_NoMove Or Swp_NoSize
    4. End Sub
    When u do the ontop code it will keep the form on top of all apps which is what u wanted but if you want a 'sub form' in ur app to be always on top (eg Help) and follow the main form if minimized then you should Show the form as follows (still using the same APIs)
    VB Code:
    1. 'Form1 is main form, Form 2 is sub form
    2.       form2.Show vbModeless, Me
    regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Fanatic Member
    Join Date
    Mar 2001
    Location
    Southern California
    Posts
    733
    Vlatko,

    I tried your code and it doesn't seem to work...

  5. #5
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Unhappy errr

    Vlatko, I also tried your code but it just hides my form....it doesnt show up what so ever

  6. #6
    Megatron
    Guest
    Try this:
    VB Code:
    1. 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)
    2.  
    3. Private Sub Form_Load()
    4.     SetWindowPos hWnd, -1, 0, 0, 0, 0, 3
    5. 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