Community discussion forum

Always on top

This is a comment thread discussing Always on top
  • 9 years ago

    This thread is for discussions of Always on top.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 years ago

    i get argument not optional when i call this "Call MakeTopMost"


    i have the other code as per the example, but still makes no difference, is this because i am using an mdi form as well as this form, the form is not an mdi child tho!


    any ideas??

  • 6 years ago

    Basically you hwnd is a Handle (Pointer) to a window object, It being a long you must first create the pointer then send it.


    Good Luck!

  • 6 years ago

    I agree with Rollershade, but this works fine, try it!:


    Call MakeTopMost(hwnd)


    Im not sure if the other function will work the same way, but this one works!

  • 6 years ago

    All this is very nice, but it comes with a very annoying side effect.  When the user
    Alt-tab's to another application, the "always-on-top" window stays annoyingly on
    top of the other application.


    VB doesn't even give you an event to tell you that you app is no longer on top.


    Got any ideas?

  • 6 years ago

    Dude thats the point of this, that the window stays on top of other apps..


    If you want the window to just stay on top of windows in your app, use


    show formName,1


    to show it as a modal form

  • 6 years ago

    You have to put

    Code:

    MakeTopMost (hwnd)

    in your code, not just
    Code:

    MakeTopMost

    James, EXCELLENT ARTICLE! Helped me a lot!

  • 6 years ago

    Guys, can you please tell me if there is any code with the same functionality that works in ASP (Active Server Pages).

  • 6 years ago

    works very nice
    but could you help me to understand want does every line of this code means and why is it there?
    thanks
    btw i am a begginer

  • 6 years ago

    once i understood a bit of vb this was very easy to implement, i put the form on top state in the  form load and it worked, i suppose you could set the form on top and normal state in to a check box

  • 6 years ago

    Just a hint to people who use this...
    On Win 98 -> XP


    1)ALT-TAB
    2)Select any explorer app (or other, didn't bother to test)
    ---All you need to do is get to the quichlaunch bar!!
    3)Start-bar pops up (with Quicklaunch attached)
    4)Click Desktop short cut.


    Hay Presto everything minimized including your ontop! app.


    (Only tested on XP, but I assume it'll work on any desktop quichlaunch shortcut)



  • 6 years ago

    I have encounted a problem when I showing another form using "form1.show vbmodal".
    form1 cannot be shown.


    How to keep the main form always on top of other application? and the child forms can show on top the main form.
    Thanks!

  • 5 years ago

    hi!
    basically you can't do it in asp as the code is executed on your web server and not on the client machine.
    Anyway, if you want to get a modal popup window you can add this code to the body tag of your popup :


    <body onblur="window.focus();">



    Cheers,


    Hervé

  • 5 years ago

    Hi
    Here it is


    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long


    -> declaration of the API function SetWindowPos taken from the "user32" library


    Private Const HWND_TOPMOST = -1
    -> constant to specify the window will be on top


    Private Const HWND_NOTOPMOST = -2
    -> constant to specify the window won't be on top


    Private Const SWP_NOMOVE = &H2
    -> constant to specify that the parameters x and y passed to the SetWindowPos function have to be ignored (keep the current x and y of the form)


    Private Const SWP_NOSIZE = &H1
    -> constant to specify that the parameters cx and cy passed to the SetWindowPos function have to be ignored (keep the current width and height of the form)


    Private Const TOPMOSTFLAGS = SWPNOMOVE Or SWPNOSIZE
    -> constant designed to pre-compute the OR logical operation of the SWP
    NOMOVE  and SWP_NOSIZE  constants (applying this constant will apply the two flags in the same time)



    Public Sub MakeTopMost(hwnd As Long)
    -> declaration of the MakeTopMost sub with the input parameter hwnd (handle window)


       SetWindowPos hwnd, HWNDTOPMOST, 0, 0, 0, 0, TOPMOSTFLAGS
       -> call of SetWindowPos
       -> don't forget that the four 0 corresponding to the x, y, cx and cy parameters are ignored because of the TOPMOST_FLAGS


    End Sub


    It's the same for the other function, but the hWndInsertAfter which is set to HWND_NOTOPMOST


    I hope this will help you


    Cheers,


    Hervé

  • 5 years ago

    Sorry i missed and i reply your question to the message post by leokth ... check there


    Cheers,


    Hervé

  • 5 years ago

    Sorry I missed ... I wanted to reply to the mssage posted by zoglchaim ...
    And I have no answer to your question yet.


    Cheers,


    Hervé

  • 5 years ago

    Hi


    I haven't try with mdi/mdi childs forms but if you want to get the handle of a form you can get it like this:


    m_lHwnd = MyForm.hwnd



    as the MyForm is your target form


    Hope this will help


    Cheers,


    Hervé

  • 5 years ago

    hi
    I am facing problem with this code.
    the form name is FrmTip which should always on top
    The Form1 has tow textbox control
    say text1 and text2 both have some tool tips
    in the gotfocus of the text box event i  calls the frmtip
    by the following code


    Private Sub Text1GotFocus()
       FrmTip.Label1.Caption = Me.ActiveControl.ToolTipText
       MakeTopMost FrmTip.hwnd
    End Sub
    Private Sub Text2
    GotFocus()
       FrmTip.Label1.Caption = Me.ActiveControl.ToolTipText
       MakeTopMost FrmTip.hwnd
    End Sub


    and also both the forms are Mdi Child forms
    Please help me
    if give frmtip.show command in the above event then the focus is in frmtip form only.
    i want to use frmtip form as a tips form.
    Please help as earyly as possible
    My email id is S_Muhilan@hotmail.com
    with regards
    S.Muhilan
    Mumbia-india.
    Waitting for ur reply


  • 5 years ago

    How can I add Command to my application in "send to" menu for any file type. I explain my problem here.


    If the user right clicks on the file, the "Send To" menu comes under windows. I want to add "Send to Dwijen's Application" text in that menu and then when the user clicks on that command from "send to" menu, the windows explorer should launch my program saying the filename which is sent to my application.

  • 5 years ago

    Simple to do, but not sure what it has to do with always on top.


    Copy this code to a new form...


    Option Explicit


    Private Sub Form_Load()
       MsgBox Command$
       End
    End Sub


    Now just make your EXE and copy a shortcut to the "SendTo" directory.  Under Win2K its C:\Documents and Settings\Suicidal\SendTo


    Hope this helps.
    Steve.


    PS.  Cheers for the code on always on top - has been useful.

  • 5 years ago

    After adding this code, the form hides behind all other windows, doesn't show in the taskbar and won't close. -_-

  • 5 years ago

  • 5 years ago

    the path for win98 is c:\windows\sendto\
    a path that should also work for windows2k is
    c:\documents and settings\all users


  • 5 years ago

    didnt make any difference

  • 5 years ago

    where do i put that bit?

  • 5 years ago

    lol

  • 5 years ago

    lol thanks that worked perfect

  • 5 years ago

    Here is an exemple of use :


    ' ---------------------------------------------------
    ' FORM frmMapSearch
    ' ---------------------------------------------------
    Private Sub Form_Activate()
     MakeTopMost Me.hwnd
    End Sub


    The result is that when the form is drawn screen the Sub MakeTopMost will be called and then it will act as a modal form

  • 5 years ago

    dropped this code into my form, cut and paste, and worked perfectly ... form stays on top of all other windows now ... even other forms in same app.

  • 4 years ago

    yeah, but can you do it in c in linux?

  • 4 years ago

    Example of call:


    Call MakeTopMost(Me.hwnd)


  • 3 years ago

    I also want to be able to interact with my application while this application stays on top.  Anyone know how to do that?


    I.e. if I put this function into the form I want to stay on top of all forms.  If I use this function inside another application, it will not allow me to manipulate the screens of that application.


    Thanks

  • 3 years ago

    I use a MDIform with some child forms. I wanted one of these child forms to stay on top of the others, but the code only works if the function is called from the MDIform, otherwise it just doesn't work. To solve the problem I had to set the MDIChild property of the form to false, but esthetically it didn't look good. If there is any way to get the code working with a child form it would fit perfectly to me.

  • 3 years ago

    The above code plus the following makes a very useful combination of floating the ENTIRE MS ACCESS WINDOW rather than just one of the MDI forms.


    Code:

    Option Explicit


    'API Declaration
    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long



    sub RaiseAccess()


    Dim hwnd As Long


    'Find the MS ACCESS WINDOW
    hwnd = FindWindow("OMain", "Microsoft Access")
    If hwnd <> 0 Then MakeTopMost (hwnd)
    'Then use MakeNormal(FindWindow("OMain","Microsoft Access") to bring it back down


    end sub



Post a reply

Enter your message below

Sign in or Join us (it's free).