Un petit code pour Noël 2006 pour vous remercier

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Un petit code pour Noël 2006 pour vous remercier

Message par Anonyme2 »

Voilà un petit code sans prétention qui fait défiler un message de Noël, avec GDi+
Il faut les 3 fichiers GDI+ mis à jour que vous trouverez en lien ici (les constantes, structures et l'ensemble des fonctions GDI+ )
Dans le fichier Gdiplus.pb, ainsi que l'exemple, il faut modifier le chemin des includefile.
Le fichier d'exemple est mettre dans le dossier qui est en rapport avec votre chemin pour Gdiplus.pb, ainsi que les fichiers de constantes et structure.

Pour les fainéants, j'ai fait un exe prêt à l'emploi.

Le zip est ici

Voici le code (inclus aussi dans l'archive)

Joyeux Noël 2006

Code : Tout sélectionner

XIncludeFile "../../../gdiplus.pbi"

EnableExplicit

Enumeration
  #MainWindow
  #Image = 0
  #ImagePereNoel
  #ImageGadget = 0
  #Police = 0
  #Timer = 10
EndEnumeration

Define .l
Global *token, *gfx1, *path1, *brush1, *brush2, *brush3, *image, *nativeFamily, *format, *hDC
Global emSize.f, fontStyle.l, timer.l = 40, temps.l = 0, temps1.l = 0, format.l = 0, HauteurImage.l
Global chaine.s = "Joyeux Noël 2006" + Chr(10) + "à tous les codeurs" + Chr(10) + "du forum fr"
Global chaine1.s = "PureBasic.fr - Joyeux Noël 2006", Img_PereNoel.l
Global rc.Rect
Global Dim pt.PointF(3)


If OpenWindow(#MainWindow, 0, 0, 810, 515, chaine1, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
  SetTimer_(WindowID(#MainWindow), #Timer, timer, 0)
  If CreateGadgetList(WindowID(#MainWindow))
    If CreateImage(#Image, WindowWidth(#MainWindow), WindowHeight(#MainWindow), 32)
      If ImageGadget(#ImageGadget, 0, 0, 0, 0, ImageID(#Image))
        UsePNGImageDecoder()
        Img_PereNoel = CatchImage(#ImagePereNoel, ?PereNoel)
        emSize = 5
        rc\left = 10 + 10
        rc\top = 110
        rc\right = WindowWidth(#MainWindow) - 50 + 25 - 10
        rc\bottom = WindowHeight(#MainWindow) - 197
        
        pt(0)\x = 0 : pt(0)\y = 0
        pt(1)\x = WindowWidth(#MainWindow) : pt(1)\y = 0
        pt(2)\x = WindowWidth(#MainWindow) : pt(2)\y = WindowHeight(#MainWindow)
        pt(3)\x = 0 : pt(3)\y = WindowHeight(#MainWindow)
        
        ; initialisation de Gdi+
        *token = Gdiplus_New()
        
        ; on vérifie que l'initialisation est Ok
        If *token
          *hDC = StartDrawing(ImageOutput(#Image))
            If *hDC
              ; création de l'objet graphique
              If GdipCreateFromHDC(*hDC, @*gfx1) = #Ok
                GdipSetSmoothingMode(*gfx1, 2)
                
                ; creation d'un objet Path
                If GdipCreatePath(#FillModeAlternate, @*path1) = #Ok
                  
                  ; choix de la famille de police
                  If GdipGetGenericFontFamilySansSerif(@*nativeFamily) = #Ok
                    GdipCreateStringFormat(format, #LANG_NEUTRAL, @*format)
                    
                    GdipCreateSolidFill(ARGB(#Black, 250), @*brush1)
                    If Img_PereNoel
                      If GdipCreateBitmapFromHBITMAP(Img_PereNoel, #Null, @*image) = #Ok
                        GdipCreateTexture(*image, #WrapModeTile, @*brush3)
                        GdipGetImageheight(*image, @HauteurImage)
                        GdipDisposeImage(*image)
                      EndIf
                    EndIf
                    If GdipCreatePathGradient(@pt(), 4, #WrapModeTile, @*brush2) = #Ok
                      If GdipSetPathGradientCenterColor(*brush2, ARGB(#Red)) = #Ok
                        GdipSetPathGradientLinearBlend(*brush2, 0.0, 1.0)
                        GdipFillRectangle(*gfx1, *brush2, 0, 0, WindowWidth(#MainWindow), WindowHeight(#MainWindow))
                        GdipFlush(*gfx1, #FlushIntentionSync)
                        GdipDeleteGraphics(*gfx1) : *gfx1 = 0
                      StopDrawing()
                      SetGadgetState(#ImageGadget, ImageID(#Image))
                      
                      HideWindow(#MainWindow, 0)
                      
                      Repeat
                        Select WaitWindowEvent()
                          Case #PB_Event_CloseWindow
                            Break
                            
                          Case #WM_TIMER
                            If EventwParam() = #Timer
                              If Len(chaine1) < 220
                                chaine1 = " " + chaine1
                              Else
                                chaine1.s = "PureBasic.fr - Joyeux Noël"
                              EndIf
                              SetWindowTitle(#MainWindow, chaine1)
                              emSize + 0.5
                              If (Int(emSize) = 88) Or temps Or temps1
                                If temps1
                                  emSize - 0.5
                                  If Not(temps1 = 50) ; Delay(50*timer)
                                    temps1 + 1
                                  Else
                                    temps1 = 0
                                  EndIf
                                ElseIf temps < 2
                                  temps + 1
                                Else
                                  If Not(temps = 50) ; Delay(50*timer)
                                    temps + 1
                                  Else
                                    temps = 0
                                    emSize = 5
                                    format + 1
                                    If format = 3
                                      format - format
                                    EndIf
                                    *hDC = StartDrawing(ImageOutput(#Image))
                                      If *hDC
                                        If GdipCreateFromHDC(*hDC, @*gfx1) = #Ok
                                          GdipSetSmoothingMode(*gfx1, 2)
                                          GdipResetPath(*path1)
                                          GdipAddPathStringI(*path1, chaine, -1, *nativeFamily, 0, 88, @rc, *format)
                                          GdipFillPath(*gfx1, *brush2, *path1)
                                          GdipFlush(*gfx1, #FlushIntentionSync)
                                          GdipDeleteGraphics(*gfx1) : *gfx1 = 0
                                        StopDrawing()
                                        SetGadgetState(#ImageGadget, ImageID(#Image))
                                        temps1 + 1
                                      EndIf
                                    EndIf
                                  EndIf
                                EndIf
                              Else
                                *hDC = StartDrawing(ImageOutput(#Image))
                                  If *hDC
                                    If GdipCreateFromHDC(*hDC, @*gfx1) = #Ok
                                      GdipSetSmoothingMode(*gfx1, 2)
                                      GdipResetPath(*path1)
                                      If emSize = 5.5
                                        GdipFillRectangle(*gfx1, *brush2, 0, 0, WindowWidth(#MainWindow), WindowHeight(#MainWindow))
                                        GdipFillRectangleI(*gfx1, *brush3, -1, -1, WindowWidth(#MainWindow) + 1, HauteurImage + 1)
                                        GdipFillRectangleI(*gfx1, *brush3, -1, WindowHeight(#MainWindow) - HauteurImage, WindowWidth(#MainWindow) + 1, HauteurImage + 1)
                                      Else
                                        GdipAddPathStringI(*path1, chaine, -1, *nativeFamily, 0, emSize - 0.5, @rc, *format)
                                        GdipFillPath(*gfx1, *brush2, *path1)
                                      EndIf
                                      GdipResetPath(*path1)
                                      GdipSetStringFormatAlign(*format, format)
                                      GdipAddPathStringI(*path1, chaine, -1, *nativeFamily, 0, emSize, @rc, *format)
                                      GdipFillPath(*gfx1, *brush1, *path1)
                                      GdipFlush(*gfx1, #FlushIntentionSync)
                                      GdipDeleteGraphics(*gfx1) : *gfx1 = 0
                                    StopDrawing()
                                    SetGadgetState(#ImageGadget, ImageID(#Image))
                                  EndIf
                                EndIf
                              EndIf
                            EndIf
                        EndSelect
                      ForEver
                      
                    EndIf
                  EndIf
                EndIf
              EndIf
            EndIf
          EndIf
        EndIf
      EndIf
    EndIf
  EndIf
EndIf

If *format : GdipDeleteStringFormat(*format) : EndIf
If *nativeFamily : GdipDeleteFontFamily(*nativeFamily) : EndIf
If *brush1 : GdipDeleteBrush(*brush1) : EndIf
If *brush2 : GdipDeleteBrush(*brush2) : EndIf
If *brush3 : GdipDeleteBrush(*brush3) : EndIf
If *path1 : GdipDeletePath(*path1) : EndIf
If *gfx1 : GdipDeleteGraphics(*gfx1) : EndIf
If *token : GdiplusShutdown(*token) : EndIf
End

DataSection
  PereNoel :
    Data.l $474E5089, $0A1A0A0D, $0D000000, $52444849, $87000000, $56000000
    Data.l $00000308, $755BD200, $000000B2, $4D497407, $0CD60745, $15020B16
    Data.l $58D98FEB, $09000000, $73594870, $C11E0000, $C11E0000, $5469C301
    Data.l $00000053, $4D416704, $B1000041, $61FC0B8F, $00000005, $544C50C0
    Data.l $FFFFFF45, $BBD7D7D7, $9090BBBB, $71717190, $8057838C, $61616078
    Data.l $81818161, $C9F3F3F3, $5565C9C9, $4A5D7A48, $E59E9E9E, $7B84E5E5
    Data.l $3B919E4C, $FF2AB6C9, $A2B300EC, $3D6B7435, $50ADADAD, $46813649
    Data.l $1C3DAB2C, $A01835B2, $47582241, $3B7E883D, $4C00DBF3, $41693F49
    Data.l $2844922E, $E5445E66, $3E5913CE, $54626F2E, $41505050, $C2D72835
    Data.l $344F6520, $7C333B48, $4E7A5E6A, $4F6A7230, $B92F3538, $DDF364A6
    Data.l $6FEBFF6E, $996CC3D7, $2B2E6D89, $191B1D22, $C96DD2E5, $030469BB
    Data.l $3D506303, $9A5FB8FD, $96A6697D, $A5D5FE6E, $8F96C2E2, $A6C1687D
    Data.l $720FA685, $0900009F, $41444947, $EDDA7854, $B2730B5A, $020516BA
    Data.l $09794498, $140B02F8, $D6A38FAC, $3DEB5FAA, $FFFFF1F5, $287849D5
    Data.l $6DEDA8C1, $E7733399, $8F8CE9EE, $F7B2B206, $44EF6BDA, $56FFE104
    Data.l $DC9A8997, $20009622, $081AFFE9, $83BA0929, $861FBF7E, $0617AF61
    Data.l $05FE803B, $BAEC0810, $2C816A7D, $02620C61, $FA831068, $0C4515E7
    Data.l $58AC5B80, $13D4E397, $65AC56BB, $E23D785F, $3BABD095, $34D0323A
    Data.l $31234824, $A3D045F3, $12C2E8AE, $B825804E, $7558730B, $2BD9C019
    Data.l $4B05911A, $608BEA1D, $89CD5DE7, $650C81A6, $209E36AD, $C3A778B9
    Data.l $B4A61C51, $0C4E0570, $670D0A24, $1DC3AB5E, $80C529A5, $EECC18C2
    Data.l $01EB978D, $27F2C2E2, $C5D2A340, $50402EF7, $3634C1A8, $0C34D11D
    Data.l $2FF72FBB, $7DF85881, $33F62343, $EF9458C0, $8D4A225F, $915AC81A
    Data.l $82E18227, $9DCC6103, $3421AF51, $E6933332, $6FE76412, $E23492A6
    Data.l $BEFE0106, $86D695A4, $3C65D925, $39C41B84, $EEC2F13C, $C3043BEF
    Data.l $CD34267C, $8B15A0A2, $2067511D, $448EA8F9, $5A96E2B7, $40A00D8A
    Data.l $03C8B974, $1A07E0BD, $69768875, $9D7EFD87, $ADE4B13C, $1049E8A7
    Data.l $89E17840, $3A89CD94, $6CDABD87, $B53DC74A, $1769ACB5, $82D46B05
    Data.l $65306AA3, $E740ECE7, $97D36C3F, $EEEA137D, $1FD7AA48, $3A46A1AC
    Data.l $90FCCE1D, $224A67DB, $5BB520AD, $BD559687, $A9AFDD41, $94E9C3A3
    Data.l $67CC02C0, $0AEBB7F2, $46879A78, $1453BFAB, $43479F53, $59B1F17B
    Data.l $F0BAE06C, $39FA69C8, $B85E7313, $2105C775, $94B68A94, $74E9FE38
    Data.l $49B66F58, $02A73BE4, $F991A8CA, $C75296A1, $B69A6338, $2BD93801
    Data.l $D509EA56, $FEDBB61F, $9F2490E1, $66A253E4, $21C76B68, $EEA12964
    Data.l $4FB1C7F7, $E6161C80, $E3ADB13C, $A0D468D3, $933AC95E, $10ECDD46
    Data.l $92AB6CE5, $964F0410, $8F126FE5, $1ED26D64, $5B1F366F, $FC849FEA
    Data.l $D5D46F53, $0000B992, $C642EB0D, $4F0E220D, $3FB263FB, $27D39346
    Data.l $3F938F15, $6CCF135E, $1FD49F4E, $8B535478, $94DA3D8A, $29A0C20E
    Data.l $99B53A67, $ED470F6E, $9F1D3878, $E7C71436, $979399C9, $91391A85
    Data.l $FA56D44B, $A65784E1, $82DB646B, $B5349ED3, $735AFB38, $9309F6F1
    Data.l $12C602CD, $3F6CD08D, $16506937, $0CA6D5B6, $1E917F95, $406E56F4
    Data.l $EE30D1BA, $26C228E5, $71A165C8, $AAAC4B51, $C9F1D3F2, $B0C51DB2
    Data.l $D4A00EA3, $A623BFC0, $6202B408, $97EDD033, $B809ABAD, $6601D4D8
    Data.l $1D3928C9, $A3B2CB0D, $FCFD31C3, $A52EA23B, $7EBA46BB, $0A00C606
    Data.l $33B6D3AE, $B6530081, $F73F91FB, $F89113A7, $01BFBFFC, $AE7D0603
    Data.l $B49F4879, $40A76DDB, $47C91A0B, $14F305B3, $E2C99B75, $DACCFFB4
    Data.l $FC0BF030, $8C3E5D80, $27C80810, $36B3CC38, $D661E6A0, $1205C5ED
    Data.l $9BB73401, $CFFA5C2C, $80DEEA89, $6211DBD1, $674EE324, $493CE97B
    Data.l $49775FE1, $59F2EF3A, $53DB36E1, $D3F1A0EA, $1731E8C8, $69781045
    Data.l $8698FB71, $D29ED2DD, $6A8FEE3D, $227AD5AB, $1B8EBD3D, $8DECC51F
    Data.l $3674F31F, $B998E3E0, $F4BE2E69, $1A537882, $71688D2E, $A08E7C3B
    Data.l $6B6F2A3C, $89DDFC81, $777C4359, $A94C7A50, $688FBDF3, $52D461B3
    Data.l $B1A02302, $6D6304E5, $DF5D91A3, $1CB8700F, $C6334C77, $26D42BA4
    Data.l $13BE39A6, $AAAAE47B, $6D4F7CB2, $E5EAA8AD, $619BE90C, $6833B2A9
    Data.l $520924B5, $0A3B4941, $A6C674D1, $C26AEB71, $1BE28590, $B67572CA
    Data.l $37FEA1A5, $164D3307, $EECBC0C6, $766D0881, $1FC8BBE9, $5F0DFEFA
    Data.l $B4931BC8, $A76CC444, $36F56484, $A21DBF57, $3B8584B2, $5E47A2F9
    Data.l $A15F482F, $3736FB69, $6CCF741B, $032FCD9F, $DF1ABD59, $384ACF6D
    Data.l $8B708CBA, $357B34C1, $11E6DB7D, $DB0CEC44, $29FC9B25, $CDBD5903
    Data.l $173B32BE, $67FEC247, $389DA53A, $E8671DC6, $68C21FCF, $8E0C1B3F
    Data.l $FB7BF2D5, $1E8E0BEE, $EEE468B3, $167D2DFA, $3630C377, $BAEAE71D
    Data.l $BB768C2A, $FF356382, $AD6A0632, $2A5F8C8B, $B160C604, $EF2F6209
    Data.l $131BBA43, $F6D1843F, $6F8C382B, $02CF90E1, $B3542A5A, $4AF41070
    Data.l $0ACC0E04, $DDA34441, $7963847E, $3B91EA4F, $7A72BD53, $1D87214B
    Data.l $79596344, $464EB0EB, $708FE1F3, $D241B2E8, $DC598DEB, $528E172E
    Data.l $3B6C68B2, $65B32344, $AF8EA3EE, $43F15C61, $0866A5B9, $32DCB3CE
    Data.l $0802BDCA, $39152CAB, $2C07D16D, $CD9A3A75, $2B2D6181, $301BA238
    Data.l $A856F470, $9DDB930C, $A49AA5FE, $D7869B4E, $1060E238, $23C91A14
    Data.l $2BCB0907, $8DCFE30B, $CB9404A2, $80B97598, $9EE2ACE2, $BE96E1A7
    Data.l $50617260, $DB4721C4, $96D3575E, $3BE6961F, $FD655393, $F438D377
    Data.l $38F10ECE, $73B7404D, $8B00CADE, $655C6303, $1DDF3BC7, $E61D8DF0
    Data.l $75684031, $93FD0B0D, $38627D78, $7AB3F419, $183CFA23, $6F2A255E
    Data.l $94373E1D, $A8D7DC0A, $6469040C, $19A452FB, $814535E0, $74BDF413
    Data.l $D72A2F28, $786C6E30, $1995D593, $751496EC, $4512470A, $64315DE9
    Data.l $0A71C7E2, $0D7CF9B4, $F1855863, $A21C837A, $A5638D72, $68C1A5A8
    Data.l $EF166BDA, $536F7E83, $C6C19949, $85BCD28F, $D772390C, $6BAA7F38
    Data.l $807ED1BC, $D58E0E57, $4B99F99F, $FF848EFA, $D101981C, $C2435CAD
    Data.l $6CDB47AC, $F6E91F17, $0C71D2F7, $8ADD09CD, $F1E7FC4E, $9517D055
    Data.l $CCA48B5A, $6F8AEAF9, $CF5773EF, $49AB4282, $872AFF9C, $184DA808
    Data.l $76186107, $24D919B4, $F7FBB0CC, $E8B4CA92, $C834F25C, $E9783763
    Data.l $94B95754, $A4054760, $81A6A671, $ACEDF144, $B757ADE8, $75E53DEC
    Data.l $041877BE, $700D2FD9, $E9E97413, $42B9CBC7, $DE7FE6A0, $F30C32B5
    Data.l $6ABD5492, $4B4A92CA, $665681F7, $D2500959, $60B728DB, $1CBA8464
    Data.l $173C0C77, $FF25E0BB, $6E1295E4, $54A804B7, $DC6DCBEB, $64AEF57B
    Data.l $A854EDEB, $C7F5DCAC, $BFAE946B, $24F1AA59, $ADF7E718, $8FE58852
    Data.l $96C8B946, $38570470, $155082D6, $3F2EF519, $BE11AF28, $C7EDC1B5
    Data.l $4EDA84E5, $B931C2CA, $A4114387, $CE7C254A, $E57C39AA, $9C3150E3
    Data.l $9082C4FB, $7B17A38B, $EACAA2D3, $7BFDA7AC, $B342E638, $44B3045A
    Data.l $3181F9D6, $C6B67616, $EFE13DA1, $4E61FB72, $DE19C955, $BAB831C2
    Data.l $EE2A02B9, $88BB1718, $6F21C739, $C3B4794E, $9320CE0F, $16566818
    Data.l $BF4B8A58, $72F3BD53, $22FD9552, $633AF8C0, $C2BB3ED6, $26E8401B
    Data.l $4AAE8C46, $9AFDB32C, $BC381757, $A82C8301, $46BD2DD2, $CF953D57
    Data.l $781A9D3D, $4AAFF012, $EE80C59B, $7F612546, $ADC32A55, $6410FD72
    Data.l $71E7DF76, $E1D5A6AA, $3817A490, $B166CA9C, $F3B70EC4, $6DE50A65
    Data.l $5B86546D, $B5E34551, $0E966852, $0F6DD1AF, $2482A0FD, $C2B8A2E4
    Data.l $82E0EA41, $B36F9DE6, $747687A3, $2D210C7D, $8A6BE58C, $B9F5E1D9
    Data.l $5FE685D9, $E9619841, $B1C4C185, $E371FC87, $1D64992A, $38BB261A
    Data.l $CFF837CB, $ED918841, $3E638A1B, $659AEFB7, $97F3BEFA, $6B1B5D53
    Data.l $F4A45395, $83510871, $FB30B90A, $4FDBC39B, $71A7A154, $5FD9A1FB
    Data.l $8BB24318, $98B4E00D, $094E38A2, $A1A73FEF, $18670F5A, $C05F864E
    Data.l $6194BD61, $B8ACC5C4, $E0F05788, $1FB64848, $1F4FE14E, $EE271903
    Data.l $A0BD3225, $A5FD0948, $F08998A8, $40FBDCC0, $D13D9686, $E84047A2
    Data.l $6E96BB91, $104106B7, $9844CECF, $C7823016, $8077A9C7, $902AFB3C
    Data.l $DE0473E8, $54F88E7D, $36E081EC, $D1FD8046, $C1C250B6, $01DC7743
    Data.l $8F2E3432, $76FF4070, $BA5158B2, $1D2FCE58, $FCA79468, $0C0E97CB
    Data.l $7B77875D, $4D2F2933, $3602F997, $99FC9DB4, $6007EB94, $043ED140
    Data.l $942D3C5F, $8B1BE7A2, $4601232C, $6D9EC555, $904CA4A7, $39630D99
    Data.l $FE2F4A8F, $9225A1F2, $B4345A99, $6A87B89F, $6F861A18, $A6D75E93
    Data.l $95A8AD9A, $2F086CD3, $215AD947, $B7EEFDC3, $65D4399E, $C4B5CCC3
    Data.l $EC7BD476, $7E7F9B4E, $D0C611BC, $04868175, $D2E9D1BD, $BD74195C
    Data.l $239E3F6F, $1456404A, $BDDF2192, $2886B190, $24401088, $C96CD060
    Data.l $273F5D5A, $3FDA0FFF, $2E1119AF, $23FAF4EA, $00000000, $444E4549
    Data.b - 82, 66, 96, -126
EndDataSection