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

Thread: Topmost Window

  1. #1
    Join Date
    May 1999
    Posts
    68

    Topmost Window

    Hi,
    How do I set a window to the topmost position. I used
    SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, Width, Height, 3)
    This works in Windows95 but refuses to work on NT/2000.

    Please advice me on this

    Thanks and best regards
    Shridhar




  2. #2
    Join Date
    Jul 2000
    Location
    india
    Posts
    49

    Re: Topmost Window

    In WinNT i successfully done it by this ,
    SetWindowPos hwnd, -1, 0, 0, 0, 0,SWP_NOMOVE Or SWP_NOSIZE


  3. #3
    Join Date
    May 1999
    Posts
    68

    Re: Topmost Window

    Does not seem to work for me. When I move another window over it it hides behind that window


  4. #4
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Topmost Window

    This Works Well For Me On All Windows Versions:

    option Explicit
    option private Module

    public Const SWP_NOMOVE = 2
    public Const SWP_NOSIZE = 1
    public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    public Const HWND_TOPMOST = -1
    public Const HWND_NOTOPMOST = -2

    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, byvalcy as Long, byval wflags as Long) as Long

    public Function SetTopMostWindow(hwnd as Long, Topmost as Boolean) as Long

    on error resume next

    If Topmost = true then
    SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    else
    SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    SetTopMostWindow = false
    End If

    End Function


    private Sub Form_Load()
    Dim lr as Long

    on error resume next

    '//set as Always on Top
    lr = SetTopMostWindow(frmPLCSettings.hWnd, true)

    End Sub


    private Sub Form_Unload(Cancel as Integer)
    Dim lr as Long

    on error resume next

    '//Remove Always on Top Status
    lr = SetTopMostWindow(frmPLCSettings.hWnd, false)

    '//Unload The Form And set to nothing to Prevent Memory Leaks
    Unload frmPLCSettings
    set frmPLCSettings = nothing

    End Sub





    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

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