不怎麼寫C++所以看不太懂
個人常用的方式是使用 WinAPI 裡的 SetWindowPos
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, IgnoreResize Or IgnoreMove)
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, ShowWindow Or IgnoreResize Or IgnoreMove)
這是 非.Net視窗(外部窗體) 的方法
如視窗是 .Net元件只要將屬性 .TopMost = True 再 .TopMost = False就可以了
.NET的宣告如下
PHP 語法:
Public Const HWND_TOP = 0
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOPMOST = -1 '將窗口置於列表頂部,並位於任何最頂部窗口的前面
<Flags> Public Enum SetWindowPosFlags As UInteger
SynchronousWindowPosition = &H4000
DeferErase = &H2000
DrawFrame = &H20
FrameChanged = &H20
HideWindow = &H80
DoNotActivate = &H10
DoNotCopyBits = &H100
IgnoreMove = &H2
DoNotChangeOwnerZOrder = &H200
DoNotRedraw = &H8
DoNotReposition = &H200
DoNotSendChangingEvent = &H400
IgnoreResize = &H1
IgnoreZOrder = &H4
ShowWindow = &H40
End Enum
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Friend Shared Function SetWindowPos( _
ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _
ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal uFlags As SetWindowPosFlags) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
原理很簡單
就是先置頂 再取消置頂 就會放在最上層
如不想獲得焦點就加個 Or DoNotActivate
===============
比較想知道如何能
得到一份目前 桌面上的視窗 順序清單
windows系統有提供這種資訊嗎?