Verifier si l'application est au premier plan

Résolu
cs_ov3rdoze Messages postés 414 Date d'inscription lundi 19 juillet 2004 Statut Membre Dernière intervention 23 septembre 2014 - 23 sept. 2008 à 09:04
cs_ov3rdoze Messages postés 414 Date d'inscription lundi 19 juillet 2004 Statut Membre Dernière intervention 23 septembre 2014 - 23 sept. 2008 à 11:31
Bonjour

Avant tout désolé mais je ne sais pas quel est le terme exact pour ce que je cherche (d'où la difficulté pour chercher...).

Je souhaite faire déclencher une action à intervalles réguliers, mais uniquement si l'application n'est pas au premier plan. Je m'explique : si elle est minimisée, on déclenche. Sinon, on ne déclenche que si , par exemple, on à choisi une autre application dans la barre des tâches qui s'est donc ouverte par dessus.

Dans le Timer_Tick, j'ai essayé :

If

(
Not
Me.Enabled)
et

If

(Not

Form.ActiveForm.Equals(
Me))
Mais aucun des 2 ne fonctionne...
Quelqu'un aurait une idée?

Merci d'avance

4 réponses

gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
23 sept. 2008 à 11:24
api   GetWindowInfo


<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _


Public Structure HWND__





'''int


Public unused As Integer


End Structure


<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _


Public Structure tagWINDOWINFO





'''DWORD->unsigned int


Public cbSize As UInteger





'''RECT->tagRECT


Public rcWindow As tagRECT





'''RECT->tagRECT


Public rcClient As tagRECT





'''DWORD->unsigned int


Public dwStyle As UInteger





'''DWORD->unsigned int


Public dwExStyle As UInteger





'''DWORD->unsigned int


Public dwWindowStatus As UInteger





'''UINT->unsigned int


Public cxWindowBorders As UInteger





'''UINT->unsigned int


Public cyWindowBorders As UInteger





'''ATOM->WORD->unsigned short


Public atomWindowType As UShort





'''WORD->unsigned short


Public wCreatorVersion As UShort


End Structure


<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _


Public Structure tagRECT





'''LONG->int


Public left As Integer





'''LONG->int


Public top As Integer





'''LONG->int


Public right As Integer





'''LONG->int


Public bottom As Integer


End Structure


Partial Public Class NativeMethods





'''Return Type: BOOL->int


'''hwnd: HWND->HWND__*


'''pwi: PWINDOWINFO->tagWINDOWINFO*


<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetWindowInfo")> _


Public Shared Function GetWindowInfo(<System.Runtime.InteropServices.InAttribute()> ByVal hwnd As System.IntPtr, ByRef pwi As tagWINDOWINFO) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean


End Function


End Class









Bonjour chez vous !
3
68manu Messages postés 43 Date d'inscription samedi 20 septembre 2008 Statut Membre Dernière intervention 1 octobre 2008
23 sept. 2008 à 09:49
Salut


et pourquoi pas utiliser la propriete WindowsState des forms...


3 choix : Maximized, Normal et Minimized ...


Ca devrait le faire :-)


Bon coding

_____________________
No problems, only soluces
0
cs_ov3rdoze Messages postés 414 Date d'inscription lundi 19 juillet 2004 Statut Membre Dernière intervention 23 septembre 2014
23 sept. 2008 à 09:55
Ben en fait j'ai essayé mais ça ne convient que pour certains cas :
 - Si la fenêtre est réduite, Minimized convient
 - Si elle ne l'est pas, son WindowsState vaut Normal (ou Maximized selon l'état) que la fenêtre soit au premier plan ou qu'elle soit "recouverte" par une autre.

Mais merci quand même.
0
cs_ov3rdoze Messages postés 414 Date d'inscription lundi 19 juillet 2004 Statut Membre Dernière intervention 23 septembre 2014
23 sept. 2008 à 11:31
Merci pour cette réponse pour le moins complète
Je vais essayer (sans conviction) de comprendre ce que ça fait...
0
Rejoignez-nous