Date: 02-16-2022
Return to Index
created by gbSnippets
Windows GDI Tutorial 1 - Drawing a Bitmap
http://www.mvps.org/user32/gditutorial.html
'DEVICE CONTEXT ====================================================
'GDI - Graphic Device Interface
'DC - Device Context
' - handle to a drawing surface on some device
' - screen plotter
' - window printers
' - memory bitmap
'Once a memory bitmap is selected into a DC, GDI function can
'be used on the bitmap (changes take place immediately)
'A bitmap that can be selected into a DC is a DDB - device independent bitmap
'A memory bitmap might be loaded from a file or a resource (found
'withing the EXE).
'Another bitmap type is DIB - device independent bitmap - cannot
'be selected into a DC. It has no handle so it cannot be used in
'most API. There are a few DIB-specific API which can copy areas
'from a DIB onto a DC.
'TRANSPARENCY ====================================================
'Windows does not support transparent bitmaps, but there are two methods
'programmers can use to create transparency
'1. Using two bitmaps - the desired bitmap and a monochrome MASK
'2. Assign a transparent color value and manually code to not display
' pixels with the transparent color
'MONOCHROME ====================================================
'Use raster operations to create a monochrome bitmap from a color bitmap
'bitmap background default color is white 'SetBkColor API can change
'DC background default is black 'SetTextColor can change
'To transfer bytes from color --> monochrome
' - pixels same color as background color are mapped to the
' background color of the monochrome bitmap. All others are
' mapped as foreground color of the monochrome bitmap
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
%ID_Graphic = 200
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,400,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Load Resource Bitmap", 30,10,140,20
Control Add Graphic, hDlg, %ID_Graphic, "", 30,40,100,100, %WS_Border
Control Add Image, hDlg, 300, "cowgirl", 150,40,100,100, %WS_Border
Graphic Attach hDlg, %ID_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case 100
Local hBMP, hDC, hDC_pb as DWord
Graphic Get DC To hDC_pb
hDC = CreateCompatibleDC(hDC_pb)
hBMP = LoadBitmap(GetModuleHandle(""), "cowgirl")
SelectObject(hDC, hBMP)
BitBlt hDC, 10,10,100,100,hDC_pb,0,0,%SRCCopy
End Select
End Select
End Function
'gbs_00535
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm