OleTranslateColor

Con OleTran slateColor

作用:
給控制項加上背景圖片
Converts an OLE_COLOR type to a COLORREF.
Copy Code
STDAPI OleTranslateColor (
OLE_COLOR clr, //Color to be converted into a COLORREF
HPALETTE hpal, //Palette used for conversion
COLORREF *pcolorref //Pointer to the caller's variable that
// receives the converted result
以下為VB加TREEVIEW背景示例
Standard Module modSubclass.bas:
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (lpDest As Any, lpSrc As Any, _
ByVal dwLen As Long)
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WndProc = (-4)
Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetProp Lib "user32" Alias _
"GetPropA" (ByVal hWnd As Long, _
ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias _
"SetPropA" (ByVal hWnd As Long, _
ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias _
"RemovePropA" (ByVal hWnd As Long, _
ByVal lpString As String) As Long
Public Sub Subclass(frm As Form, tv As TreeView)
'Subclass the TreeView and store an object
'pointer to the form.
Dim lProc As Long
If GetProp(tv.hWnd, "VBTWndProc") <> 0 Then
Exit Sub
End If
lProc = GetWindowLong(tv.hWnd, GWL_WNDPROC)
SetProp tv.hWnd, "VBTWndProc", lProc
SetProp tv.hWnd, "VBTWndPtr", ObjPtr(frm)
SetWindowLong tv.hWnd, GWL_WNDPROC, _
AddressOf WndProcTV
End Sub
Public Sub UnSubclass(tv As TreeView)
Dim lProc As Long
lProc = GetProp(tv.hWnd, "VBTWndProc")
If lProc = 0 Then
Exit Sub
End If
SetWindowLong tv.hWnd, GWL_WNDPROC, lProc
RemoveProp tv.hWnd, "VBTWndProc"
RemoveProp tv.hWnd, "VBTWndPtr"
End Sub
Public Function WndProcTV(ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
On Error Resume Next
Dim lProc As Long
Dim lPtr As Long
Dim tmpForm As Form
Dim bUseRetVal As Boolean
Dim lRetVal As Long
bUseRetVal = False
lProc = GetProp(hWnd, "VBTWndProc")
lPtr = GetProp(hWnd, "VBTWndPtr")
&#039;Copy the form&#039;s object pointer into an
&#039;object variable and call the message handler.
CopyMemory tmpForm, lPtr, 4
tmpForm.TreeViewMessage hWnd, wMsg, wParam, lParam, _
lRetVal, bUseRetVal
CopyMemory tmpForm, 0&, 4
&#039;我將以上三句中的"tmpForm" 替換成"frmMain"後才能運行。
If bUseRetVal = True Then
&#039;Use the return value from the form&#039;s
&#039;handler
WndProcTV = lRetVal
Else
&#039;Pass on to original wndproc
WndProcTV = CallWindowProc(lProc, hWnd, wMsg, _
wParam, lParam)
End If
End Function
&#039;--end block--&#039;
Standard Module Paint.bas:
Option Explicit
&#039;================================================
&#039;Paint.bas
&#039;Visual Basic Thunder
&#039;http://www.vbthunder.com
&#039;
&#039;These routines taken (and later modified) from
&#039;Microsoft&#039;s Visual Basic 5.0 Owner&#039;s Area.
&#039;================================================
&#039;halftone created for default palette use
Private m_hpalHalftone As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateSolidBrush Lib "gdi32" _
(ByVal crColor As Long) As Long
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
Private Declare Function SetBkColor Lib "gdi32" _
(ByVal hDC As Long, ByVal crColor As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function ReleaseDC Lib "user32" _
(ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
(ByVal hDC As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" _
(ByVal hDC As Long, ByVal crColor As Long) As Long
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
Private Declare Function getbkcolor Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function GetTextColor Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function SelectPalette Lib "gdi32" _
(ByVal hDC As Long, ByVal hPalette As Long, _
ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function OleTranslateColor Lib "oleaut32.dll" _
(ByVal lOleColor As Long, ByVal lHPalette As Long, _
lColorRef As Long) As Long
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
Private Declare Function FillRect Lib "user32" _
(ByVal hDC As Long, lpRect As RECT, _
ByVal hBrush As Long) As Long
&#039;DrawIconEx Flags
Private Const DI_MASK = &H1
Private Const DI_IMAGE = &H2
Private Const DI_NORMAL = &H3
Private Const DI_COMPAT = &H4
Private Const DI_DEFAULTSIZE = &H8
&#039;Raster Operation Codes
Private Const DSna = &H220326 &#039;0x00220326
&#039;VB Errors
Private Const giINVALID_PICTURE As Integer = 481
Public Function TranslateColor(inCol As Long) As Long
&#039;A simple wrapper for OleTranslateColor
Dim retCol As Long
OleTranslateColor inCol, 0&, retCol
TranslateColor = retCol
End Function
Public Sub PaintNormalStdPic(ByVal hdcDest As Long, _
ByVal xDest As Long, _
ByVal yDest As Long, _
ByVal width As Long, _
ByVal Height As Long, _
ByVal picSource As Picture, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
Optional ByVal hPal As Long = 0)
Dim hdcTemp As Long
Dim hPalOld As Long
Dim hbmMemSrcOld As Long
Dim hdcScreen As Long
Dim hbmMemSrc As Long
&#039;Validate that a bitmap was passed in
If picSource Is Nothing Then GoTo PaintNormalStdPic_InvalidParam
Select Case picSource.Type
Case vbPicTypeBitmap
If hPal = 0 Then
hPal = m_hpalHalftone
End If
hdcScreen = GetDC(0&)
&#039;Create a DC to select bitmap into
hdcTemp = CreateCompatibleDC(hdcScreen)
hPalOld = SelectPalette(hdcTemp, hPal, True)
RealizePalette hdcTemp
&#039;Select bitmap into DC
hbmMemSrcOld = SelectObject(hdcTemp, picSource.Handle)
&#039;Copy to destination DC
BitBlt hdcDest, xDest, yDest, width, Height, hdcTemp, xSrc, ySrc, vbSrcCopy
&#039;Cleanup
SelectObject hdcTemp, hbmMemSrcOld
SelectPalette hdcTemp, hPalOld, True
RealizePalette hdcTemp
DeleteDC hdcTemp
ReleaseDC 0&, hdcScreen
Case vbPicTypeIcon
&#039;Create a bitmap and select it into an DC
&#039;Draw Icon onto DC
DrawIconEx hdcDest, xDest, yDest, picSource.Handle, 0, 0, 0&, 0&, DI_NORMAL
Case Else
GoTo PaintNormalStdPic_InvalidParam
End Select
Exit Sub
PaintNormalStdPic_InvalidParam:
Err.Raise giINVALID_PICTURE
End Sub
Public Sub PaintTransparentDC(ByVal hdcDest As Long, _
ByVal xDest As Long, _
ByVal yDest As Long, _
ByVal width As Long, _
ByVal Height As Long, _
ByVal hdcSrc As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal clrMask As OLE_COLOR, _
Optional ByVal hPal As Long = 0)
Dim hdcMask As Long &#039;HDC of the created mask image
Dim hdcColor As Long &#039;HDC of the created color image
Dim hbmMask As Long &#039;Bitmap handle to the mask image
Dim hbmColor As Long &#039;Bitmap handle to the color image
Dim hbmColorOld As Long
Dim hbmMaskOld As Long
Dim hPalOld As Long
Dim hdcScreen As Long
Dim hdcScnBuffer As Long &#039;Buffer to do all work on
Dim hbmScnBuffer As Long
Dim hbmScnBufferOld As Long
Dim hPalBufferOld As Long
Dim lMaskColor As Long
hdcScreen = GetDC(0&)
&#039;Validate palette
If hPal = 0 Then
hPal = m_hpalHalftone
End If
OleTranslateColor clrMask, hPal, lMaskColor
&#039;Create a color bitmap to server as a copy of the destination
&#039;Do all work on this bitmap and then copy it back over the destination
&#039;when it&#039;s done.
hbmScnBuffer = CreateCompatibleBitmap(hdcScreen, width, Height)
&#039;Create DC for screen buffer
hdcScnBuffer = CreateCompatibleDC(hdcScreen)
hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
hPalBufferOld = SelectPalette(hdcScnBuffer, hPal, True)
RealizePalette hdcScnBuffer
&#039;Copy the destination to the screen buffer
BitBlt hdcScnBuffer, 0, 0, width, Height, hdcDest, xDest, yDest, vbSrcCopy
&#039;Create a (color) bitmap for the cover (can&#039;t use CompatibleBitmap with
&#039;hdcSrc, because this will create a dib section if the original bitmap
&#039;is a DIB section)
hbmColor = CreateCompatibleBitmap(hdcScreen, width, Height)
&#039;Now create a monochrome bitmap for the mask
hbmMask = CreateBitmap(width, Height, 1, 1, ByVal 0&)
&#039;First, blt the source bitmap onto the cover. We do this first
&#039;and then use it instead of the source bitmap
&#039;because the source bitmap may be
&#039;a DIB section, which behaves differently than a bitmap.
&#039;(Specifically, copying from a DIB section to a monochrome bitmap
&#039;does a nearest-color selection rather than painting based on the
&#039;backcolor and forecolor.
hdcColor = CreateCompatibleDC(hdcScreen)
hbmColorOld = SelectObject(hdcColor, hbmColor)
hPalOld = SelectPalette(hdcColor, hPal, True)
RealizePalette hdcColor
&#039;In case hdcSrc contains a monochrome bitmap, we must set the destination
&#039;foreground/background colors according to those currently set in hdcSrc
&#039;(because Windows will associate these colors with the two monochrome colors)
SetBkColor hdcColor, GetBkColor(hdcSrc)
SetTextColor hdcColor, GetTextColor(hdcSrc)
BitBlt hdcColor, 0, 0, width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
&#039;Paint the mask. What we want is white at the transparent color
&#039;from the source, and black everywhere else.
hdcMask = CreateCompatibleDC(hdcScreen)
hbmMaskOld = SelectObject(hdcMask, hbmMask)
&#039;When bitblt&#039;ing from color to monochrome, Windows sets to 1
&#039;all pixels that match the background color of the source DC. All
&#039;other bits are set to 0.
SetBkColor hdcColor, lMaskColor
SetTextColor hdcColor, vbWhite
BitBlt hdcMask, 0, 0, width, Height, hdcColor, 0, 0, vbSrcCopy
&#039;Paint the rest of the cover bitmap.
&#039;
&#039;What we want here is black at the transparent color, and
&#039;the original colors everywhere else. To do this, we first
&#039;paint the original onto the cover (which we already did), then we
&#039;AND the inverse of the mask onto that using the DSna ternary raster
&#039;operation (0x00220326 - see Win32 SDK reference, Appendix, "Raster
&#039;Operation Codes", "Ternary Raster Operations", or search in MSDN
&#039;for 00220326). DSna [reverse polish] means "(not SRC) and DEST".
&#039;
&#039;When bitblt&#039;ing from monochrome to color, Windows transforms all white
&#039;bits (1) to the background color of the destination hdc. All black (0)
&#039;bits are transformed to the foreground color.
SetTextColor hdcColor, vbBlack
SetBkColor hdcColor, vbWhite
BitBlt hdcColor, 0, 0, width, Height, hdcMask, 0, 0, DSna
&#039;Paint the Mask to the Screen buffer
BitBlt hdcScnBuffer, 0, 0, width, Height, hdcMask, 0, 0, vbSrcAnd
&#039;Paint the Color to the Screen buffer
BitBlt hdcScnBuffer, 0, 0, width, Height, hdcColor, 0, 0, vbSrcPaint
&#039;Copy the screen buffer to the screen
BitBlt hdcDest, xDest, yDest, width, Height, hdcScnBuffer, 0, 0, vbSrcCopy
&#039;All done!
DeleteObject SelectObject(hdcColor, hbmColorOld)
SelectPalette hdcColor, hPalOld, True
RealizePalette hdcColor
DeleteDC hdcColor
DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
SelectPalette hdcScnBuffer, hPalBufferOld, True
RealizePalette hdcScnBuffer
DeleteDC hdcScnBuffer
DeleteObject SelectObject(hdcMask, hbmMaskOld)
DeleteDC hdcMask
ReleaseDC 0&, hdcScreen
End Sub
Public Sub PaintTransparentStdPic(ByVal hdcDest As Long, _
ByVal xDest As Long, _
ByVal yDest As Long, _
ByVal width As Long, _
ByVal Height As Long, _
ByVal picSource As Picture, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal clrMask As OLE_COLOR, _
Optional ByVal hPal As Long = 0)
Dim hdcSrc As Long &#039;HDC that the source bitmap is selected into
Dim hbmMemSrcOld As Long
Dim hbmMemSrc As Long
Dim udtRect As RECT
Dim hbrMask As Long
Dim lMaskColor As Long
Dim hdcScreen As Long
Dim hPalOld As Long
&#039;Verify that the passed picture is a Bitmap
If picSource Is Nothing Then
GoTo PaintTransparentStdPic_InvalidParam
End If
Select Case picSource.Type
Case vbPicTypeBitmap
hdcScreen = GetDC(0&)
&#039;Validate palette
If hPal = 0 Then
hPal = m_hpalHalftone
End If
&#039;Select passed picture into an HDC
hdcSrc = CreateCompatibleDC(hdcScreen)
hbmMemSrcOld = SelectObject(hdcSrc, picSource.Handle)
hPalOld = SelectPalette(hdcSrc, hPal, True)
RealizePalette hdcSrc
&#039;Draw the bitmap
PaintTransparentDC hdcDest, xDest, yDest, width, Height, hdcSrc, xSrc, ySrc, clrMask, hPal
SelectObject hdcSrc, hbmMemSrcOld
SelectPalette hdcSrc, hPalOld, True
RealizePalette hdcSrc
DeleteDC hdcSrc
ReleaseDC 0&, hdcScreen
Case vbPicTypeIcon
&#039;Create a bitmap and select it into an DC
hdcScreen = GetDC(0&)
&#039;Validate palette
If hPal = 0 Then
hPal = m_hpalHalftone
End If
hdcSrc = CreateCompatibleDC(hdcScreen)
hbmMemSrc = CreateCompatibleBitmap(hdcScreen, width, Height)
hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
hPalOld = SelectPalette(hdcSrc, hPal, True)
RealizePalette hdcSrc
&#039;Draw Icon onto DC
udtRect.Bottom = Height
udtRect.Right = width
OleTranslateColor clrMask, 0&, lMaskColor
hbrMask = CreateSolidBrush(lMaskColor)
FillRect hdcSrc, udtRect, hbrMask
DeleteObject hbrMask
DrawIconEx hdcSrc, 0, 0, picSource.Handle, 0, 0, 0, 0, DI_NORMAL
&#039;Draw Transparent image
PaintTransparentDC hdcDest, xDest, yDest, width, Height, hdcSrc, 0, 0, lMaskColor, hPal
&#039;Clean up
DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
SelectPalette hdcSrc, hPalOld, True
RealizePalette hdcSrc
DeleteDC hdcSrc
ReleaseDC 0&, hdcScreen
Case Else
GoTo PaintTransparentStdPic_InvalidParam
End Select
Exit Sub
PaintTransparentStdPic_InvalidParam:
&#039;Err.Raise giINVALID_PICTURE
Exit Sub
End Sub
&#039;--end block--&#039;
Form frmMain.frm
For this example you will need:
- A TreeView control named tvBG
- An Image control named img
Set the Picture property of img to a bitmap that is
conducive to tiling. (Or any old bitmap, if you really want!)
Once the bitmap is in place, it&#039;s time to insert the code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type paintstruct
hDC As Long
fErase As Long
rcPaint As RECT
fRestore As Long
fIncUpdate As Long
rgbReserved As Byte
End Type
Private Declare Function BeginPaint Lib "user32" _
(ByVal hWnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function EndPaint Lib "user32" _
(ByVal hWnd As Long, lpPaint As PAINTSTRUCT) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" _
(ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
(ByVal hDC As Long, ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
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
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function InvalidateRect Lib "user32" _
(ByVal hWnd As Long, ByVal lpRect As Long, _
ByVal bErase As Long) As Long
Private Const WM_PAINT = &HF
Private Const WM_ERASEBKGND = &H14
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
Private Const WM_MOUSEWHEEL = &H20A
Private Sub Form_Load()
&#039;Subclass the TreeView to trap messages
&#039;that we&#039;ll need to respond to
Subclass Me, tvBG
Dim Root As Node
&#039;Add some items
With tvBG.Nodes
Set Root = .Add(, , , "Top-level Node #1")
.Add Root.Index, tvwChild, , "Child Node #1"
.Add Root.Index, tvwChild, , "Child Node #2"
.Add Root.Index, tvwChild, , "Child Node #3"
Set Root = .Add(, , , "Top-level Node #2")
.Add Root.Index, tvwChild, , "Child Node #1"
.Add Root.Index, tvwChild, , "Child Node #2"
.Add Root.Index, tvwChild, , "Child Node #3"
Set Root = .Add(, , , "Top-level Node #3")
.Add Root.Index, tvwChild, , "Child Node #1"
.Add Root.Index, tvwChild, , "Child Node #2"
.Add Root.Index, tvwChild, , "Child Node #3"
Set Root = .Add(, , , "Top-level Node #4")
.Add Root.Index, tvwChild, , "Child Node #1"
.Add Root.Index, tvwChild, , "Child Node #2"
.Add Root.Index, tvwChild, , "Child Node #3"
End With
End Sub
Public Sub TreeViewMessage(ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long, RetVal As Long, _
UseRetVal As Boolean)
&#039;Prevent recursion with this variable
Static InProc As Boolean
Dim ps As PAINTSTRUCT
Dim TVDC As Long, drawDC1 As Long, drawDC2 As Long
Dim oldBMP1 As Long, drawBMP1 As Long
Dim oldBMP2 As Long, drawBMP2 As Long
Dim x As Long, y As Long, w As Long, h As Long
Dim TVWidth As Long, TVHeight As Long
If wMsg = WM_PAINT Then
If InProc = True Then
Exit Sub
End If
InProc = True
&#039;Prepare some variables we&#039;ll use
TVWidth = tvBG.width \ Screen.TwipsPerPixelX
TVHeight = tvBG.Height \ Screen.TwipsPerPixelY
w = ScaleX(img.Picture.width, vbHimetric, vbPixels)
h = ScaleY(img.Picture.Height, vbHimetric, vbPixels)
&#039;Begin painting. This API must be called in
&#039;response to the WM_PAINT message or you&#039;ll see
&#039;some odd visual effects :-)
Call BeginPaint(hWnd, ps)
TVDC = ps.hDC
&#039;Create a few canvases in memory to
&#039;draw on
drawDC1 = CreateCompatibleDC(TVDC)
drawBMP1 = CreateCompatibleBitmap(TVDC, TVWidth, TVHeight)
oldBMP1 = SelectObject(drawDC1, drawBMP1)
drawDC2 = CreateCompatibleDC(TVDC)
drawBMP2 = CreateCompatibleBitmap(TVDC, TVWidth, TVHeight)
oldBMP2 = SelectObject(drawDC2, drawBMP2)
&#039;This actually causes the TreeView to paint
&#039;itself onto our memory DC!
SendMessage hWnd, WM_PAINT, drawDC1, ByVal 0&
&#039;Tile the bitmap and draw the TreeView
&#039;over it transparently
For y = 0 To TVHeight Step h
For x = 0 To TVWidth Step w
PaintNormalStdPic drawDC2, x, y, w, h, _
img.Picture, 0, 0
Next
Next
PaintTransparentDC drawDC2, 0, 0, TVWidth, TVHeight, _
drawDC1, 0, 0, TranslateColor(vbWindowBackground)
&#039;Draw to the target DC
BitBlt TVDC, 0, 0, TVWidth, TVHeight, _
drawDC2, 0, 0, vbSrcCopy
&#039;Cleanup
SelectObject drawDC1, oldBMP1
SelectObject drawDC2, oldBMP2
DeleteObject drawBMP1
DeleteObject drawBMP2
EndPaint hWnd, ps
RetVal = 0
UseRetVal = True
InProc = False
ElseIf wMsg = WM_ERASEBKGND Then
&#039;Return TRUE
RetVal = 1
UseRetVal = True
ElseIf wMsg = WM_HSCROLL Or wMsg = WM_VSCROLL Or wMsg = WM_MOUSEWHEEL Then
&#039;Force a repaint to keep the bitmap
&#039;tiles lined up
InvalidateRect hWnd, 0, 0
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
&#039;Kill subclassing routine for exit
UnSubclass tvBG
End Sub
&#039;--end block--&#039;
);
Parameters
clr
[in] The OLE color to be converted into a COLORREF.
hpal
[in] Palette used as a basis for the conversion.
pcolorref
[out] Pointer to the caller&#039;s variable that receives the converted COLORREF result. This can be NULL, indicating that the caller wants only to verify that a converted color exists.
Return Values
This function supports the standard return values E_INVALIDARG and E_UNEXPECTED, as well as the following:
S_OK
The color was translated successfully.
Remarks
The following table describes the color conversion:
OLE_COLOR hPal Resulting COLORREF
invalid
Undefined (E_INVALIDARG)
0x800000xx, xx is not a valid Win32 GetSysColor index
Undefined (E_INVALIDARG)
invalid
Undefined (E_INVALIDARG)
0x0100iiii, iiii is not a valid palette index
valid palette
Undefined (E_INVALIDARG)
0x800000xx, xx is a valid GetSysColor index
NULL
0x00bbggrr
0x0100iiii, iiii is a valid palette index
NULL
0x0100iiii
0x02bbggrr (palette relative)
NULL
0x02bbggrr
0x00bbggrr
NULL
0x00bbggrr
0x800000xx, xx is a valid GetSysColor index
valid palette
0x00bbggrr
0x0100iiii, iiii is a valid palette index in hPal
valid palette
0x0100iiii
0x02bbggrr (palette relative)
valid palette
0x02bbggrr
0x00bbggrr
valid palette
0x02bbggrr
Requirements
For an explanation of the requirement values, see Requirements (COM).
Windows NT/2000/XP: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in olectl.h.
Library: Included as a resource in olepro32.dll.
VB聲明:
private declare function oletranslatecolor lib "oleaut32.dll" _
(byval lolecolor as long, byval lhpalette as long, _
lcolorref as long) as long

相關詞條

相關搜尋

熱門詞條

聯絡我們