USF toujours en premier plan même sur Windows

Bonjour,

Je viens vers vous pour m'aider à résoudre un problème, je souhaiterais si possible mettre un USF toujours en premier plan même sous windows, le faire apparaître dans tout les cas.

Avez vous une idée ?

Edite : j'ai oublié de préciser que j'utilise c'est ligne

Application.Visible = False

BarreOutil.Show vbModeless

Bonjour,

Avec APIs, à mettre dans le module de ta Form :

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

Private Declare Function FindWindowA _
            Lib "user32" ( _
            ByVal lpClassName As String, _
            ByVal lpWindowName As String) As Long

Private Sub UserForm_Initialize()

    Dim Position As Long
    Dim Hwnd As Long
    Dim Hauteur As Long
    Dim Largeur As Long

    With Me

        Hauteur = .Height
        Largeur = .Width

        Hwnd = FindWindowA(vbNullString, .Caption)

        Position = SetWindowPos(Hwnd, -1, _
            .Top, _
            .Left, _
            .Width, _
            .Height, 0)

        .Width = Largeur
        .Height = Hauteur

    End With

End Sub

Bonjour,

Hier j'ai pu tester le code que tu m'as proposé, il fonctionne parfaitement ! Merci beaucoup

J'ai rencontrer un problème car j'utilise ce code pour quitter mon programme

    If CloseMode <> vbFormCode Then
        Select Case MsgBox("Voulez-vous enregistrer les modifications avant de quitter le programme ?", vbYesNoCancel + vbQuestion + vbDefaultButton1, "Enregistrer avant de quitter ?")
        Case vbYes
            ThisWorkbook.Save
            Application.DisplayAlerts = False
            Application.Quit
        Case vbNo
            ThisWorkbook.Saved = True
            Application.DisplayAlerts = False
            Application.Quit
        Case vbCancel
            Cancel = True
            With Me
                Hauteur = .Height
                Largeur = .Width
                Hwnd = FindWindowA(vbNullString, .Caption)
                Position = SetWindowPos(Hwnd, -1, .Top, .Left, .Width, .Height, 0)
                .Width = Largeur
                .Height = Hauteur
            End With
        End Select
    End If

Le problème c'est que le MSGBOX n'apparaissait pas, donc avec l'aide d'un ami, on a modifier le code, ce qui donne ceci :

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim Hwnd As Long
Dim Hauteur As Long
Dim Largeur As Long
Dim Position As Long
    With Me
        Hauteur = .Height
        Largeur = .Width
        Hwnd = FindWindowA(vbNullString, .Caption)
        Position = SetWindowPos(Hwnd, -2, .Top, .Left, .Width, .Height, 0)
        .Width = Largeur
        .Height = Hauteur
    End With
    If CloseMode <> vbFormCode Then
        Select Case MsgBox("Voulez-vous enregistrer les modifications avant de quitter le programme ?", vbYesNoCancel + vbQuestion + vbDefaultButton1, "Enregistrer avant de quitter ?")
        Case vbYes
            ThisWorkbook.Save
            Application.DisplayAlerts = False
            Application.Quit
        Case vbNo
            ThisWorkbook.Saved = True
            Application.DisplayAlerts = False
            Application.Quit
        Case vbCancel
            Cancel = True
            With Me
                Hauteur = .Height
                Largeur = .Width
                Hwnd = FindWindowA(vbNullString, .Caption)
                Position = SetWindowPos(Hwnd, -1, .Top, .Left, .Width, .Height, 0)
                .Width = Largeur
                .Height = Hauteur
            End With
        End Select
    End If
End Sub

Actuellement, lorsque je ferme mon USF en utilisant le code ci-dessus, la positionnement de mon usf change, il se met en haut à gauche.

As-tu une idée?

Merci et à bientôt

Rechercher des sujets similaires à "usf premier plan meme windows"