'This is a PowerBASIC 32-bit DLL
'using pure SDK programming style "a la Petzold" (just like in plain C)
'
'Complete source code + DLL could be downloaded from there:
'http://www.zapsolution.com/preview/skssfx.zip
'(size of the ZIP file: 9064 bytes)
'
'Author's web site:
'http://www.zapsolution.com
'Want to see what could be done with PowerBASIC then give a try to this:
'http://www.zapsolution.com/preview/WinLIFT.exe
'
'
VB Code:
  1. SUB skEffect ALIAS "skEffect" (BYVAL hDC&, _                 ' Destination device context
  2.                                BYVAL xDest&, _               ' Upper-left X coordinate (pixels)
  3.                                BYVAL yDest&, _               ' Upper-left Y coordinate (pixels)
  4.                                BYVAL nWidth&, _              ' Width of destination
  5.                                BYVAL nHeight&, _             ' Height of destination
  6.                                BYVAL hSrcBMP&, _             ' Handle of the source bitmap
  7.                                BYVAL Dummy&, _               ' Unused
  8.                                BYVAL CallBackFX AS DWORD, _  ' CODEPTR
  9.                                BYVAL uGrain&, _              ' Pixel square size
  10.                                BYVAL uDelay&, _              ' Speed effect in millisecond
  11.                                BYVAL UseEffect&) EXPORT      ' The effect type
  12.  
  13.     REGISTER x&, y&
  14.  
  15.     DIM Bm(2) AS BITMAP, hTmpBmp&(2), hDC&(2), hTmpDC&(2)
  16.     DIM bmi As BITMAPINFO
  17.     DIM pBits0 AS BYTE PTR, pBits1 AS BYTE PTR, pBits2 AS BYTE PTR
  18.  
  19.     hDC&(1) = CreateCompatibleDC(hDC&)
  20.     CALL SelectObject(hDC&(1), hSrcBMP&)
  21.  
  22.     hDC&(2) = CreateCompatibleDC(hDC&)
  23.     hResultBmp& = CreateCompatibleBitmap(hDC&, nWidth&, nHeight&)
  24.     hDestPrevBmp& = SelectObject(hDC&(2), hResultBmp&)
  25.     CALL BitBlt(hDC&(2), 0, 0, nWidth&, nHeight&, hDC&, xDest&, yDest&, %SRCCOPY)
  26.  
  27.     bmi.bmiHeader.biSize = SIZEOF(bmi.bmiHeader)
  28.     bmi.bmiHeader.biWidth = nWidth&
  29.     bmi.bmiHeader.biHeight = nHeight&
  30.     bmi.bmiHeader.biPlanes = 1
  31.     bmi.bmiHeader.biBitCount = 32
  32.     bmi.bmiHeader.biCompression = %BI_RGB
  33.     FOR K& = 2 TO 0 STEP -1
  34.        hTmpDC&(K&) = CreateCompatibleDC (hDC&)
  35.        hTmpBmp&(K&) = CreateDIBSection(hTmpDC&(K&), bmi, %DIB_RGB_COLORS, 0, 0, 0)
  36.        CALL GlobalLock(hTmpBmp&(K&))
  37.        CALL SelectObject(hTmpDC&(K&), hTmpBmp&(K&))
  38.        IF K& THEN
  39.           CALL BitBlt(hTmpDC&(K&), 0, 0, nWidth&, nHeight&, hDC&(K&), 0, 0, %SRCCOPY)
  40.        END IF
  41.        CALL GetObject(hTmpBmp&(K&), SIZEOF(bm(K&)), bm(K&))
  42.        IF K& = 0 THEN
  43.           SELECT CASE LONG UseEffect&
  44.           CASE FxAlphablend ' Alphablending using using uGrain& as percent value
  45.                GOSUB ResetPTR
  46.                p1& = uGrain&: p2& = 100 - uGrain&
  47.                FOR Y& = nHeight& - 1 TO 0 STEP - 1
  48.                    FOR X& = nWidth& - 1 TO 0 STEP -1
  49.                        GOSUB ComputePTR
  50.                    NEXT
  51.                NEXT
  52.                GOSUB DisplayFX
  53.                GOSUB DelayFX
  54.           CASE FxTop, FxBottom ' 1 = Dissolve from top
  55.                                ' 2 = Dissolve from bottom
  56.                GOSUB ResetPTR
  57.                FOR Y& = nHeight& - 1 TO 0 STEP - 1
  58.                    Percent& = Y& / nHeight& * 100
  59.                    IF UseEffect& = 1 THEN
  60.                       p1& = percent&: p2& = 100 - percent&
  61.                    ELSE
  62.                       p1& = 100 - percent&: p2& = percent&
  63.                    END IF
  64.                    FOR X& = nWidth& - 1 TO 0 STEP -1
  65.                        GOSUB ComputePTR
  66.                    NEXT
  67.                NEXT
  68.                GOSUB DisplayFX
  69.                GOSUB DelayFX
  70.           CASE FxLeft, FxRight ' 3 = Dissolve from left
  71.                                ' 4 = Dissolve from right
  72.                GOSUB ResetPTR
  73.                FOR Y& = nHeight& - 1 TO 0 STEP - 1
  74.                    FOR X& = nWidth& - 1 TO 0 STEP -1
  75.                        Percent& = X& / nWidth& * 100
  76.                        IF UseEffect& = 3 THEN
  77.                           p1& = 100 - percent&: p2& = percent&
  78.                        ELSE
  79.                           p2& = 100 - percent&: p1& = percent&
  80.                        END IF
  81.                        GOSUB ComputePTR
  82.                    NEXT
  83.                NEXT
  84.                GOSUB DisplayFX
  85.                GOSUB DelayFX
  86.           CASE FxHorzCenter, FxVertCenter ' 5 = Dissolve horizontaly to center
  87.                                           ' 6 = Dissolve verticaly to center
  88.                GOSUB ResetPTR
  89.                FOR Y& = nHeight& - 1 TO 0 STEP - 1
  90.                    IF UseEffect& = 5 THEN
  91.                       IF Y& < nHeight& \ 2 THEN
  92.                          Percent& = (Y& / nHeight& * 100) * 2
  93.                       ELSE
  94.                          Percent& = 200 - ((Y& / nHeight& * 100) * 2)
  95.                       END IF
  96.                       p2& = 100 - percent&: p1& = percent&
  97.                    END IF
  98.                    FOR X& = nWidth& - 1 TO 0 STEP -1
  99.                        IF UseEffect& = 6 THEN
  100.                           IF X& < nWidth& \ 2 THEN
  101.                              Percent& = (X& / nWidth& * 100) * 2
  102.                           ELSE
  103.                              Percent& = 200 - ((X& / nWidth& * 100) * 2)
  104.                           END IF
  105.                           p2& = 100 - percent&: p1& = percent&
  106.                        END IF
  107.                        GOSUB ComputePTR
  108.                    NEXT
  109.                NEXT
  110.                GOSUB DisplayFX
  111.                GOSUB DelayFX
  112.           CASE FxCenter    ' 7 = Dissolve to center
  113.                GOSUB ResetPTR
  114.                FOR Y& = nHeight& - 1 TO 0 STEP - 1
  115.                    IF Y& < nHeight& \ 2 THEN
  116.                       P& = (Y& / nHeight& * 100) * 2
  117.                    ELSE
  118.                       P& = 200 - ((Y& / nHeight& * 100) * 2)
  119.                    END IF
  120.                    FOR X& = nWidth& - 1 TO 0 STEP -1
  121.                        IF X& < nWidth& \ 2 THEN
  122.                           Percent& = (X& / nWidth& * 100) * 2
  123.                        ELSE
  124.                           Percent& = 200 - ((X& / nWidth& * 100) * 2)
  125.                        END IF
  126.                        IF P& < Percent& THEN Percent& = P&
  127.                        p2& = 100 - percent&: p1& = percent&
  128.                        GOSUB ComputePTR
  129.                    NEXT
  130.                NEXT
  131.                GOSUB DisplayFX
  132.                GOSUB DelayFX
  133.           CASE ELSE ' Full dissolve
  134.                FOR Percent& = 1 TO 100 STEP uGrain&
  135.                    GOSUB ResetPTR
  136.                    p1& = percent&: p2& = 100 - percent&
  137.                    FOR Y& = nHeight& - 1 TO 0 STEP - 1
  138.                        FOR X& = nWidth& - 1 TO 0 STEP -1
  139.                            GOSUB ComputePTR
  140.                        NEXT
  141.                    NEXT
  142.                    GOSUB DisplayFX
  143.                    IF uDelay& THEN
  144.                       T??? = GetTickCount + uDelay&
  145.                       DO WHILE GetTickCount < T???
  146.                          CALL apiSLEEP(0)
  147.                          GOSUB CheckStatusFX: IF BailOut& THEN EXIT DO
  148.                       LOOP
  149.                    ELSE
  150.                       GOSUB CheckStatusFX
  151.                    END IF
  152.                    IF BailOut& THEN EXIT FOR
  153.                NEXT
  154.           END SELECT
  155.           FOR T& = 0 TO 2
  156.               CALL GlobalUnLock(hTmpBmp&(T&))
  157.               CALL DeleteDC(hTmpDC&(T&)): CALL DeleteObject(hTmpBmp&(T&))
  158.           NEXT
  159.        END IF
  160.     NEXT
  161.   ' Select original objects back.
  162.     CALL SelectObject(hDC&(2), hDestPrevBmp&)
  163.   ' Deallocate system resources.
  164.     CALL DeleteObject(hResultBmp&)
  165.     FOR K& = 1 TO 2
  166.         DeleteDC hDC&(K&)
  167.     NEXT
  168.     EXIT SUB
  169.    
  170. ResetPTR:
  171.     pBits0 = bm(0).bmBits
  172.     pBits1 = bm(1).bmBits
  173.     pBits2 = bm(2).bmBits
  174.     RETURN    
  175. ComputePTR:
  176.     @pBits0[2] = ((p1& * @pBits1[2] + p2& * @pBits2[2])) \ 100
  177.     @pBits0[1] = ((p1& * @pBits1[1] + p2& * @pBits2[1])) \ 100
  178.     @pBits0[0] = ((p1& * @pBits1[0] + p2& * @pBits2[0])) \ 100
  179.     pBits0 = pBits0 + 4: pBits1 = pBits1 + 4: pBits2 = pBits2 + 4
  180.     RETURN
  181. DelayFX:
  182.     IF uDelay& THEN
  183.        T??? = GetTickCount + uDelay&
  184.        DO WHILE GetTickCount < T???
  185.           CALL apiSLEEP(0)
  186.           GOSUB CheckStatusFX: IF BailOut& THEN EXIT DO
  187.        LOOP
  188.     END IF
  189.     RETURN
  190. CheckStatusFX:
  191.     IF CallBackFX THEN
  192.        CALL DWORD CallBackFX USING StatusCallBack(0) TO BailOut&
  193.        IF BailOut& <> ERROR_USER_ABORT THEN BailOut& = 0
  194.     END IF
  195.     RETURN
  196. DisplayFX:
  197.     CALL BitBlt(hDC&, xDest&, yDest&, nWidth&, nHeight&, hTmpDC&(K&), 0, 0, %SRCCOPY)
  198.     RETURN
  199. END SUB
  200. '