Part III, Code Part II:
VB Code:
  1. Public Function SmoothIconBlt(ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hExeSrc As String, ByVal hIndex As Long, ByVal hSmallIcon As Boolean) As Long
  2. Dim hSmIco As Long
  3. Dim hLgIco As Long
  4. Dim hResult As Long
  5.  
  6. Dim hImgDC As Long
  7. Dim hMaskDC As Long
  8. Dim hTempDC As Long
  9.  
  10.     hImgDC = CreateMyDC(16, 16)
  11.     hMaskDC = CreateMyDC(16, 16)
  12.     hTempDC = CreateMyDC(16, 16)
  13.    
  14.     Call ExtractIconEx(hExeSrc, hIndex, hLgIco, hSmIco, 1)
  15.     If hSmallIcon Then
  16.         hResult = DrawIconEx(hMaskDC, 0, 0, hSmIco, 16, 16, 0, 0, DI_MASK)
  17.         hResult = DrawIconEx(hImgDC, 0, 0, hSmIco, 16, 16, 0, 0, DI_IMAGE)
  18.         SmoothMaskFast hTempDC, hMaskDC, 0, 0, 16, 16, smoothval
  19.         AlphaBltFast hDestDC, X, Y, 16, 16, hImgDC, hMaskDC, 0, 0
  20.     Else
  21.         hResult = DrawIconEx(hMaskDC, 0, 0, hLgIco, 32, 32, 0, 0, DI_MASK)
  22.         hResult = DrawIconEx(hImgDC, 0, 0, hLgIco, 32, 32, 0, 0, DI_IMAGE)
  23.         SmoothMaskFast hTempDC, hMaskDC, 0, 0, 32, 32, smoothval * 2
  24.         AlphaBltFast hDestDC, X, Y, 32, 32, hImgDC, hMaskDC, 0, 0
  25.     End If
  26.     DestroyIcon hSmIco: DestroyIcon hLgIco
  27.    
  28.     ReleaseDC frmMain.hwnd, hImgDC
  29.     ReleaseDC frmMain.hwnd, hMaskDC
  30.     ReleaseDC frmMain.hwnd, hTempDC
  31.    
  32. End Function
  33. Public Function SmoothMaskFast(ByVal hDestDC As Long, ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal hWidth As Long, ByVal hHeight As Long, ByVal hSmoothWeight As Long)
  34. Dim hInverse As Long
  35. Dim I As Long, J As Long
  36. Dim Base As Long
  37. Dim Plus As Long
  38. Dim Dot As Long
  39. Dim Q As Long
  40. Dim nDot As Long
  41. Dim nPlus As Long
  42.  
  43. Dim xBitmap As Long
  44. Dim xBMP As BITMAP
  45. Dim xPic() As mRGB
  46. Dim xMem As BITMAPINFO
  47.  
  48.     xBitmap = GetCurrentObject(hDestDC, OBJ_BITMAP)
  49.     GetObjectAPI xBitmap, Len(xBMP), xBMP
  50.     With xMem.bmiHeader
  51.         .biBitCount = 32
  52.         .biCompression = BI_RGB
  53.         .biPlanes = 1
  54.         .biSize = Len(xMem.bmiHeader)
  55.         .biWidth = xBMP.bmWidth
  56.         .biHeight = xBMP.bmHeight
  57.         ReDim Preserve xPic(0 To (.biWidth * .biHeight) - 1) As mRGB
  58.     End With
  59.     GetDIBits hDestDC, xBitmap, 0, xBMP.bmHeight, xPic(0), xMem, DIB_RGB_COLORS
  60.  
  61.     hInverse = 100 - (6 * hSmoothWeight)
  62.    
  63.     '.+.   This requires explaining. # will recieve hInverse rating, + will
  64.     '+#+   recieve hSmoothWeight rating, and . will recieve half of hSmoothWieght
  65.     '.+.   as its rating. Thus 4 * hSmoothWeight + (4 * 0.5) * hSmoothWeight, or 6 * hSmoothweight
  66.    
  67.     For J = Y To Y + (hHeight - 1)
  68.         For I = X To X + (hWidth - 1)
  69.            
  70.             Dot = 0
  71.             Q = 0
  72.             Base = 0
  73.             Plus = 0
  74.             nPlus = 0
  75.             nDot = 0
  76.            
  77.             Q = xPic(Morph2D(I, hHeight - J, hWidth)).R
  78.             Base = Mono(Q)
  79.            
  80.             If Base = 0 Then
  81.            
  82.                 If I - 1 >= X Then
  83.                     Plus = Plus + MonoA(xPic(Morph2D(I - 1, hHeight - J, hWidth)).R)
  84.                     nPlus = nPlus + 1
  85.                     If J - 1 >= Y Then
  86.                         Dot = Dot + MonoA(xPic(Morph2D(I - 1, hHeight - (J - 1), hWidth)).R)
  87.                         nDot = nDot + 1
  88.                     End If
  89.                     If J + 1 <= Y + (hHeight - 1) Then
  90.                         Dot = Dot + MonoA(xPic(Morph2D(I - 1, hHeight - (J + 1), hWidth)).R)
  91.                         nDot = nDot + 1
  92.                     End If
  93.                 End If
  94.                
  95.                 If I + 1 <= X + (hWidth - 1) Then
  96.                     Plus = Plus + MonoA(xPic(Morph2D(I + 1, hHeight - J, hWidth)).R)
  97.                     nPlus = nPlus + 1
  98.                     If J - 1 >= Y Then
  99.                         Dot = Dot + MonoA(xPic(Morph2D(I + 1, hHeight - (J - 1), hWidth)).R)
  100.                         nDot = nDot + 1
  101.                     End If
  102.                     If J + 1 <= Y + (hHeight - 1) Then
  103.                         Dot = Dot + MonoA(xPic(Morph2D(I + 1, hHeight - (J + 1), hWidth)).R)
  104.                         nDot = nDot + 1
  105.                     End If
  106.                 End If
  107.                
  108.                 If J + 1 <= Y + (hHeight - 1) Then
  109.                     Plus = Plus + MonoA(xPic(Morph2D(I, hHeight - (J + 1), hWidth)).R)
  110.                     nPlus = nPlus + 1
  111.                 End If
  112.                
  113.                 If J - 1 >= Y Then
  114.                     Plus = Plus + MonoA(xPic(Morph2D(I, hHeight - (J - 1), hWidth)).R)
  115.                     nPlus = nPlus + 1
  116.                 End If
  117.                
  118.                 Plus = Plus / nPlus
  119.                 Dot = Dot / nDot
  120.                
  121.                 Base = ((hInverse / 100) * Base) + ((hSmoothWeight * 4 / 100) * Plus) + ((hSmoothWeight * 2 / 100) * Dot)
  122.                
  123.                 With xPic(Morph2D(I, hHeight - J, hWidth))
  124.                     .R = Base
  125.                     .G = Base
  126.                     .B = Base
  127.                 End With
  128.            
  129.             End If
  130.            
  131.         Next I
  132.     Next J
  133.    
  134.     SetDIBits hDestDC, xBitmap, 0, xBMP.bmHeight, xPic(0), xMem, DIB_RGB_COLORS
  135.    
  136. End Function
  137. Public Function SmoothMask(ByVal hDestDC As Long, ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal hWidth As Long, ByVal hHeight As Long, ByVal hSmoothWeight As Long)
  138. Dim hInverse As Long
  139. Dim I As Long, J As Long
  140. Dim Base As Long
  141. Dim Plus As Long
  142. Dim Dot As Long
  143. Dim Q As Long
  144. Dim nDot As Long
  145. Dim nPlus As Long
  146.  
  147.     hInverse = 100 - (6 * hSmoothWeight)
  148.    
  149.     '.+.   This requires explaining. # will recieve hInverse rating, + will
  150.     '+#+   recieve hSmoothWeight rating, and . will recieve half of hSmoothWieght
  151.     '.+.   as its rating. Thus 4 * hSmoothWeight + (4 * 0.5) * hSmoothWeight, or 6 * hSmoothweight
  152.    
  153.     For J = Y To Y + (hHeight - 1)
  154.         For I = X To X + (hWidth - 1)
  155.            
  156.             Dot = 0
  157.             Q = 0
  158.             Base = 0
  159.             Plus = 0
  160.             nPlus = 0
  161.             nDot = 0
  162.            
  163.             Q = GetPixel(hDestDC, I, J)
  164.             Base = Mono(Q)
  165.            
  166.             If Base = 0 Then
  167.            
  168.                 Q = GetPixel(hdc, I - 1, J)
  169.                 If Q <> -1 Then
  170.                     Plus = Plus + Mono(Q)
  171.                     nPlus = nPlus + 1
  172.                 End If
  173.                 Q = GetPixel(hdc, I + 1, J)
  174.                 If Q <> -1 Then
  175.                     Plus = Plus + Mono(Q)
  176.                     nPlus = nPlus + 1
  177.                 End If
  178.                 Q = GetPixel(hdc, I, J - 1)
  179.                 If Q <> -1 Then
  180.                     Plus = Plus + Mono(Q)
  181.                     nPlus = nPlus + 1
  182.                 End If
  183.                 Q = GetPixel(hdc, I, J + 1)
  184.                 If Q <> -1 Then
  185.                     Plus = Plus + Mono(Q)
  186.                     nPlus = nPlus + 1
  187.                 End If
  188.                 Plus = Plus / nPlus
  189.            
  190.                 Q = GetPixel(hdc, I - 1, J - 1)
  191.                 If Q <> -1 Then
  192.                     Dot = Dot + Mono(Q)
  193.                     nDot = nDot + 1
  194.                 End If
  195.                 Q = GetPixel(hdc, I + 1, J - 1)
  196.                 If Q <> -1 Then
  197.                     Dot = Dot + Mono(Q)
  198.                     nDot = nDot + 1
  199.                 End If
  200.                 Q = GetPixel(hdc, I - 1, J + 1)
  201.                 If Q <> -1 Then
  202.                     Dot = Dot + Mono(Q)
  203.                     nDot = nDot + 1
  204.                 End If
  205.                 Q = GetPixel(hdc, I + 1, J + 1)
  206.                 If Q <> -1 Then
  207.                     Dot = Dot + Mono(Q)
  208.                     nDot = nDot + 1
  209.                 End If
  210.                 Dot = Dot / nDot
  211.            
  212.                 Base = ((hInverse / 100) * Base) + ((hSmoothWeight * 4 / 100) * Plus) + ((hSmoothWeight * 2 / 100) * Dot)
  213.                 SetPixelV hDestDC, I, J, RGB(Base, Base, Base)
  214.            
  215.             End If
  216.            
  217.         Next I
  218.     Next J
  219.    
  220. End Function
  221. Public Function Mono(Valu As Long) As Long
  222.     If Valu = 0 Then Mono = 0 Else Mono = 255
  223. End Function
  224. Public Function MonoA(Valu As Byte) As Long
  225.     If Valu = 0 Then MonoA = 0 Else MonoA = 255
  226. End Function
  227. Public Function CreateMyDC(Width As Long, Height As Long, Optional hCompatDC As Long) As Long
  228. Dim iCompatDC As Long
  229. Dim iDC As Long
  230.  
  231. If IsMissing(hCompatDC) Then
  232.     iCompatDC = GetDC(GetDesktopWindow)
  233. Else
  234.     iCompatDC = hCompatDC
  235. End If
  236.  
  237. iDC = CreateCompatibleDC(iCompatDC)
  238. DeleteObject SelectObject(iDC, CreateCompatibleBitmap(iCompatDC, Width, Height))
  239.  
  240. CreateMyDC = iDC
  241.  
  242. End Function
  243.  
  244. Public Function DestroyDC(lngDC As Long) As Boolean
  245.     ReleaseDC frmMain.hwnd, lngDC
  246. End Function
  247. Public Function Morph2D(X As Long, Y As Long, NumRow As Long) As Long
  248.     Morph2D = (Y - 1) * NumRow + X
  249. End Function