home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / XP_Menu_'2762294262002.psc / c_MenuXP.cls < prev    next >
Encoding:
Visual Basic class definition  |  2002-04-07  |  43.4 KB  |  1,115 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "c_MenuXP"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Description = "Provides methods for painting transparent and disabled looking images."
  15. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  16. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  17. Option Explicit
  18. DefInt A-Z
  19.  
  20. Private Type RECT
  21.     Left       As Long
  22.     Top        As Long
  23.     Right      As Long
  24.     Bottom     As Long
  25. End Type
  26.  
  27. Private Type BITMAPINFOHEADER '40 bytes
  28.     biSize As Long
  29.     biWidth As Long
  30.     biHeight As Long
  31.     biPlanes As Integer
  32.     biBitCount As Integer
  33.     biCompression As Long
  34.     biSizeImage As Long
  35.     biXPelsPerMeter As Long
  36.     biYPelsPerMeter As Long
  37.     biClrUsed As Long
  38.     biClrImportant As Long
  39. End Type
  40.  
  41. Private Type RGBQUAD
  42.     rgbBlue As Byte
  43.     rgbGreen As Byte
  44.     rgbRed As Byte
  45.     rgbReserved As Byte
  46. End Type
  47.  
  48. Private Type BITMAPINFO
  49.     bmiHeader As BITMAPINFOHEADER
  50.     bmiColors(1) As RGBQUAD
  51. End Type
  52.  
  53. Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long) As Long
  54. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  55. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  56. Private Declare Function SetBkColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
  57. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
  58. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
  59. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  60. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
  61. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  62. Private Declare Function FillRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  63. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
  64. Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
  65. Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
  66. Private Declare Function GetBkColor Lib "gdi32" (ByVal hDC As Long) As Long
  67. Private Declare Function GetTextColor Lib "gdi32" (ByVal hDC As Long) As Long
  68. Private Declare Function SelectPalette Lib "gdi32" (ByVal hDC As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
  69. Private Declare Function RealizePalette Lib "gdi32" (ByVal hDC As Long) As Long
  70. Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
  71. Private Declare Function CreateHalftonePalette Lib "gdi32" (ByVal hDC As Long) As Long
  72. Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As Long
  73. Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  74. Private Declare Function SetDIBColorTable Lib "gdi32" (ByVal hDC As Long, ByVal un1 As Long, ByVal un2 As Long, pcRGBQuad As RGBQUAD) As Long
  75. Private Declare Function SetMapMode Lib "gdi32" (ByVal hDC As Long, ByVal nMapMode As Long) As Long
  76. Private Declare Function GetMapMode Lib "gdi32" (ByVal hDC As Long) As Long
  77. Private Declare Function DrawIconEx Lib "user32" (ByVal hDC As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyHeight As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
  78.  
  79. Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  80. Private Declare Function DrawEdge Lib "user32" (ByVal hDC As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
  81. Private Declare Function InflateRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  82.  
  83. Private Declare Function DrawState Lib "user32" Alias "DrawStateA" (ByVal hDC As Long, ByVal hBrush As Long, ByVal lpDrawStateProc As Long, ByVal lParam As Long, ByVal wParam As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal un As Long) As Long
  84.  
  85. 'DrawIconEx Flags
  86. Private Const DI_MASK = &H1
  87. Private Const DI_IMAGE = &H2
  88. Private Const DI_NORMAL = &H3
  89. Private Const DI_COMPAT = &H4
  90. Private Const DI_DEFAULTSIZE = &H8
  91.  
  92. 'DIB Section constants
  93. Private Const BI_RGB = 0&
  94. Private Const DIB_RGB_COLORS = 0 '  color table in RGBs
  95.  
  96. 'Raster Operation Codes
  97. Private Const DSna = &H220326 '0x00220326
  98.  
  99. Private Const giINVALID_PICTURE As Integer = 481
  100.  
  101. Private Const DSS_DISABLED = &H20
  102. Private Const DSS_MONO = &H80
  103. Private Const DSS_NORMAL = &H0
  104. Private Const DSS_RIGHT = &H8000
  105. Private Const DSS_UNION = &H10
  106. Private Const DST_BITMAP = &H4
  107. Private Const DST_COMPLEX = &H0
  108. Private Const DST_ICON = &H3
  109. Private Const DST_PREFIXTEXT = &H2
  110. Private Const DST_TEXT = &H1
  111.  
  112. Private m_hpalHalftone As Long  'Halftone created for default palette use
  113.  
  114. Public Sub TileBitmapToHDC(ByVal lhDCDest As Long, _
  115.                            ByVal picSource As Picture, _
  116.                            ByVal lLeft As Long, _
  117.                            ByVal lTop As Long, _
  118.                            ByVal lWidth As Long, _
  119.                            ByVal lHeight As Long, _
  120.                            ByVal lDestLeft As Long, _
  121.                            ByVal lDestTop As Long, _
  122.                            ByVal lDestWidth As Long, _
  123.                            ByVal lDestHeight As Long, _
  124.                            Optional ByVal lhPal As Long)
  125.  
  126.   '-------------------------------------------------------------------------
  127.   'Purpose:   Draws a Bitmap to an HDC without transparency
  128.   'In:
  129.   '   [lhdcDest]
  130.   '           HDC of the memory device context to paint the picture on
  131.   '   [picSource]
  132.   '           Picture to paint
  133.   '   [lLeft]
  134.   '           X coordinate of the upper left corner of the area that the
  135.   '           picture is to be painted on. (in pixels)
  136.   '   [lTop]
  137.   '           Y coordinate of the upper left corner of the area that the
  138.   '           picture is to be painted on. (in pixels)
  139.   '   [lWidth]
  140.   '           Width of picture area to paint in pixels
  141.   '   [lHeight]
  142.   '           Height of picture area to paint in pixels
  143.   '   [lhPal]
  144.   '           Must be a valid HPALETTE
  145.   '-------------------------------------------------------------------------
  146.   
  147.   Dim lhdcTemp As Long
  148.   Dim lhPalOld As Long
  149.   Dim hbmOld As Long
  150.   Dim hDCScreen As Long
  151.   Dim X As Long, Y As Long
  152.   Dim W As Long, H As Long
  153.  
  154.     hDCScreen = GetDC(0&)
  155.  
  156.     If picSource.Type <> vbPicTypeBitmap Then Error.Raise giINVALID_PICTURE
  157.  
  158.     lhdcTemp = CreateCompatibleDC(hDCScreen)
  159.     lhPalOld = SelectPalette(lhdcTemp, lhPal, True)
  160.     RealizePalette lhdcTemp
  161.  
  162.     hbmOld = SelectObject(lhdcTemp, picSource.handle)
  163.  
  164.     For X = lDestLeft To lDestLeft + lDestWidth Step lWidth
  165.         For Y = lDestTop To lDestTop + lDestHeight Step lHeight
  166.  
  167.             If X + lWidth > (lDestLeft + lDestWidth) Then
  168.                 W = (lDestLeft + lDestWidth) - X
  169.               Else
  170.                 W = lWidth
  171.             End If
  172.             If Y + lHeight > (lDestTop + lDestHeight) Then
  173.                 H = (lDestTop + lDestHeight) - Y
  174.               Else
  175.                 H = lHeight
  176.             End If
  177.             BitBlt lhDCDest, X, Y, W, H, lhdcTemp, 0, 0, vbSrcCopy
  178.         Next Y
  179.     Next X
  180.  
  181.     SelectObject lhdcTemp, hbmOld
  182.     SelectPalette lhdcTemp, lhPalOld, True
  183.     RealizePalette (lhdcTemp)
  184.     DeleteDC lhdcTemp
  185.     ReleaseDC 0&, hDCScreen
  186.  
  187. End Sub
  188.  
  189. Public Sub PaintDisabledPicture(ByVal hDCDest As Long, _
  190.                                 ByVal picSource As StdPicture, _
  191.                                 ByVal xDest As Long, _
  192.                                 ByVal yDest As Long, _
  193.                                 ByVal Width As Long, _
  194.                                 ByVal Height As Long, _
  195.                                 Optional ByVal xSrc As Long = 0, _
  196.                                 Optional ByVal ySrc As Long = 0, _
  197.                                 Optional ByVal clrMask As OLE_COLOR = 16711935, _
  198.                                 Optional ByVal hPal As Long = 0)
  199.  
  200.   Dim lbmTemp As Long
  201.   Dim lbmTempOld As Long
  202.   Dim lhdcTemp As Long
  203.   Dim lhPalOld As Long
  204.   Dim udtTempRect As RECT
  205.   Dim lhbrWhite As Long
  206.   Dim hDCScreen As Long
  207.   Dim hBrush As Long
  208.  
  209.     On Error Resume Next
  210.       If picSource Is Nothing Then
  211.  
  212.         ElseIf picSource.Type = vbPicTypeNone Then
  213.  
  214.         ElseIf picSource.Type = vbPicTypeIcon Then
  215.  
  216.           hBrush = CreateSolidBrush(RGB(128, 128, 128))
  217.  
  218.           DrawState hDCDest, hBrush, 0, picSource.handle, 0, xDest, yDest, 0, 0, (DST_ICON Or DSS_MONO)
  219.  
  220.           DeleteObject hBrush
  221.  
  222.         Else
  223.           hDCScreen = GetDC(0&)
  224.           lhdcTemp = CreateCompatibleDC(hDCScreen)     'Create a temporary hDC compatible to the Destination hDC
  225.           lbmTemp = CreateCompatibleBitmap(hDCScreen, Width, Height)
  226.           lbmTempOld = SelectObject(lhdcTemp, lbmTemp)
  227.           lhPalOld = SelectPalette(lhdcTemp, hPal, True)
  228.           RealizePalette lhdcTemp
  229.           With udtTempRect
  230.               .Top = 0
  231.               .Left = 0
  232.               .Bottom = Height
  233.               .Right = Width
  234.           End With
  235.           SetBkColor lhdcTemp, vbWhite
  236.           lhbrWhite = CreateSolidBrush(vbWhite)
  237.           FillRect lhdcTemp, udtTempRect, lhbrWhite
  238.           PaintTransparentPicture lhdcTemp, picSource, 0, 0, Width, Height, xSrc, ySrc, clrMask
  239.           SelectObject lhdcTemp, lbmTempOld
  240.           Err.Clear
  241.  
  242.           hBrush = CreateSolidBrush(RGB(128, 128, 128))
  243.  
  244.           DrawState hDCDest, hBrush, 0, lbmTemp, 0, xDest, yDest, 0, 0, (DST_BITMAP Or DSS_MONO)
  245.  
  246.           DeleteObject hBrush
  247.  
  248.           DeleteObject lhbrWhite
  249.           SelectPalette lhdcTemp, lhPalOld, True
  250.           RealizePalette lhdcTemp
  251.           DeleteObject SelectObject(lhdcTemp, lbmTempOld)
  252.           DeleteObject lbmTempOld
  253.           DeleteObject lbmTemp
  254.           DeleteObject lhPalOld
  255.           DeleteDC lhdcTemp
  256.           ReleaseDC 0&, hDCScreen
  257.       End If
  258.  
  259. End Sub
  260.  
  261. Public Sub PaintCheckedPattern(ByVal hDCDest As Long, ByVal hdcSrc As Long, ByVal xDest As Long, ByVal yDest As Long, _
  262.                                ByVal wRequired As Long, ByVal hRequired As Long, _
  263.                                ByVal clrRequired As OLE_COLOR, Optional ByVal hPal As Long = 0)
  264.  
  265.   Dim hdcMask As Long        'hDC of the created mask image
  266.   Dim hdcColor As Long       'hDC of the created color image
  267.   Dim hbmMask As Long        'Bitmap handle to the mask image
  268.   Dim hbmColor As Long       'Bitmap handle to the color image
  269.   Dim hbmColorOld As Long
  270.   Dim hbmMaskOld As Long
  271.   Dim hPalOld As Long
  272.   Dim hPalBufferOld As Long
  273.   Dim lRequiredColor As Long
  274.   Dim X As Long, Y As Long
  275.   Dim bltWidth As Integer, bltHeight As Integer
  276.   Dim hDCScreen As Long
  277.  
  278.     On Error Resume Next
  279.       hDCScreen = GetDC(0&)
  280.  
  281.       If hPal = 0 Then hPal = m_hpalHalftone
  282.  
  283.       OleTranslateColor clrRequired, hPal, lRequiredColor
  284.  
  285.       hbmColor = CreateCompatibleBitmap(hDCScreen, 8, 8)
  286.  
  287.       hbmMask = CreateBitmap(8, 8, 1, 1, ByVal 0&)
  288.  
  289.       hdcColor = CreateCompatibleDC(hDCScreen)
  290.       hbmColorOld = SelectObject(hdcColor, hbmColor)
  291.       hPalOld = SelectPalette(hdcColor, hPal, True)
  292.       RealizePalette hdcColor
  293.  
  294.       SetBkColor hdcColor, GetBkColor(hdcSrc)
  295.       SetTextColor hdcColor, GetTextColor(hdcSrc)
  296.       BitBlt hdcColor, 0, 0, 8, 8, hdcSrc, 0, 0, vbSrcCopy
  297.  
  298.       hdcMask = CreateCompatibleDC(hDCScreen)
  299.       hbmMaskOld = SelectObject(hdcMask, hbmMask)
  300.  
  301.       SetBkColor hdcColor, vbBlack
  302.       SetTextColor hdcColor, vbWhite
  303.       BitBlt hdcMask, 0, 0, 8, 8, hdcColor, 0, 0, vbSrcCopy
  304.  
  305.       SetTextColor hDCDest, lRequiredColor
  306.  
  307.       For X = xDest To xDest + wRequired Step 8
  308.           For Y = yDest To yDest + hRequired Step 8
  309.  
  310.               If X + 8 > (xDest + wRequired) Then
  311.                   bltWidth = (xDest + wRequired) - X
  312.                 Else
  313.                   bltWidth = 8
  314.               End If
  315.               If Y + 8 > (yDest + hRequired) Then
  316.                   bltHeight = (yDest + hRequired) - Y
  317.                 Else
  318.                   bltHeight = 8
  319.               End If
  320.               BitBlt hDCDest, X, Y, bltWidth, bltHeight, hdcMask, 0, 0, vbSrcCopy
  321.           Next Y
  322.       Next X
  323.  
  324.       DeleteObject SelectObject(hdcColor, hbmColorOld)
  325.       SelectPalette hdcColor, hPalOld, True
  326.       RealizePalette hdcColor
  327.       DeleteDC hdcColor
  328.       DeleteObject SelectObject(hdcMask, hbmMaskOld)
  329.       DeleteDC hdcMask
  330.       ReleaseDC 0&, hDCScreen
  331.  
  332. End Sub
  333.  
  334. '-------------------------------------------------------------------------
  335. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  336. '           input bitmap.
  337. 'In:
  338. '   [hdcDest]
  339. '           Device context to paint the picture on
  340. '   [xDest]
  341. '           X coordinate of the upper left corner of the area that the
  342. '           picture is to be painted on. (in pixels)
  343. '   [yDest]
  344. '           Y coordinate of the upper left corner of the area that the
  345. '           picture is to be painted on. (in pixels)
  346. '   [Width]
  347. '           Width of picture area to paint in pixels.  Note: If this value
  348. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  349. '           instead of the pictures' width in pixels), this procedure will
  350. '           attempt to create bitmaps that require outrageous
  351. '           amounts of memory.
  352. '   [Height]
  353. '           Height of picture area to paint in pixels.  Note: If this
  354. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  355. '           twips instead of the pictures' height in pixels), this
  356. '           procedure will attempt to create bitmaps that require
  357. '           outrageous amounts of memory.
  358. '   [picSource]
  359. '           Standard Picture object to be used as the image source
  360. '   [xSrc]
  361. '           X coordinate of the upper left corner of the area in the picture
  362. '           to use as the source. (in pixels)
  363. '           Ignored if picSource is an Icon.
  364. '   [ySrc]
  365. '           Y coordinate of the upper left corner of the area in the picture
  366. '           to use as the source. (in pixels)
  367. '           Ignored if picSource is an Icon.
  368. '   [clrMask]
  369. '           Color of pixels to be masked out
  370. '   [clrHighlight]
  371. '           Color to be used as outline highlight
  372. '   [clrShadow]
  373. '           Color to be used as outline shadow
  374. '   [hPal]
  375. '           Handle of palette to select into the memory DC's used to create
  376. '           the painting effect.
  377. '           If not provided, a HalfTone palette is used.
  378. '-------------------------------------------------------------------------
  379. Public Sub PaintDisabledPictureEx(ByVal hDCDest As Long, _
  380.                                   ByVal xDest As Long, _
  381.                                   ByVal yDest As Long, _
  382.                                   ByVal Width As Long, _
  383.                                   ByVal Height As Long, _
  384.                                   ByVal picSource As StdPicture, _
  385.                                   Optional ByVal xSrc As Long = 0, _
  386.                                   Optional ByVal ySrc As Long = 0, _
  387.                                   Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  388.                                   Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  389.                                   Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  390.                                   Optional ByVal hPal As Long = 0)
  391. Attribute PaintDisabledPictureEx.VB_Description = "Paints a disabled appearing image (embossed) given a source picture object."
  392.  
  393.   Dim hdcSrc As Long         'hDC that the source bitmap is selected into
  394.   Dim hbmMemSrcOld As Long
  395.   Dim hbmMemSrc As Long
  396.   Dim udtRect As RECT
  397.   Dim hbrMask As Long
  398.   Dim lMaskColor As Long
  399.   Dim hDCScreen As Long
  400.   Dim hPalOld As Long
  401.  
  402.     If picSource Is Nothing Then GoTo PaintDisabledDC_InvalidParam
  403.     Select Case picSource.Type
  404.       Case vbPicTypeBitmap
  405.  
  406.         hDCScreen = GetDC(0&)
  407.  
  408.         If hPal = 0 Then
  409.             hPal = m_hpalHalftone
  410.         End If
  411.         hdcSrc = CreateCompatibleDC(hDCScreen)
  412.         hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  413.         hPalOld = SelectPalette(hdcSrc, hPal, True)
  414.         RealizePalette hdcSrc
  415.  
  416.         PaintDisabledDC hDCDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, clrHighlight, clrShadow, hPal
  417.  
  418.         SelectObject hdcSrc, hbmMemSrcOld
  419.         SelectPalette hdcSrc, hPalOld, True
  420.         RealizePalette hdcSrc
  421.         DeleteDC hdcSrc
  422.         ReleaseDC 0&, hDCScreen
  423.       Case vbPicTypeIcon
  424.  
  425.         hDCScreen = GetDC(0&)
  426.  
  427.         If hPal = 0 Then
  428.             hPal = m_hpalHalftone
  429.         End If
  430.         On Error Resume Next
  431.           DrawState hDCDest, 0, 0, picSource.handle, 0, xDest, yDest, 0, 0, (DST_ICON Or DSS_MONO)
  432.           If Err Then
  433.               hdcSrc = CreateCompatibleDC(hDCScreen)
  434.               hbmMemSrc = CreateCompatibleBitmap(hDCScreen, Width, Height)
  435.               hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  436.               hPalOld = SelectPalette(hdcSrc, hPal, True)
  437.               RealizePalette hdcSrc
  438.  
  439.               udtRect.Bottom = Height
  440.               udtRect.Right = Width
  441.               OleTranslateColor clrMask, 0&, lMaskColor
  442.               SetBkColor hdcSrc, lMaskColor
  443.               hbrMask = CreateSolidBrush(lMaskColor)
  444.               FillRect hdcSrc, udtRect, hbrMask
  445.               DeleteObject hbrMask
  446.               DrawIcon hdcSrc, 0, 0, picSource.handle
  447.  
  448.               PaintDisabledDC hDCDest, xDest, yDest, Width, Height, hdcSrc, 0&, 0&, clrMask, clrHighlight, clrShadow, hPal
  449.  
  450.               SelectPalette hdcSrc, hPalOld, True
  451.               RealizePalette hdcSrc
  452.               DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  453.               DeleteDC hdcSrc
  454.           End If
  455.         On Error GoTo 0
  456.         ReleaseDC 0&, hDCScreen
  457.       Case Else
  458.         GoTo PaintDisabledDC_InvalidParam
  459.     End Select
  460.  
  461.     Exit Sub
  462.  
  463. PaintDisabledDC_InvalidParam:
  464.  
  465. Exit Sub
  466.  
  467. End Sub
  468.  
  469. '-------------------------------------------------------------------------
  470. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  471. '           input bitmap.
  472. 'In:
  473. '   [hdcDest]
  474. '           Device context to paint the picture on
  475. '   [xDest]
  476. '           X coordinate of the upper left corner of the area that the
  477. '           picture is to be painted on. (in pixels)
  478. '   [yDest]
  479. '           Y coordinate of the upper left corner of the area that the
  480. '           picture is to be painted on. (in pixels)
  481. '   [Width]
  482. '           Width of picture area to paint in pixels.  Note: If this value
  483. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  484. '           instead of the pictures' width in pixels), this procedure will
  485. '           attempt to create bitmaps that require outrageous
  486. '           amounts of memory.
  487. '   [Height]
  488. '           Height of picture area to paint in pixels.  Note: If this
  489. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  490. '           twips instead of the pictures' height in pixels), this
  491. '           procedure will attempt to create bitmaps that require
  492. '           outrageous amounts of memory.
  493. '   [hdcSrc]
  494. '           Device context that contains the source picture
  495. '   [xSrc]
  496. '           X coordinate of the upper left corner of the area in the picture
  497. '           to use as the source. (in pixels)
  498. '   [ySrc]
  499. '           Y coordinate of the upper left corner of the area in the picture
  500. '           to use as the source. (in pixels)
  501. '   [clrMask]
  502. '           Color of pixels to be masked out
  503. '   [clrHighlight]
  504. '           Color to be used as outline highlight
  505. '   [clrShadow]
  506. '           Color to be used as outline shadow
  507. '   [hPal]
  508. '           Handle of palette to select into the memory DC's used to create
  509. '           the painting effect.
  510. '           If not provided, a HalfTone palette is used.
  511. '-------------------------------------------------------------------------
  512. Public Sub PaintDisabledDC(ByVal hDCDest As Long, _
  513.                            ByVal xDest As Long, _
  514.                            ByVal yDest As Long, _
  515.                            ByVal Width As Long, _
  516.                            ByVal Height As Long, _
  517.                            ByVal hdcSrc As Long, _
  518.                            Optional ByVal xSrc As Long = 0, _
  519.                            Optional ByVal ySrc As Long = 0, _
  520.                            Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  521.                            Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  522.                            Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  523.                            Optional ByVal hPal As Long = 0)
  524. Attribute PaintDisabledDC.VB_Description = "Paints a disabled appearing image (embossed) given a source hDC."
  525.  
  526.   Dim hDCScreen As Long
  527.   Dim hbmMonoSection As Long
  528.   Dim hbmMonoSectionSav As Long
  529.   Dim hdcMonoSection As Long
  530.   Dim hdcColor As Long
  531.   Dim hdcDisabled As Long
  532.   Dim hbmDisabledSav As Long
  533.   Dim lpbi As BITMAPINFO
  534.   Dim hbmMono As Long
  535.   Dim hdcMono As Long
  536.   Dim hbmMonoSav As Long
  537.   Dim lMaskColor As Long
  538.   Dim lMaskColorCompare As Long
  539.   Dim hdcMaskedSource As Long
  540.   Dim hbmMasked As Long
  541.   Dim hbmMaskedOld As Long
  542.   Dim hpalMaskedOld As Long
  543.   Dim hpalDisabledOld As Long
  544.   Dim hpalMonoOld As Long
  545.   Dim rgbBlack As RGBQUAD
  546.   Dim rgbWhite As RGBQUAD
  547.   Dim dwSys3dShadow As Long
  548.   Dim dwSys3dHighlight As Long
  549.   Dim pvBits As Long
  550.   Dim rgbnew(1) As RGBQUAD
  551.   Dim hbmDisabled As Long
  552.   Dim lMonoBkGrnd As Long
  553.   Dim lMonoBkGrndChoices(2) As Long
  554.   Dim lIndex As Long  'For ... Next index
  555.   Dim hbrWhite As Long
  556.   Dim udtRect As RECT
  557.  
  558.     If hPal = 0 Then
  559.         hPal = m_hpalHalftone
  560.     End If
  561.  
  562.     OleTranslateColor clrShadow, hPal, dwSys3dShadow
  563.     OleTranslateColor clrHighlight, hPal, dwSys3dHighlight
  564.  
  565.     hDCScreen = GetDC(0&)
  566.     With rgbBlack
  567.         .rgbBlue = 0
  568.         .rgbGreen = 0
  569.         .rgbRed = 0
  570.         .rgbReserved = 0
  571.     End With
  572.     With rgbWhite
  573.         .rgbBlue = 255
  574.         .rgbGreen = 255
  575.         .rgbRed = 255
  576.         .rgbReserved = 255
  577.     End With
  578.  
  579.     With lpbi.bmiHeader
  580.         .biSize = LenB(lpbi.bmiHeader)
  581.         .biWidth = Width
  582.         .biHeight = -Height
  583.         .biPlanes = 1
  584.         .biBitCount = 1         ' monochrome
  585.         .biCompression = BI_RGB
  586.         .biSizeImage = 0
  587.         .biXPelsPerMeter = 0
  588.         .biYPelsPerMeter = 0
  589.         .biClrUsed = 0          ' max colors used (2^1 = 2)
  590.         .biClrImportant = 0     ' all (both :-]) colors are important
  591.     End With
  592.     With lpbi
  593.         .bmiColors(0) = rgbBlack
  594.         .bmiColors(1) = rgbWhite
  595.     End With
  596.  
  597.     hbmMonoSection = CreateDIBSection(hDCScreen, lpbi, DIB_RGB_COLORS, pvBits, 0&, 0)
  598.  
  599.     hdcMonoSection = CreateCompatibleDC(hDCScreen)
  600.     hbmMonoSectionSav = SelectObject(hdcMonoSection, hbmMonoSection)
  601.  
  602.     OleTranslateColor vbWhite, hPal, lMaskColorCompare
  603.     OleTranslateColor clrMask, hPal, lMaskColor
  604.     If lMaskColor = lMaskColorCompare Then
  605.         BitBlt hdcMonoSection, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
  606.       Else
  607.         hbmMasked = CreateCompatibleBitmap(hDCScreen, Width, Height)
  608.         hdcMaskedSource = CreateCompatibleDC(hDCScreen)
  609.         hbmMaskedOld = SelectObject(hdcMaskedSource, hbmMasked)
  610.         hpalMaskedOld = SelectPalette(hdcMaskedSource, hPal, True)
  611.         RealizePalette hdcMaskedSource
  612.  
  613.         With udtRect
  614.             .Left = 0
  615.             .Top = 0
  616.             .Right = Width
  617.             .Bottom = Height
  618.         End With
  619.         hbrWhite = CreateSolidBrush(vbWhite)
  620.         FillRect hdcMaskedSource, udtRect, hbrWhite
  621.         DeleteObject hbrWhite
  622.  
  623.         PaintTransparentDC hdcMaskedSource, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, hPal
  624.  
  625.         BitBlt hdcMonoSection, 0, 0, Width, Height, hdcMaskedSource, 0, 0, vbSrcCopy
  626.  
  627.         SelectPalette hdcMaskedSource, hpalMaskedOld, True
  628.         RealizePalette hdcMaskedSource
  629.         DeleteObject SelectObject(hdcMaskedSource, hbmMaskedOld)
  630.         DeleteDC hdcMaskedSource
  631.     End If
  632.  
  633.     hbmDisabled = CreateCompatibleBitmap(hDCScreen, Width, Height)
  634.  
  635.     hdcDisabled = CreateCompatibleDC(hDCScreen)
  636.     hbmDisabledSav = SelectObject(hdcDisabled, hbmDisabled)
  637.     hpalDisabledOld = SelectPalette(hdcDisabled, hPal, True)
  638.     RealizePalette hdcDisabled
  639.  
  640.     BitBlt hdcDisabled, 0, 0, Width, Height, hDCDest, xDest, yDest, vbSrcCopy
  641.  
  642.     OleTranslateColor vbBlack, hPal, lMonoBkGrndChoices(0)
  643.     OleTranslateColor vbRed, hPal, lMonoBkGrndChoices(1)
  644.     OleTranslateColor vbBlue, hPal, lMonoBkGrndChoices(2)
  645.  
  646.     For lIndex = 0 To 2
  647.         If lMonoBkGrndChoices(lIndex) <> dwSys3dHighlight And _
  648.            lMonoBkGrndChoices(lIndex) <> dwSys3dShadow Then
  649.  
  650.             lMonoBkGrnd = lMonoBkGrndChoices(lIndex)
  651.             Exit For
  652.         End If
  653.     Next lIndex
  654.  
  655.     With rgbnew(0)
  656.         .rgbRed = (vbWhite \ 2 ^ 16) And &HFF
  657.         .rgbGreen = (vbWhite \ 2 ^ 8) And &HFF
  658.         .rgbBlue = vbWhite And &HFF
  659.     End With
  660.     With rgbnew(1)
  661.         .rgbRed = (vbBlack \ 2 ^ 16) And &HFF
  662.         .rgbGreen = (vbBlack \ 2 ^ 8) And &HFF
  663.         .rgbBlue = vbBlack And &HFF
  664.     End With
  665.  
  666.     SetDIBColorTable hdcMonoSection, 0, 2, rgbnew(0)
  667.  
  668.     hbmMono = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  669.     hdcMono = CreateCompatibleDC(hDCScreen)
  670.     hbmMonoSav = SelectObject(hdcMono, hbmMono)
  671.     SetMapMode hdcMono, GetMapMode(hdcSrc)
  672.     SetBkColor hdcMono, dwSys3dHighlight
  673.     SetTextColor hdcMono, lMonoBkGrnd
  674.     hpalMonoOld = SelectPalette(hdcMono, hPal, True)
  675.     RealizePalette hdcMono
  676.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  677.  
  678.     PaintTransparentDC hdcDisabled, 1, 1, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  679.  
  680.     SetBkColor hdcMono, dwSys3dShadow
  681.     SetTextColor hdcMono, lMonoBkGrnd
  682.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  683.  
  684.     PaintTransparentDC hdcDisabled, 0, 0, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  685.     BitBlt hDCDest, xDest, yDest, Width, Height, hdcDisabled, 0, 0, vbSrcCopy
  686.  
  687.     SelectPalette hdcDisabled, hpalDisabledOld, True
  688.     RealizePalette hdcDisabled
  689.     DeleteObject SelectObject(hdcMonoSection, hbmMonoSectionSav)
  690.     DeleteDC hdcMonoSection
  691.     DeleteObject SelectObject(hdcDisabled, hbmDisabledSav)
  692.     DeleteDC hdcDisabled
  693.     DeleteObject SelectObject(hdcMono, hbmMonoSav)
  694.     SelectPalette hdcMono, hpalMonoOld, True
  695.     RealizePalette hdcMono
  696.     DeleteDC hdcMono
  697.     ReleaseDC 0&, hDCScreen
  698.  
  699. End Sub
  700.  
  701. '-------------------------------------------------------------------------
  702. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  703. '           bitmap that match the passed mask color will not be painted
  704. '           to the destination DC
  705. 'In:
  706. '   [hdcDest]
  707. '           Device context to paint the picture on
  708. '   [xDest]
  709. '           X coordinate of the upper left corner of the area that the
  710. '           picture is to be painted on. (in pixels)
  711. '   [yDest]
  712. '           Y coordinate of the upper left corner of the area that the
  713. '           picture is to be painted on. (in pixels)
  714. '   [Width]
  715. '           Width of picture area to paint in pixels.  Note: If this value
  716. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  717. '           instead of the pictures' width in pixels), this procedure will
  718. '           attempt to create bitmaps that require outrageous
  719. '           amounts of memory.
  720. '   [Height]
  721. '           Height of picture area to paint in pixels.  Note: If this
  722. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  723. '           twips instead of the pictures' height in pixels), this
  724. '           procedure will attempt to create bitmaps that require
  725. '           outrageous amounts of memory.
  726. '   [hdcSrc]
  727. '           Device context that contains the source picture
  728. '   [xSrc]
  729. '           X coordinate of the upper left corner of the area in the picture
  730. '           to use as the source. (in pixels)
  731. '   [ySrc]
  732. '           Y coordinate of the upper left corner of the area in the picture
  733. '           to use as the source. (in pixels)
  734. '   [clrMask]
  735. '           Color of pixels to be masked out
  736. '   [hPal]
  737. '           Handle of palette to select into the memory DC's used to create
  738. '           the painting effect.
  739. '           If not provided, a HalfTone palette is used.
  740. '-------------------------------------------------------------------------
  741. Public Sub PaintTransparentDC(ByVal hDCDest As Long, _
  742.                               ByVal xDest As Long, _
  743.                               ByVal yDest As Long, _
  744.                               ByVal Width As Long, _
  745.                               ByVal Height As Long, _
  746.                               ByVal hdcSrc As Long, _
  747.                               Optional ByVal xSrc As Long = 0, _
  748.                               Optional ByVal ySrc As Long = 0, _
  749.                               Optional ByVal clrMask As OLE_COLOR = 16711935, _
  750.                               Optional ByVal hPal As Long = 0)
  751. Attribute PaintTransparentDC.VB_Description = "Paints an image with transparent pixels defined by the mask color.  Accepts an hDC as its image source."
  752.  
  753.   Dim hdcMask As Long        'hDC of the created mask image
  754.   Dim hdcColor As Long       'hDC of the created color image
  755.   Dim hbmMask As Long        'Bitmap handle to the mask image
  756.   Dim hbmColor As Long       'Bitmap handle to the color image
  757.   Dim hbmColorOld As Long
  758.   Dim hbmMaskOld As Long
  759.   Dim hPalOld As Long
  760.   Dim hDCScreen As Long
  761.   Dim hdcScnBuffer As Long         'Buffer to do all work on
  762.   Dim hbmScnBuffer As Long
  763.   Dim hbmScnBufferOld As Long
  764.   Dim hPalBufferOld As Long
  765.   Dim lMaskColor As Long
  766.  
  767.     hDCScreen = GetDC(0&)
  768.  
  769.     If hPal = 0 Then
  770.         hPal = m_hpalHalftone
  771.     End If
  772.     OleTranslateColor clrMask, hPal, lMaskColor
  773.  
  774.     hbmScnBuffer = CreateCompatibleBitmap(hDCScreen, Width, Height)
  775.  
  776.     hdcScnBuffer = CreateCompatibleDC(hDCScreen)
  777.     hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
  778.     hPalBufferOld = SelectPalette(hdcScnBuffer, hPal, True)
  779.     RealizePalette hdcScnBuffer
  780.  
  781.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hDCDest, xDest, yDest, vbSrcCopy
  782.  
  783.     hbmColor = CreateCompatibleBitmap(hDCScreen, Width, Height)
  784.  
  785.     hbmMask = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  786.  
  787.     hdcColor = CreateCompatibleDC(hDCScreen)
  788.     hbmColorOld = SelectObject(hdcColor, hbmColor)
  789.     hPalOld = SelectPalette(hdcColor, hPal, True)
  790.     RealizePalette hdcColor
  791.  
  792.     SetBkColor hdcColor, GetBkColor(hdcSrc)
  793.     SetTextColor hdcColor, GetTextColor(hdcSrc)
  794.     BitBlt hdcColor, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
  795.  
  796.     hdcMask = CreateCompatibleDC(hDCScreen)
  797.     hbmMaskOld = SelectObject(hdcMask, hbmMask)
  798.  
  799.     SetBkColor hdcColor, lMaskColor
  800.     SetTextColor hdcColor, vbWhite
  801.     BitBlt hdcMask, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcCopy
  802.  
  803.     SetTextColor hdcColor, vbBlack
  804.     SetBkColor hdcColor, vbWhite
  805.     BitBlt hdcColor, 0, 0, Width, Height, hdcMask, 0, 0, DSna
  806.  
  807.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcMask, 0, 0, vbSrcAnd
  808.  
  809.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcPaint
  810.  
  811.     BitBlt hDCDest, xDest, yDest, Width, Height, hdcScnBuffer, 0, 0, vbSrcCopy
  812.  
  813.     DeleteObject SelectObject(hdcColor, hbmColorOld)
  814.     SelectPalette hdcColor, hPalOld, True
  815.     RealizePalette hdcColor
  816.     DeleteDC hdcColor
  817.     DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
  818.     SelectPalette hdcScnBuffer, hPalBufferOld, True
  819.     RealizePalette hdcScnBuffer
  820.     DeleteDC hdcScnBuffer
  821.  
  822.     DeleteObject SelectObject(hdcMask, hbmMaskOld)
  823.     DeleteDC hdcMask
  824.     ReleaseDC 0&, hDCScreen
  825.  
  826. End Sub
  827.  
  828. '-------------------------------------------------------------------------
  829. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  830. '           bitmap that match the passed mask color will not be painted
  831. '           to the destination DC
  832. 'In:
  833. '   [hdcDest]
  834. '           Device context to paint the picture on
  835. '   [xDest]
  836. '           X coordinate of the upper left corner of the area that the
  837. '           picture is to be painted on. (in pixels)
  838. '   [yDest]
  839. '           Y coordinate of the upper left corner of the area that the
  840. '           picture is to be painted on. (in pixels)
  841. '   [Width]
  842. '           Width of picture area to paint in pixels.  Note: If this value
  843. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  844. '           instead of the pictures' width in pixels), this procedure will
  845. '           attempt to create bitmaps that require outrageous
  846. '           amounts of memory.
  847. '   [Height]
  848. '           Height of picture area to paint in pixels.  Note: If this
  849. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  850. '           twips instead of the pictures' height in pixels), this
  851. '           procedure will attempt to create bitmaps that require
  852. '           outrageous amounts of memory.
  853. '   [picSource]
  854. '           Standard Picture object to be used as the image source
  855. '   [xSrc]
  856. '           X coordinate of the upper left corner of the area in the picture
  857. '           to use as the source. (in pixels)
  858. '           Ignored if picSource is an Icon.
  859. '   [ySrc]
  860. '           Y coordinate of the upper left corner of the area in the picture
  861. '           to use as the source. (in pixels)
  862. '           Ignored if picSource is an Icon.
  863. '   [clrMask]
  864. '           Color of pixels to be masked out
  865. '   [hPal]
  866. '           Handle of palette to select into the memory DC's used to create
  867. '           the painting effect.
  868. '           If not provided, a HalfTone palette is used.
  869. '-------------------------------------------------------------------------
  870. Public Sub PaintTransparentPicture(ByVal hDCDest As Long, _
  871.                                    ByVal picSource As Picture, _
  872.                                    ByVal xDest As Long, _
  873.                                    ByVal yDest As Long, _
  874.                                    ByVal Width As Long, _
  875.                                    ByVal Height As Long, _
  876.                                    Optional ByVal xSrc As Long = 0, _
  877.                                    Optional ByVal ySrc As Long = 0, _
  878.                                    Optional ByVal clrMask As OLE_COLOR = 16711935, _
  879.                                    Optional ByVal hPal As Long = 0)
  880. Attribute PaintTransparentPicture.VB_Description = "Paints an image with transparent pixels defined by the mask color.  Accepts a picture object as its image source."
  881.  
  882.   Dim hdcSrc As Long         'hDC that the source bitmap is selected into
  883.   Dim hbmMemSrcOld As Long
  884.   Dim hbmMemSrc As Long
  885.   Dim udtRect As RECT
  886.   Dim hbrMask As Long
  887.   Dim lMaskColor As Long
  888.   Dim hDCScreen As Long
  889.   Dim hPalOld As Long
  890.  
  891.     If picSource Is Nothing Then GoTo PaintTransparentStdPic_InvalidParam
  892.  
  893.     Select Case picSource.Type
  894.       Case vbPicTypeBitmap
  895.         hDCScreen = GetDC(0&)
  896.  
  897.         If hPal = 0 Then
  898.             hPal = m_hpalHalftone
  899.         End If
  900.  
  901.         hdcSrc = CreateCompatibleDC(hDCScreen)
  902.         hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  903.         hPalOld = SelectPalette(hdcSrc, hPal, True)
  904.         RealizePalette hdcSrc
  905.  
  906.         PaintTransparentDC hDCDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, hPal
  907.  
  908.         SelectObject hdcSrc, hbmMemSrcOld
  909.         SelectPalette hdcSrc, hPalOld, True
  910.         RealizePalette hdcSrc
  911.         DeleteDC hdcSrc
  912.         ReleaseDC 0&, hDCScreen
  913.       Case vbPicTypeIcon
  914.  
  915.         hDCScreen = GetDC(0&)
  916.  
  917.         If hPal = 0 Then
  918.             hPal = m_hpalHalftone
  919.         End If
  920.         hdcSrc = CreateCompatibleDC(hDCScreen)
  921.         hbmMemSrc = CreateCompatibleBitmap(hDCScreen, Width, Height)
  922.         hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  923.         hPalOld = SelectPalette(hdcSrc, hPal, True)
  924.         RealizePalette hdcSrc
  925.  
  926.         udtRect.Bottom = Height
  927.         udtRect.Right = Width
  928.         OleTranslateColor clrMask, 0&, lMaskColor
  929.         hbrMask = CreateSolidBrush(lMaskColor)
  930.         FillRect hdcSrc, udtRect, hbrMask
  931.         DeleteObject hbrMask
  932.         DrawIcon hdcSrc, 0, 0, picSource.handle
  933.  
  934.         PaintTransparentDC hDCDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, hPal
  935.  
  936.         DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  937.         SelectPalette hdcSrc, hPalOld, True
  938.         RealizePalette hdcSrc
  939.         DeleteDC hdcSrc
  940.         ReleaseDC 0&, hDCScreen
  941.       Case Else
  942.         GoTo PaintTransparentStdPic_InvalidParam
  943.     End Select
  944.  
  945.     Exit Sub
  946.  
  947. PaintTransparentStdPic_InvalidParam:
  948.  
  949. Exit Sub
  950.  
  951. End Sub
  952.  
  953. '-------------------------------------------------------------------------
  954. 'Purpose:   Draws a standard picture object to a DC
  955. 'In:
  956. '   [hdcDest]
  957. '           Handle of the device context to paint the picture on
  958. '   [xDest]
  959. '           X coordinate of the upper left corner of the area that the
  960. '           picture is to be painted on. (in pixels)
  961. '   [yDest]
  962. '           Y coordinate of the upper left corner of the area that the
  963. '           picture is to be painted on. (in pixels)
  964. '   [Width]
  965. '           Width of picture area to paint in pixels.  Note: If this value
  966. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  967. '           instead of the pictures' width in pixels), this procedure will
  968. '           attempt to create bitmaps that require outrageous
  969. '           amounts of memory.
  970. '   [Height]
  971. '           Height of picture area to paint in pixels.  Note: If this
  972. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  973. '           twips instead of the pictures' height in pixels), this
  974. '           procedure will attempt to create bitmaps that require
  975. '           outrageous amounts of memory.
  976. '   [picSource]
  977. '           Standard Picture object to be used as the image source
  978. '   [xSrc]
  979. '           X coordinate of the upper left corner of the area in the picture
  980. '           to use as the source. (in pixels)
  981. '           Ignored if picSource is an Icon.
  982. '   [ySrc]
  983. '           Y coordinate of the upper left corner of the area in the picture
  984. '           to use as the source. (in pixels)
  985. '           Ignored if picSource is an Icon.
  986. '   [hPal]
  987. '           Handle of palette to select into the memory DC's used to create
  988. '           the painting effect.
  989. '           If not provided, a HalfTone palette is used.
  990. '-------------------------------------------------------------------------
  991. Public Sub PaintStandardPicture(ByVal hDCDest As Long, _
  992.                                 ByVal picSource As Picture, _
  993.                                 ByVal xDest As Long, _
  994.                                 ByVal yDest As Long, _
  995.                                 ByVal Width As Long, _
  996.                                 ByVal Height As Long, _
  997.                                 Optional ByVal xSrc As Long = 0, _
  998.                                 Optional ByVal ySrc As Long = 0, _
  999.                                 Optional ByVal hPal As Long = 0)
  1000. Attribute PaintStandardPicture.VB_Description = "Paints an image provided by a picture object to an hDC with no effects."
  1001.  
  1002.   Dim hdcTemp As Long
  1003.   Dim hPalOld As Long
  1004.   Dim hbmMemSrcOld As Long
  1005.   Dim hDCScreen As Long
  1006.   Dim hbmMemSrc As Long
  1007.  
  1008.     If picSource Is Nothing Then GoTo PaintNormalStdPic_InvalidParam
  1009.     Select Case picSource.Type
  1010.       Case vbPicTypeBitmap
  1011.         If hPal = 0 Then
  1012.             hPal = m_hpalHalftone
  1013.         End If
  1014.         hDCScreen = GetDC(0&)
  1015.  
  1016.         hdcTemp = CreateCompatibleDC(hDCScreen)
  1017.         hPalOld = SelectPalette(hdcTemp, hPal, True)
  1018.         RealizePalette hdcTemp
  1019.  
  1020.         hbmMemSrcOld = SelectObject(hdcTemp, picSource.handle)
  1021.  
  1022.         BitBlt hDCDest, xDest, yDest, Width, Height, hdcTemp, xSrc, ySrc, vbSrcCopy
  1023.  
  1024.         SelectObject hdcTemp, hbmMemSrcOld
  1025.         SelectPalette hdcTemp, hPalOld, True
  1026.         RealizePalette hdcTemp
  1027.         DeleteDC hdcTemp
  1028.         ReleaseDC 0&, hDCScreen
  1029.       Case vbPicTypeIcon
  1030.         DrawIconEx hDCDest, xDest, yDest, picSource.handle, Width, Height, 0&, 0&, DI_NORMAL
  1031.       Case Else
  1032.         GoTo PaintNormalStdPic_InvalidParam
  1033.     End Select
  1034.  
  1035.     Exit Sub
  1036.  
  1037. PaintNormalStdPic_InvalidParam:
  1038.  
  1039. End Sub
  1040.  
  1041. Private Sub Class_Initialize()
  1042.  
  1043.   Dim hDCScreen As Long
  1044.  
  1045.     hDCScreen = GetDC(0&)
  1046.     m_hpalHalftone = CreateHalftonePalette(hDCScreen)
  1047.     ReleaseDC 0&, hDCScreen
  1048.  
  1049. End Sub
  1050.  
  1051. Private Sub Class_Terminate()
  1052.  
  1053.     DeleteObject m_hpalHalftone
  1054.  
  1055. End Sub
  1056.  
  1057. Public Sub PaintPictureToDC(ByVal hDCDest As Long, ByVal picSource As StdPicture, ByVal xDest As Long, ByVal yDest As Long, ByVal Width As Long, ByVal Height As Long, Optional ByVal clrMask As OLE_COLOR = 16711935, Optional ByVal bShadow As Boolean)
  1058.  
  1059.   Dim lbmTemp As Long
  1060.   Dim lbmTempOld As Long
  1061.   Dim lhdcTemp As Long
  1062.   Dim lhPalOld As Long
  1063.   Dim udtTempRect As RECT
  1064.   Dim lhbrWhite As Long
  1065.   Dim hDCScreen As Long
  1066.   Dim xSrc As Long, ySrc, hPal
  1067.  
  1068.     xSrc = 0
  1069.     ySrc = 0
  1070.     hPal = 0
  1071.  
  1072.     On Error Resume Next
  1073.       If picSource Is Nothing Then
  1074.  
  1075.         ElseIf picSource.Type = vbPicTypeNone Then
  1076.  
  1077.         ElseIf picSource.Type = vbPicTypeIcon Then
  1078.  
  1079.           DrawState hDCDest, 0, 0, picSource.handle, 0, xDest, yDest, 0, 0, (DST_ICON Or IIf(bShadow, DSS_MONO, DSS_NORMAL))
  1080.           If Err Then PaintDisabledPictureEx hDCDest, xDest, yDest, Width, Height, picSource, xSrc, ySrc, clrMask, vb3DHighlight, vb3DShadow, hPal
  1081.         Else
  1082.           hDCScreen = GetDC(0&)
  1083.           lhdcTemp = CreateCompatibleDC(hDCScreen)     'Create a temporary hDC compatible to the Destination hDC
  1084.           lbmTemp = CreateCompatibleBitmap(hDCScreen, Width, Height)
  1085.           lbmTempOld = SelectObject(lhdcTemp, lbmTemp)
  1086.           lhPalOld = SelectPalette(lhdcTemp, hPal, True)
  1087.           RealizePalette lhdcTemp
  1088.           With udtTempRect
  1089.               .Top = 0
  1090.               .Left = 0
  1091.               .Bottom = Height
  1092.               .Right = Width
  1093.           End With
  1094.           SetBkColor lhdcTemp, vbWhite
  1095.           lhbrWhite = CreateSolidBrush(vbWhite)
  1096.           FillRect lhdcTemp, udtTempRect, lhbrWhite
  1097.           PaintTransparentPicture lhdcTemp, picSource, 0, 0, Width, Height, xSrc, ySrc, clrMask
  1098.           SelectObject lhdcTemp, lbmTempOld
  1099.           Err.Clear
  1100.           DrawState hDCDest, 0, 0, lbmTemp, 0, xDest, yDest, 0, 0, (DST_BITMAP Or IIf(bShadow, DSS_MONO, DSS_NORMAL))
  1101.           If Err Then PaintDisabledPictureEx hDCDest, xDest, yDest, Width, Height, picSource, xSrc, ySrc, clrMask, vb3DHighlight, vb3DShadow, hPal
  1102.  
  1103.           DeleteObject lhbrWhite
  1104.           SelectPalette lhdcTemp, lhPalOld, True
  1105.           RealizePalette lhdcTemp
  1106.           DeleteObject SelectObject(lhdcTemp, lbmTempOld)
  1107.           DeleteObject lbmTempOld
  1108.           DeleteObject lbmTemp
  1109.           DeleteObject lhPalOld
  1110.           DeleteDC lhdcTemp
  1111.           ReleaseDC 0&, hDCScreen
  1112.       End If
  1113.  
  1114. End Sub
  1115.