CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Always on Top

  1. #1
    Join Date
    Mar 2001
    Posts
    17

    Always on Top

    Hi,
    How can I make a form stay always on top ? (In similiar to Windows Clock utility).

    Yaron.


  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Always on Top

    put this in a module..


    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

    'constants for SetWindowPos API
    private Const SWP_NOMOVE = 2
    private Const SWP_NOSIZE = 1
    private Const HWND_TOPMOST = -1
    private Const HWND_NOTOPMOST = -2

    public Sub SetOnTop(byval hwnd as Long, byval bSetOnTop as Boolean)

    Dim lR as Long
    If bSetOnTop then
    lR = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
    SWP_NOSIZE)
    else
    lR = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
    SWP_NOSIZE)
    End If
    End Sub






    Then in your form load event..


    private Sub Form_Load()
    'keep form on top of everything
    SetOnTop me.hwnd, true
    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

Featured