Date: 02-16-2022
Return to Index
created by gbSnippets
'MSDN says this is ignored
Graphic Attach P.hbmColor, 0
Graphic Set Bits Bitstring
Graphic Attach P.hbmMask,0
Graphic Set Bits bmp$
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
Global hDlg As DWord, P As IconInfo, w As Long, h As Long, bmp$, hLst As DWord
Global bmpXOR() As Byte, bmpAND() As Byte, hIcon As DWord
Global hBMPXor As DWord, hBMPAnd As DWord
%ID_Graphic = 400 : %ID_Button = 300
Function PBMain() As Long
Dialog New Pixels, 0, "GDI Convert BMP Test II",300,300,250,100, %WS_OverlappedWindow To hDlg
ConvertBMPtoIcon
SendMessage hDlg, %WM_SETICON, %ICON_SMALL, hIcon 'use the icon to show it works
Dialog Show Modal hDlg
End Function
Sub ConvertBMPtoIcon
Local B As Bitmap, iPos As Long, x As Long
bmp$ = Bitstring : w = CVL(bmp$,1) : h = CVL(bmp$,5) 'get w/h from XOR bitstring
'Create an XOR bitmap using the bitstring in bmp$
Graphic Bitmap New w,h To hBMPXOR
Graphic Attach hBMPXOR, 0
Graphic Set Bits bmp$
'create the bit array for the monochrome MASK bitmask. &HECE9D8 is transparent color
Dim Mask(1 To w*h/8) As Static Byte
For x = 9 To Len(bmp$) Step 4
If CVL(bmp$,x) = &HECE9D8 Then
Bit Set Mask(1),(iPos AND &hfffffff8) + 7 - (iPos AND &h7) 'bit is transparent
Else
Bit Reset Mask(1),(iPos AND &hfffffff8) + 7 - (iPos AND &h7) 'bit is not transparent
End If
Incr iPos
Next
'fill out the MASK bitmap variable information
B.bmType = 0 : B.bmWidth = w : B.bmHeight = h
B.bmWidthBytes = w/8 : B.bmPlanes = 1 : B.bmBitsPixel = 1
B.bmBits = VarPTR(Mask(1))
'create the MASK bitmap
hBMPAND = CreateBitmapIndirect(B)
'fill in the ICONINFO variable and create the icon (.xHotSpot/.yHotSpot are ignored)
P.fIcon = %True
P.hbmColor = hBMPXOR
P.hbmMask = hBMPAND
hIcon = CreateIconIndirect (P)
End Sub
Function BitString() As String
'bit string for: FACE 16x16
Local bmp$, i As Long
Data 000010, 000010, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, 000000, 000000, 000000, 000000, 000000, 000000, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000
Data 000000, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, ECE9D8, ECE9D8, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00
Data FFFF00, FFFF00, FFFF00, FFFF00, 000000, ECE9D8, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, 000000, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00
Data FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000
Data 000000, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00
Data 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, FFFF00, FFFF00, FFFF00, 000000, 000000, FFFF00, FFFF00, FFFF00, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, FFFF00, FFFF00, FFFF00, 000000, ECE9D8, 000000
Data FFFF00, FFFF00, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 808000, FFFF00, FFFF00, 000000, ECE9D8, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, ECE9D8, 000000, 000000, 000000, 000000, 808000, FFFF00, FFFF00, FFFF00, 000000, ECE9D8
Data ECE9D8, ECE9D8, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, 000000, 000000, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, FFFF00, 000000, 000000, ECE9D8
Data ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8, 000000, 000000, 000000, 000000, 000000, 000000, ECE9D8, ECE9D8, ECE9D8, ECE9D8, ECE9D8
For i = 1 To Datacount
bmp$ = bmp$ + Mkl$(Val("&H"+Read$(i)))
Next i
Function = bmp$
End Function
'gbs_00485
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm