Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

NodeBB

  1. Home
  2. Programmation
  3. Développement de logiciels
  4. VB.Net
  5. Faire un splashscreen avec le canal alpha (donc avec de la translucidité)

Faire un splashscreen avec le canal alpha (donc avec de la translucidité)

Scheduled Pinned Locked Moved VB.Net
2 Posts 2 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mars073M
    mars073M
    mars073
    wrote on last edited by
    #1

    <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>

    Aide à l'apprentissage et la réalisation pour des graphismes, des programmes, des sites ou autres.Signature aléatoire, proposez vous aussi une signature ici!

    1 Reply Last reply
    1
    • AzadA
      AzadA
      Azad
      wrote on last edited by
      #2

      <p>
      </p><p>Merci du tutoriel.</p><p>
      Si quelqu'un retrouve les sources, postez-les.</p><p></p><p>
      +1 Rep. 🙂 </p>

      Administrateur du forum.
      Contactez-moi par message privé ou par mail.

      1 Reply Last reply
      0

      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
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Login or register to search.
      Powered by NodeBB Contributors
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups