Sous XP, c'est un vrai bordel
La fenêtre TopMost Layered reste derrière la fenetre non TopMost Layered mais la fenetre la topmost layered est devant la fenêtre normale et la fenêtre non TopMost layered est derrière la fenêtre normale.
ça parait confu mais le code illustre bien le problème
Code : Tout sélectionner
; PureBasic 4.40
ProcedureDLL SetLayeredWindow2(WindowID) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
SetWindowLong_(WindowID, #GWL_EXSTYLE, GetWindowLong_(WindowID, #GWL_EXSTYLE) | #WS_EX_LAYERED) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
EndProcedure
ProcedureDLL AlphaImageWindow2(WindowID, ImageID) ; Mettre une image PNG comme fond d'une fenêtre
Protected Image_HDC, Image_Bitmap.BITMAP, ContextOffset.POINT, Blend.BLENDFUNCTION, Image
; Dimension de l'image
GetObject_(ImageID, SizeOf(BITMAP), @Image_Bitmap)
Image = CreateImage(#PB_Any, Image_Bitmap\bmWidth, Image_Bitmap\bmHeight, 32)
StartDrawing(ImageOutput(Image))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID, 0, 0)
DrawingMode(#PB_2DDrawing_AlphaChannel)
DrawAlphaImage(ImageID, 0, 0)
StopDrawing()
; Chargement du HDC
Image_HDC = CreateCompatibleDC_(#Null)
Image_Ancienne = SelectObject_(Image_HDC, ImageID(Image))
; L'image est mise en skin de la fenêtre
Blend\SourceConstantAlpha = 255 ; niveau de transparence
Blend\AlphaFormat = 1 ; Support de la couche alpha
Blend\BlendOp = 0
Blend\BlendFlags = 0
UpdateLayeredWindow_(WindowID, 0, 0, @Image_Bitmap + 4, Image_HDC, @ContextOffset, 0, @Blend, 2)
; Fermeture du HDC
SelectObject_(Image_HDC, Image_Ancienne)
DeleteDC_(Image_HDC)
; Supression de l'image
FreeImage(Image)
EndProcedure
; Procedure Callback(WindowID, message, wParam, lParam)
; Protected *WindowPos.WINDOWPOS
; Result = #PB_ProcessPureBasicEvents
; If WindowID(0) = WindowID
; If message = #WM_WINDOWPOSCHANGING ; Window position is about to change !
; *WindowPos = lParam
; *WindowPos\hwndInsertAfter = #HWND_TOPMOST ; <-- Forces the window to stay in the background
; EndIf
; EndIf
; If WindowID(1) = WindowID
; If message = #WM_WINDOWPOSCHANGING ; Window position is about to change !
; *WindowPos = lParam
; *WindowPos\hwndInsertAfter = #HWND_BOTTOM ; <-- Forces the window to stay in the background
; EndIf
; EndIf
; ProcedureReturn Result
; EndProcedure
CreateImage(0, 200, 200, 32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0, 0, 200, 200, $80000000)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
DrawText(10, 10, "Premier plan / Topmost", $FFFFFFFF)
StopDrawing()
CreateImage(1, 200, 200, 32)
StartDrawing(ImageOutput(1))
Box(0, 0, 200, 200, $0000FF)
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0, 0, 200, 200, $FF000000)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
DrawText(10, 10, "Normal / NonTopmost", $FFFFFFFF)
StopDrawing()
If OpenWindow(1, 150, 150, ImageWidth(0), ImageHeight(0), "Test", #PB_Window_BorderLess)
SetLayeredWindow2(WindowID(1))
AlphaImageWindow2(WindowID(1), ImageID(1))
If OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0), "Test", #PB_Window_BorderLess)
SetLayeredWindow2(WindowID(0))
AlphaImageWindow2(WindowID(0), ImageID(0))
StickyWindow(0, 1)
; SetWindowCallback(@Callback())
If OpenWindow(2, 200, 200, 200, 200, "Test")
Repeat
Event = WaitWindowEvent()
If Event = #WM_LBUTTONDOWN
SendMessage_(WindowID(EventWindow()), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
ElseIf Event = #WM_MOUSEMOVE
; Debug "ok"
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
EndIf