Faire un splashscreen avec le canal alpha (donc avec de la translucidité)
-
<p>Salut all,<br/><br/>
Je encore faire un tuto à l'arrache.
<br/>
Donc je vais vous expliquer comment faire pour faire un splashScreen, c'était l'image de présentation ou de chargement que l'on peu voir parfois avec certains programmes.<br/><br/>
je vais prendre comme exemple:<br/><img alt="logos_red-30cdb6e.png" src="<base_url>/applications/sslimageproxy/interface/image.php?url=http://img72.xooimage.com/files/b/7/a/logos_red-30cdb6e.png"/><br/>
il y a un dégradé de transparence et donc si j'utilise "tranparencyColor" ça va juste me retirer la couleur pure... alors dans ce cas il faut rien mettre dans transparency et mette un code kikoolong, enfin un peu long
<br/><br/><span style="color:#FF0000;">/!\Les contrôles (outils) ne sont pas visible après la manipulation !/!</span><br/><br/>
Le code à mettre après "Public Class [Votreforme]"</p>
<pre class="ipsCode prettyprint lang-auto">
#Region "full_decla"
Public Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
End Structure
Public Const ULW_COLORKEY As Integer = 1
Public Const ULW_ALPHA As Integer = 2
Public Const ULW_OPAQUE As Integer = 4
Public Const AC_SRC_OVER As Byte = 0
Public Const AC_SRC_ALPHA As Byte = 1
Public Const GWL_EXSTYLE = (-20)
Public Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal crKey As Integer, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Integer) As Boolean
Private Declare Auto Function SetWindowLong Lib "User32.Dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Auto Function GetWindowLong Lib "User32.Dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
Public Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
Public Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
Public Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As IntPtr) As IntPtr
Public Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Boolean
Public Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As IntPtr) As Boolean
Public Sub SetBitmap(ByVal PNG As Bitmap, ByVal opacity As Byte)
If Not (PNG.PixelFormat = Imaging.PixelFormat.Format32bppArgb) Then
Throw New ApplicationException("The bitmap must be 32ppp with alpha-channel.")
End If
Dim screenDc As IntPtr = GetDC(IntPtr.Zero)
Dim memDc As IntPtr = CreateCompatibleDC(screenDc)
Dim hBitmap As IntPtr = IntPtr.Zero
Dim oldBitmap As IntPtr = IntPtr.Zero
Try
hBitmap = PNG.GetHbitmap(Color.FromArgb(0))
oldBitmap = SelectObject(memDc, hBitmap)
Dim size As Size = New Size(PNG.Width, PNG.Height)
Dim pointSource As Point = New Point(0, 0)
Dim topPos As Point = New Point(Left, Top)
Dim blend As BLENDFUNCTION = New BLENDFUNCTION
blend.BlendOp = AC_SRC_OVER
blend.BlendFlags = 0
blend.SourceConstantAlpha = opacity
blend.AlphaFormat = AC_SRC_ALPHA
UpdateLayeredWindow(Handle, screenDc, topPos, size, memDc, pointSource, 0, blend, ULW_ALPHA)
Finally
ReleaseDC(IntPtr.Zero, screenDc)
If Not (hBitmap.Equals(IntPtr.Zero)) Then
SelectObject(memDc, oldBitmap)
DeleteObject(hBitmap)
End If
DeleteDC(memDc)
End Try
End Sub
#End Region</pre>
<p>Puis dans Form.load:</p>
<pre class="ipsCode prettyprint lang-auto">
Dim Param As Long
Param = GetWindowLong(Me.Handle, GWL_EXSTYLE)
Call SetWindowLong(Me.Handle, GWL_EXSTYLE, Param Or (524288))
Call SetBitmap(Me.BackgroundImage, 255)</pre>
<p>___________<br/>
Tuto part2, un petit bonus
<br/><br/>
Comment faire une animation et faire en sorte que le splash se ferme un jour xD<br/><br/>
Il suffit de mettre un timer avec un interval de 1000ms (1sec.)<br/>
et d'ajouter 2variales de type byte que on va appeler "Anim" et "Loader" (pense bête: faire un tuto sur les variables)<br/>
Donc vous mettez le code suivant entre de sub (si on le met dedans la variable va toujours se redéclarer et remettre la valeur de base.</p>
<pre class="ipsCode prettyprint lang-auto">
Dim anim As Byte = 0
Dim loader As Byte = 0</pre>
<p>Puis dans le Timer.tick (double clique sur le timer pour le voir) et dedans on va mettre:</p>
<pre class="ipsCode prettyprint lang-auto">
anim += 1
If anim = 1 Then
Me.BackgroundImage = My.Resources.trame1 'la première image de l'animation
ElseIf anim = 10 Then
Me.BackgroundImage = My.Resources.trame2 ' la seconde
ElseIf anim = 11 Then
Me.BackgroundImage = My.Resources.trame2 ' la quatrième ou troisième je sais pu
loading += 1
anim = 0
End If
Dim Param As Long
Param = GetWindowLong(Me.Handle, GWL_EXSTYLE)
Call SetWindowLong(Me.Handle, GWL_EXSTYLE, Param Or (524288))
Call SetBitmap(Me.BackgroundImage, 255)
If loader = 3 Then
' Pensez à mettre la forme suivante à ouvrir et aller dans les préférences de votre projet et changer le style de fermeture par fermeture du dernier formulaire
Me.Close()
End If</pre>
<p>Voilà maintenant vous savez faire des SplashScreen stylé
<br/>
le code de base et pas de moi j'ai oublié la source mais je l'ai bcp édité de toute façon
<br/><br/>
Bonne programmation à tous!<br/>
Cordialement,<br/>
Mars073</p>
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
</p>