SetWindowsTransparency

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: SetWindowsTransparency

Message par JohnJohnsonSHERMAN »

Bien sûr, c'est exactement ce que je fais avec mon Sherman volant :)
Il n'est pas transparent, mais bien sur fond rouge, c'est ce fond qui est effacé en utilisant le paramétre #LWA_COLORKEY associé à une couleur, ici ce rouge... En fait ce n'est qu'une fenêtre sans bordure avec un Sherman sur fond rouge dedans. Il te suffit en fait de modifier la couleur de la fenêtre, puis de filtrer cette couleur avec #LWA_COLORKEY dans SetLayeredWindowAttribues_

Bref voici un petit exemple de ce que tu veux :

Code : Tout sélectionner

#GWL_EXSTYLE = -20
#GWL_STYLE = -16
#WS_EX_LAYERED = 524288
#LWA_ALPHA = 2
#LWA_COLORKEY = 1

Prototype.i Proto_SetWindowLong_(hWnd,nIndex.i, NewLong.l)
Prototype.b Proto_SetLayeredWindowAttributes_(hWnd,ColorKey,Alpha.b,Flags.w)

OpenLibrary(1,"user32.dll")
Global SetWindowLong_.Proto_SetWindowLong_ = GetFunction(1,"SetWindowLongW") ;on charge la fonction
Global SetLayeredWindowAttributes_.Proto_SetLayeredWindowAttributes_ = GetFunction(1,"SetLayeredWindowAttributes")
CloseLibrary(1)

Procedure SetWindowTransparency(Window, Alpha)
  SetWindowLong_(WindowID(Window),#GWL_EXSTYLE, #WS_EX_LAYERED)
  SetLayeredWindowAttributes_(WindowID(Window), RGB(0,255,0),Alpha, #LWA_COLORKEY) ;On définit ici un masque de couleur avec #LWA_COLORKEY et on précise la couleur
                                                                                   ;Comme seule #LWA_COLORKEY est précisé, la transparence Alpha ne sera pas prise en compte
EndProcedure


width = 600
height = 400

OpenWindow(1,0,0,width,height,"Exemple de fenêtre avec colorkey",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(1,10,10,100,30,"Bouton")
CheckBoxGadget(2,10,50,100,20,"Case à cocher")
ComboBoxGadget(3,200,10,150,30)
ExplorerTreeGadget(4,20,200,200,150,"")
ListIconGadget(5,300,100,250,250,"Liste de rien",100)

SetWindowColor(1,RGB(0,255,0)) ;On modifie le fond de la fenêtre sur la couleur qui sera filtré, ici vert

SetWindowTransparency(1,220)

Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow


"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Avatar de l’utilisateur
venom
Messages : 3137
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: SetWindowsTransparency

Message par venom »

Cool merci SHERMAN






@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Répondre