OVH Cloud OVH Cloud

UserForm tjrs visible

4 réponses
Avatar
John Fuss
Bonjour,

j'ai réalisé une macro qui pilote une application avec Shell(),
AppActivate() & SendKeys(). J'aimerai pouvoir afficher une UserForm pendant
le pilotage de l'application pour afficher les opérations réalisées.
SendKeys() envoi des frappes claviers à l'application qui a le focus..
Comment puis-je faire pour que ma UserForm soit tjrs visible mais sans prise
de focus ?

Merci d'avance.

John Fuss

4 réponses

Avatar
John Fuss
J'en viens à l'instant. Merci bcp

John Fuss.

"François Picalausa" a écrit dans le message de news:

Bonjour/soir,

L'article suivant de la FAQ pourra t'aider:
http://faq.vb.free.fr/index.php?questionP

Toutefois, si il s'agit bien d'un UserForm, VBA, les feuilles ne possèdent
pas de propriété hwnd.
Voici un contournement:

'Dans un module:

Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const Flags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or
SWP_NOSIZE

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 FindWindow Lib "user32" Alias "FindWindowA"


(ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Function SetTopMostWindow(WindowTitle As String, Topmost As


Boolean)
As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, WindowTitle)
If hWnd Then
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)
End If
End If
End Function


'Dans la userform:
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal x As Single, ByVal y As Single)
If Button = VBA.vbKeyLButton Then
SetTopMostWindow Me.Caption, True 'Active au click gauche
ElseIf Button = VBA.vbKeyRButton Then
SetTopMostWindow Me.Caption, False 'Désactive au click droit
End If
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"John Fuss" a écrit dans le message de
news:
> Bonjour,
>
> j'ai réalisé une macro qui pilote une application avec Shell(),
> AppActivate() & SendKeys(). J'aimerai pouvoir afficher une UserForm
> pendant le pilotage de l'application pour afficher les opérations
> réalisées. SendKeys() envoi des frappes claviers à l'application qui
> a le focus.. Comment puis-je faire pour que ma UserForm soit tjrs
> visible mais sans prise de focus ?
>
> Merci d'avance.
>
> John Fuss




Avatar
John Fuss
Euhh, un pti pbl,

j'utilise VBA et ds le code j'ai remplacé Form par UserForm, et UserForm n'a
pas de propriété hwnd.

Comment puis-je faire ?

Merci


"John Fuss" a écrit dans le message de news:

J'en viens à l'instant. Merci bcp

John Fuss.

"François Picalausa" a écrit dans le message de


news:

> Bonjour/soir,
>
> L'article suivant de la FAQ pourra t'aider:
> http://faq.vb.free.fr/index.php?questionP
>
> Toutefois, si il s'agit bien d'un UserForm, VBA, les feuilles ne


possèdent
> pas de propriété hwnd.
> Voici un contournement:
>
> 'Dans un module:
>
> Private Const SWP_NOMOVE = &H2
> Private Const SWP_NOSIZE = &H1
> Private Const SWP_NOACTIVATE = &H10
> Private Const SWP_SHOWWINDOW = &H40
> Private Const HWND_TOPMOST = -1
> Private Const HWND_NOTOPMOST = -2
> Private Const Flags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or
> SWP_NOSIZE
>
> 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 FindWindow Lib "user32" Alias "FindWindowA"
(ByVal
> lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Function SetTopMostWindow(WindowTitle As String, Topmost As
Boolean)
> As Long
> Dim hWnd As Long
> hWnd = FindWindow(vbNullString, WindowTitle)
> If hWnd Then
> 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)
> End If
> End If
> End Function
>
>
> 'Dans la userform:
> Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As
> Integer, ByVal x As Single, ByVal y As Single)
> If Button = VBA.vbKeyLButton Then
> SetTopMostWindow Me.Caption, True 'Active au click gauche
> ElseIf Button = VBA.vbKeyRButton Then
> SetTopMostWindow Me.Caption, False 'Désactive au click droit
> End If
> End Sub
>
> --
> François Picalausa (MVP VB)
> FAQ VB : http://faq.vb.free.fr
> MSDN : http://msdn.microsoft.com
>
>
> "John Fuss" a écrit dans le message de
> news:
> > Bonjour,
> >
> > j'ai réalisé une macro qui pilote une application avec Shell(),
> > AppActivate() & SendKeys(). J'aimerai pouvoir afficher une UserForm
> > pendant le pilotage de l'application pour afficher les opérations
> > réalisées. SendKeys() envoi des frappes claviers à l'application qui
> > a le focus.. Comment puis-je faire pour que ma UserForm soit tjrs
> > visible mais sans prise de focus ?
> >
> > Merci d'avance.
> >
> > John Fuss
>
>




Avatar
François Picalausa
Bonjour/soir,

relis mon post en entier, il y a la solution ;-)

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"John Fuss" a écrit dans le message de
news:O$
Euhh, un pti pbl,

j'utilise VBA et ds le code j'ai remplacé Form par UserForm, et
UserForm n'a pas de propriété hwnd.

Comment puis-je faire ?

Merci


"John Fuss" a écrit dans le message de news:

J'en viens à l'instant. Merci bcp

John Fuss.

"François Picalausa" a écrit dans le message
de news:
Bonjour/soir,

L'article suivant de la FAQ pourra t'aider:
http://faq.vb.free.fr/index.php?questionP

Toutefois, si il s'agit bien d'un UserForm, VBA, les feuilles ne
possèdent pas de propriété hwnd.
Voici un contournement:

'Dans un module:

Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const Flags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or
SWP_NOMOVE Or SWP_NOSIZE

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 FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long

Public Function SetTopMostWindow(WindowTitle As String, Topmost As
Boolean) As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, WindowTitle)
If hWnd Then
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)
End If
End If
End Function


'Dans la userform:
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift
As Integer, ByVal x As Single, ByVal y As Single)
If Button = VBA.vbKeyLButton Then
SetTopMostWindow Me.Caption, True 'Active au click gauche
ElseIf Button = VBA.vbKeyRButton Then
SetTopMostWindow Me.Caption, False 'Désactive au click droit
End If
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"John Fuss" a écrit dans le message de
news:
Bonjour,

j'ai réalisé une macro qui pilote une application avec Shell(),
AppActivate() & SendKeys(). J'aimerai pouvoir afficher une UserForm
pendant le pilotage de l'application pour afficher les opérations
réalisées. SendKeys() envoi des frappes claviers à l'application
qui a le focus.. Comment puis-je faire pour que ma UserForm soit
tjrs visible mais sans prise de focus ?

Merci d'avance.

John Fuss








Avatar
John Fuss
Désolé et encore merci, je m'y colle

John Fuss le désolé...

"François Picalausa" a écrit dans le message de news:

Bonjour/soir,

relis mon post en entier, il y a la solution ;-)

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"John Fuss" a écrit dans le message de
news:O$
> Euhh, un pti pbl,
>
> j'utilise VBA et ds le code j'ai remplacé Form par UserForm, et
> UserForm n'a pas de propriété hwnd.
>
> Comment puis-je faire ?
>
> Merci
>
>
> "John Fuss" a écrit dans le message de news:
>
>> J'en viens à l'instant. Merci bcp
>>
>> John Fuss.
>>
>> "François Picalausa" a écrit dans le message
>> de news:
>>> Bonjour/soir,
>>>
>>> L'article suivant de la FAQ pourra t'aider:
>>> http://faq.vb.free.fr/index.php?questionP
>>>
>>> Toutefois, si il s'agit bien d'un UserForm, VBA, les feuilles ne
>>> possèdent pas de propriété hwnd.
>>> Voici un contournement:
>>>
>>> 'Dans un module:
>>>
>>> Private Const SWP_NOMOVE = &H2
>>> Private Const SWP_NOSIZE = &H1
>>> Private Const SWP_NOACTIVATE = &H10
>>> Private Const SWP_SHOWWINDOW = &H40
>>> Private Const HWND_TOPMOST = -1
>>> Private Const HWND_NOTOPMOST = -2
>>> Private Const Flags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or
>>> SWP_NOMOVE Or SWP_NOSIZE
>>>
>>> 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 FindWindow Lib "user32" Alias
>>> "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
>>> String) As Long
>>>
>>> Public Function SetTopMostWindow(WindowTitle As String, Topmost As
>>> Boolean) As Long
>>> Dim hWnd As Long
>>> hWnd = FindWindow(vbNullString, WindowTitle)
>>> If hWnd Then
>>> 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)
>>> End If
>>> End If
>>> End Function
>>>
>>>
>>> 'Dans la userform:
>>> Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift
>>> As Integer, ByVal x As Single, ByVal y As Single)
>>> If Button = VBA.vbKeyLButton Then
>>> SetTopMostWindow Me.Caption, True 'Active au click gauche
>>> ElseIf Button = VBA.vbKeyRButton Then
>>> SetTopMostWindow Me.Caption, False 'Désactive au click droit
>>> End If
>>> End Sub
>>>
>>> --
>>> François Picalausa (MVP VB)
>>> FAQ VB : http://faq.vb.free.fr
>>> MSDN : http://msdn.microsoft.com
>>>
>>>
>>> "John Fuss" a écrit dans le message de
>>> news:
>>>> Bonjour,
>>>>
>>>> j'ai réalisé une macro qui pilote une application avec Shell(),
>>>> AppActivate() & SendKeys(). J'aimerai pouvoir afficher une UserForm
>>>> pendant le pilotage de l'application pour afficher les opérations
>>>> réalisées. SendKeys() envoi des frappes claviers à l'application
>>>> qui a le focus.. Comment puis-je faire pour que ma UserForm soit
>>>> tjrs visible mais sans prise de focus ?
>>>>
>>>> Merci d'avance.
>>>>
>>>> John Fuss