
Mapping Bitmap Background Colors to System Colors
I am hoping that someone out there can shed some light on a problem that
I have spent days on.
In my Visual Basic 4.0 application I have a 3D logo that I want to display
on a form.
The logo is stored in a BMP as ADS3D.BMP. The problem is I want the colors
in the BMP
to automatically map to the appropriate 3D system colors. As documented,
the API call
LoadImage with the LR_LOADMAP3DCOLORS option appears to do what I want. I
have had
difficulties implementing it. The code listed below is what I came up with
after talking
to Microsoft. It should Load the image from the BMP file and transfer it
to the bitmap
that is already displayed. That's what it SHOULD do, I actually get no
visible results in
my VB application.
Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As
Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2
As Long, ByVal un2 As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject
As Long) As Long
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
Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public ImageHandle As Long
Dim CompatibleDC As Long, OldHGDIOBJ As Long, Success As Long
' Load logo image from file and do 3DMAPCOLOR translation
ImageHandle = LoadImage(APP.hInstance, "ADS3D.BMP", 0, 150, 75, &H1030)
CompatibleDC = CreateCompatibleDC(bmpLogo.hdc) ' Create device context for
source bitmap
OldHGDIOBJ = SelectObject(CompatibleDC, ImageHandle)
Success = BitBlt(bmpLogo.hdc, 0, 0, 150, 75, CompatibleDC, 0, 0, &HCC0020)
' Copy image
Success = SelectObject(CompatibleDC, OldHGDIOBJ) ' Restore original
Success = DeleteDC(CompatibleDC) ' delete device context
If anyone could help me out it would be greatly appreciated, I am open to
other
ideas as well.