Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Window Always on Top
Message
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00138360
Message ID:
00138551
Vues:
16
>How do I to put a window allways on top.

To try this example, save the following code in a form file and link it to a project.

VERSION 5.00
Begin VB.Form frmTopMost
Caption = "Topmost Window"
ClientHeight = 3960
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 3960
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 500
Left = 4080
Top = 3480
End
Begin VB.CheckBox chkFlash
Caption = "Flash Window"
Height = 495
Left = 120
TabIndex = 4
Top = 2280
Width = 4455
End
Begin VB.CommandButton cmdExit
Caption = "E&xit"
Height = 495
Left = 1800
TabIndex = 1
Top = 3240
Width = 1215
End
Begin VB.Frame Frame1
Caption = "Windows position"
Height = 1695
Left = 120
TabIndex = 0
Top = 240
Width = 4455
Begin VB.OptionButton optTopmost
Caption = "Topmost window"
Height = 495
Left = 240
TabIndex = 3
Top = 480
Width = 2415
End
Begin VB.OptionButton optNonTopmost
Caption = "Non-Topmost window"
Height = 495
Left = 240
TabIndex = 2
Top = 1080
Width = 2655
End
End
End
Attribute VB_Name = "frmTopMost"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function FlashWindow _
Lib "user32" _
(ByVal hwnd As Long, ByVal bInvert As Long) As Long
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
Const HWND_NOTOPMOST = -2
Const HWND_TOPMOST = -1
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE

Private Sub chkFlash_Click()
Timer1.Enabled = chkFlash.Value
End Sub

Private Sub cmdExit_Click()
Unload Me
End
End Sub

Private Sub optNonTopmost_Click()
SetWindowPos frmTopMost.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
End Sub

Private Sub optTopmost_Click()
SetWindowPos frmTopMost.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub

Private Sub Timer1_Timer()
FlashWindow frmTopMost.hwnd, 1
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform