martini
April 19th, 2001, 03:42 AM
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
raghu_nv
April 19th, 2001, 04:50 AM
In WinNT i successfully done it by this ,
SetWindowPos hwnd, -1, 0, 0, 0, 0,SWP_NOMOVE Or SWP_NOSIZE
martini
April 19th, 2001, 07:37 AM
Does not seem to work for me. When I move another window over it it hides behind that window
softweng
April 19th, 2001, 11:08 AM
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