Fenêtre popup vers zone de notification

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Fenêtre popup vers zone de notification

Message par Le Soldat Inconnu »

Salut,

ce petit code permet d'afficher une fenêtre près de la zone de notification, comme le fond pas mal de logiciel (plus ou moins bien)

Le but de ce code est que la fenêtre ne se positionne pas bêtement en bas à droite mais elle se positionne réellement en fonction de la position de la zone de notification

J'ai besoin de testeurs sous différent OS (windows par contre, pas linux) avec la barre des taches un peu partout autour de l'écran (haut, bas , droite, gauche) pour en validé le fonctionnement.

Merci :D

Code : Tout sélectionner

Procedure GetTaskBarPosition(*TaskBarRect.RECT = 0)
  Protected TaskBarArea.RECT, TaskBar_Hwnd.l, Find_Hwnd.l, Find_Class.s, ScreenH.l, TaskBarPosition.l
  
  #TaskBar_Down = 0
  #TaskBar_Up = 1
  #TaskBar_Left = 2
  #TaskBar_Right = 3
  
  TaskBarPosition = -1
  
  ; On recherche la barre des taches
  TaskBar_Hwnd = 0
  Find_Hwnd.l = FindWindow_(0, 0)
  While Find_Hwnd <> 0 And TaskBar_Hwnd = 0
    Find_Class.s = Space(255)
    GetClassName_(Find_Hwnd, @Find_Class, 256)
    If Find_Class = "Shell_TrayWnd"
      TaskBar_Hwnd = Find_Hwnd
    EndIf
    Find_Hwnd = GetWindow_(Find_Hwnd, #GW_HWNDNEXT)
  Wend
  
  If TaskBar_Hwnd
    
    ; Taille de la barre des taches
    GetWindowRect_(TaskBar_Hwnd, @TaskBarArea)
    
    ; Taille de l'écran
    If ExamineDesktops()
      ScreenH = DesktopHeight(0)
      
      If 0 >= TaskBarArea\left And 0 <= TaskBarArea\right ; Si la barre touche la gauche de l'écran
        If 0 >= TaskBarArea\top And 0 <= TaskBarArea\bottom And ScreenH >= TaskBarArea\top And ScreenH <= TaskBarArea\bottom ; Barre verticale à gauche, on touche le bord haut et bas de l'écran
          TaskBarPosition = #TaskBar_Left
        ElseIf 0 >= TaskBarArea\top And 0 <= TaskBarArea\bottom ; On touche le bord haut de l'écran
          TaskBarPosition = #TaskBar_Up
        Else ; Sinon, on touche uniquement le bord bas
          TaskBarPosition = #TaskBar_Down
        EndIf
        
      Else ; Barre verticale à droite
        TaskBarPosition = #TaskBar_Right
      EndIf
      
    EndIf
    
    If *TaskBarRect <>0
      CopyMemory(@TaskBarArea, *TaskBarRect, SizeOf(RECT))
    EndIf
  EndIf
  
  ProcedureReturn TaskBarPosition
EndProcedure

Procedure NotificationWindow(Window, Space = 0)
  Protected TaskBarArea.RECT, TaskBarPosition.l, ScreenH.l, ScreenW.l
  
	StickyWindow(Window, 1)
	SetWindowLong_(WindowID(Window), #GWL_EXSTYLE, GetWindowLong_(WindowID(Window), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
	
  TaskBarPosition = GetTaskBarPosition(@TaskBarArea)
  
  ; Juste pour voir le retour de la fonction
  CompilerIf #PB_Compiler_Debugger
    Select TaskBarPosition
      Case #TaskBar_Down
        Debug "Barre des taches en bas"
      Case #TaskBar_Up
        Debug "Barre des taches en haut"
      Case #TaskBar_Left
        Debug "Barre des taches à gauche"
      Case #TaskBar_Right
        Debug "Barre des taches à droite"
      Default
        Debug "Erreur"
    EndSelect
    Debug "Position de la barre des taches"
    Debug TaskBarArea\left
    Debug TaskBarArea\right
    Debug TaskBarArea\top
    Debug TaskBarArea\bottom
    Debug ""
  CompilerEndIf
  
  ; Taille de l'écran
  If ExamineDesktops()
    ScreenH = DesktopHeight(0)
    ScreenW = DesktopWidth(0) 
  EndIf
  
  ; On déplace la fenêtre pour la mettre proche de la zone de notification
  Select TaskBarPosition
    Case #TaskBar_Down
      ResizeWindow(Window, ScreenW - Space - WindowWidth(Window), TaskBarArea\top - Space - WindowHeight(Window), #PB_Ignore, #PB_Ignore)
    Case #TaskBar_Up
      ResizeWindow(Window, ScreenW - Space - WindowWidth(Window), TaskBarArea\bottom + Space, #PB_Ignore, #PB_Ignore)
    Case #TaskBar_Left
      ResizeWindow(Window, TaskBarArea\right + Space, ScreenH - Space - WindowHeight(Window), #PB_Ignore, #PB_Ignore)
    Case #TaskBar_Right
      ResizeWindow(Window, TaskBarArea\left - Space - WindowWidth(Window), ScreenH - Space - WindowHeight(Window), #PB_Ignore, #PB_Ignore)
  EndSelect
  
	HideWindow(Window, 0)
	
EndProcedure

; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 150, 150, "Test", #PB_Window_BorderLess | #PB_Window_Invisible) = 0
  End
EndIf

NotificationWindow(0, 10)

; une petite image sur la fenêtre pour faire jolie
CreateImage(0, WindowWidth(0), WindowHeight(0))
StartDrawing(ImageOutput(0))
  Box(1, 1, WindowWidth(0) - 2, WindowHeight(0) - 2, $FFFFFF)
StopDrawing()
ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), ImageID(0))

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Menu
      Select EventMenu() ; Menus
          
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget() ; Gadgets
        Case 0
          Select EventType()
            Case #PB_EventType_LeftClick
              Event = #PB_Event_CloseWindow ; On ferme
          EndSelect
      EndSelect
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End

Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Fenêtre popup vers zone de notification

Message par nico »

Fonctionne correctement sur Window XP sur toutes les positions de la barre de tâche. :)

Pourrait tu rajouter le slide de la fenêtre?
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Fenêtre popup vers zone de notification

Message par Le Soldat Inconnu »

ça ne fonctionne pas terrible avec les images alors je n'ai pas mis.

je te laisse piocher toi même sur ce code et modifier le précédent. Il faut placé l'animation de la fenêtre à la fin de la procedure NotificationWindow(), à la place du HideWindow()

Code : Tout sélectionner

; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Animation d'ouverture et de fermeture


#AW_HOR_POSITIVE = $1 ; Animates the window from left to right. This flag can be used with roll or slide animation.
#AW_HOR_NEGATIVE = $2 ; Animates the window from right to left. This flag can be used with roll or slide animation.
#AW_VER_POSITIVE = $4 ; Animates the window from top to bottom. This flag can be used with roll or slide animation.
#AW_VER_NEGATIVE = $8 ; Animates the window from bottom to top. This flag can be used with roll or slide animation.
#AW_CENTER = $10 ; Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
#AW_HIDE = $10000 ; Hides the window. By default, the window is shown.
#AW_ACTIVATE = $20000 ; Activates the window.
#AW_SLIDE = $40000 ; Uses slide animation. By default, roll animation is used.
#AW_BLEND = $80000 ; Uses a fade effect. This flag can be used only if hwnd is a top-level window.

Procedure.l Valeur_Duree()
  ProcedureReturn Val(GetGadgetText(1))
EndProcedure

Procedure Animation(Fenetre, Effet, Duree)
  ; On cache la fenêtre
  AnimateWindow_(WindowID(Fenetre), Duree, Effet | #AW_HIDE)
  
  Delay(1000)
  
  ; On affiche la fenêtre
  AnimateWindow_(WindowID(Fenetre), Duree, Effet)
  
  ; On redessine la fenêtre, certain gadget ne se réaffiche pas correctement
  RedrawWindow_(WindowID(Fenetre), 0, 0, 1)
EndProcedure



; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0 Or CreateGadgetList(WindowID(0)) = 0
  End
EndIf

TextGadget(#PB_Any, 0, 0, 300, 15, "Durée de l'animation en ms :")
StringGadget(1, 0, 15, 100, 20, "500", #PB_String_Numeric)

ButtonGadget(2, 0, 50, 150, 25, "Effet de transparence") : ButtonGadget(3, 150, 50, 150, 25, "Du centre")
ButtonGadget(4, 0, 75, 150, 25, "De la gauche vers la droite") : ButtonGadget(5, 150, 75, 150, 25, "De la droite vers la gauche")
ButtonGadget(6, 0, 100, 150, 25, "Du haut vers le bas") : ButtonGadget(7, 150, 100, 150, 25, "Du bas vers le haut")
ButtonGadget(8, 0, 125, 150, 25, "Diagonale HG vers BD") : ButtonGadget(9, 150, 125, 150, 25, "Diagonale BG vers HD")
ButtonGadget(10, 0, 150, 150, 25, "Diagonale HD vers BG") : ButtonGadget(11, 150, 150, 150, 25, "Diagonale BD vers HG")
Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget() ; Gadgets
        Case 2
          Animation(0, #AW_BLEND, Valeur_Duree())
        Case 3
          Animation(0, #AW_CENTER, Valeur_Duree())
        Case 4
          Animation(0, #AW_HOR_POSITIVE, Valeur_Duree())
        Case 5
          Animation(0, #AW_HOR_NEGATIVE, Valeur_Duree())
        Case 6
          Animation(0, #AW_VER_POSITIVE, Valeur_Duree())
        Case 7
          Animation(0, #AW_VER_NEGATIVE, Valeur_Duree())
        Case 8
          Animation(0, #AW_HOR_POSITIVE | #AW_VER_POSITIVE, Valeur_Duree())
        Case 9
          Animation(0, #AW_HOR_POSITIVE | #AW_VER_NEGATIVE, Valeur_Duree())
        Case 10
          Animation(0, #AW_HOR_NEGATIVE | #AW_VER_POSITIVE, Valeur_Duree())
        Case 11
          Animation(0, #AW_HOR_NEGATIVE | #AW_VER_NEGATIVE, Valeur_Duree())
      EndSelect
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Fenêtre popup vers zone de notification

Message par nico »

Si ça ne marche pas trop avec les images, alors peut être que la solution serait de faire un fondu avec setlayeredwindow.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Fenêtre popup vers zone de notification

Message par Le Soldat Inconnu »

ça c'est une bonne idée :D
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
TazNormand
Messages : 1297
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: Fenêtre popup vers zone de notification

Message par TazNormand »

Salut LSI

sous VISTA Pro SP2 x86, ça fonctionne nickel sur les 4 côtés de l'écran, en résolution 1280x1024.
Image
Image
Répondre