Results 1 to 7 of 7

Thread: Always On Top?

  1. #1
    adim
    Guest

    Always On Top?

    i have a program, the thing is i need it to always be on top no matter what other programs are launched! there will be no minimise option, the only time it will not be on screen is when it is closed!

    how do i do this??

    thanx in advance

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    You can accomplish this using the SetWindowPos API...

    In a module place the following code:
    Code:
    Public Const HWND_TOPMOST& = -1
    
    Const SWP_NOMOVE& = &H2
    Const SWP_NOSIZE& = &H1
    
    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)
    Then in a function or, as in my example, the form_load event place the following code:

    Code:
    Private Sub Form_Load()
    Dim lFlags As Long
    Dim lStay As Long
    
    lFlags = SWP_NOSIZE Or SWP_NOMOVE
    lStay = SetWindowPos(Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, lFlags)
    End Sub
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3
    DaoK
    Guest
    adim that question was asked a lot in the past so you can always use the Search engine in VBForums who is located to the top of that screen. Next time just search before posting and you will have a answer very fast,

    Daok

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by DaoK
    adim that question was asked a lot in the past so you can always use the Search engine in VBForums who is located to the top of that screen. Next time just search before posting and you will have a answer very fast,

    Daok
    This answer has been used before.
    Before you answer a question please use the search engine of these forums.
    Next time you consider answering a question please make sure this answer hasn't been posted before
    Lesson: (I'm sorry that I'm aiming this to you again DaoK, I know I've treated you badly before )
    There is no such thing as a stupid question only stupid answers!

  5. #5
    DaoK
    Guest
    I know, I do not yell to him it's just because he is new to VBforums and I want to tell you some "feature" to optimize vbforums.com

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by DaoK
    I know, I do not yell to him it's just because he is new to VBforums and I want to tell you some "feature" to optimize vbforums.com
    I was only joking DaoK

  7. #7
    dana340
    Guest
    try this ,

    Private Declare Function SetWindowPos Lib "user32" Alias "setwindowpos" (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

    Public Sub FormAlwaysOnTop(frm As Form, ontop As Boolean)
    If ontop Then
    SetWindowPos frm.hwnd, -1, (frm.Left / Screen.TwipsPerPixelX), (frm.Top / Screen.TwipsPerPixelY), (frm.Width / Screen.TwipsPerPixelX), (frm.Height / Screen.TwipsPerPixelY), 1
    Else
    SetWindowPos frm.hwnd, -2, (frm.Left / Screen.TwipsPerPixelX), (frm.Top / Screen.TwipsPerPixelY), (frm.Width / Screen.TwipsPerPixelX), (frm.Height / Screen.TwipsPerPixelY), 1
    End If

    End Sub

    'frmresult is the form that 1 want to diplay it on top always and u can put your form name

    Private Sub Command1_Click()
    FormAlwaysOnTop frmresult, 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