Results 1 to 6 of 6

Thread: Form: Stay on Top

  1. #1
    Guest
    My Condition:
    I have 2 application running at the same time on my window. Both was created using VB6.


    My Problem;
    I just want one of my application remain on top all the time even when I use Alt+Tab key to select active application.


    My Question:
    Is form has the hidden object property on stay on top. Anyway how can I overcome the problem above. I prefer code reply but any method goes...?


    Thank You

  2. #2
    Guest
    Here's what you can do, use API, I'll give you the code to do it:

    'declaration part
    'API DECLARATION

    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


    'Code
    Const SWP_NOMOVE = 2
    Const SWP_NOSIZE = 1
    Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    SetWindowPos(Form1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)


    This will make your form stay on top.... HOpe this helps...

  3. #3
    Guest
    Thank you I'll try on now...

  4. #4
    Guest
    By putting:
    Private Sub Form_Load()
    Const SWP_NOMOVE = 2
    Const SWP_NOSIZE = 1
    Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    SetWindowPos(Wall.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    End Sub

    and instead of using private on the form i'm using public on the module:
    Public 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

    ------------------

    But it seems to have problem at the end of :
    SetWindowPos(Wall.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) ??
    The message need = to add to the ?? as above...

    Thank you..


  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    :) (: :) (:
    Remove those ()

  6. #6
    Guest
    Yea you can remove that, or what you can do is make a whole new sub with that and make it work with any form you want too, here's an example... Make this whole thing in a module, Exactly like I show you...

    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

    Public Sub StayOnTop(frmID as form, ontop as integer)

    Const SWP_NOMOVE = 2
    Const SWP_NOSIZE = 1
    Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    If OnTop = -1 Then
    OnTop = SetWindowPos(FrmID.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    Else
    OnTop = SetWindowPos(FrmID.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    End If
    End Sub


    And then use this sub from anyform you want to stay on top, for example...

    StayOnTop(Wall.hWnd, -1)
    and that window will stay on top, if you make the "-1" to whatever other number, it'll make the form NOT stay on top anymore... if you use it exactly as I got it above, it should work without errors, you don't need to make the API declaration public because the sub is in the module so no need for it to be public... oh and the reason it gave you errors at the end was one, that you used ( ) and the other is that you can simpy put "CALL" before the function and it will work, but the above method will give you a permanent ONTOP funtion,
    HAPPY CODING

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