# Re: VB 4.0 如何"最上层显示"

Posted by 小呆 on May 08, 1999 at 15:43:40:

In Reply to: VB 4.0 如何"最上层显示" posted by Luke on May 08, 1999 at 15:31:27:

: 我使用Visual Basic 4.0 中文普及版
: 我欲将某表单使其永远都是"最上层显示"(除非我取消)
: 怎么办呢?
: 请各位高手协助
: VB副程序 DLL函数......方式不拘
: 能用就好

: 不胜感激!!
====================================================================
Option Explicit

#If Win16 Then
Private Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
#Else
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
#End If

Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const wFlags = SWP_NOMOVE Or SWP_NOSIZE

Private Sub Form_DblClick()
SetWindowPos Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags '取消最上层显示
End Sub

Private Sub Form_Load()
SetWindowPos Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, wFlags '设定最上层显示
End Sub

Follow Ups: