Hi all

This creates a bitmap to be used as a brush. The brush is used to draw a grid. Grid spacing 2 to 20, independent x and y.
Should be plenty of ways to optimize this one. Myself I am just happy to be able to make it work.

KetilO

MakeBitmap proc hDC:HDC

LOCAL bicx:DWORD
LOCAL bicy:DWORD
LOCAL hBit:DWORD
LOCAL bi:BITMAPINFO
LOCAL pBits:DWORD
LOCAL nCol:DWORD

;The size of the bitmap for the brush must not be less than 12x12
mov eax,Gridcx
mov bicx,eax
.while bicx<12
add bicx,eax
.endw
mov eax,Gridcy
mov bicy,eax
.while bicy<12
add bicy,eax
.endw
;Set BITMAPINFO struct
mov bi.bmiHeader.biSize,sizeof BITMAPINFOHEADER
m2m bi.bmiHeader.biWidth,bicx
m2m bi.bmiHeader.biHeight,bicy
mov bi.bmiHeader.biPlanes,1
mov bi.bmiHeader.biBitCount,32
mov bi.bmiHeader.biCompression,BI_RGB
mov bi.bmiHeader.biXPelsPerMeter,0
mov bi.bmiHeader.biYPelsPerMeter,0
mov bi.bmiHeader.biClrUsed,0
mov bi.bmiHeader.biClrImportant,0
mov bi.bmiColors.rgbBlue,0
mov bi.bmiColors.rgbGreen,0
mov bi.bmiColors.rgbRed,0
mov bi.bmiColors.rgbReserved,0
;Create bitmap
invoke CreateDIBSection,hDC,addr bi,DIB_RGB_COLORS,addr pBits,0,0
mov hBit,eax
;Get back color
invoke GetSysColor,COLOR_BTNFACE
;Swap red & blue
mov edx,eax
shr edx,16
xchg al,ah
shl eax,8
and eax,0FFFF00h
or eax,edx
mov nCol,eax
;Get no of pixels in bitmap
mov eax,bicx
mov ecx,bicy
mul ecx
mov ecx,eax
push edi
mov edi,pBits
mov eax,nCol
rep stosd
;Make edi point at bitmap 0,0
mov eax,bicx
shl eax,2
sub edi,eax
;Set black pixels line for line
.while edi>pBits
push eax
call Ln
pop eax
mov ecx,Gridcy
.while ecx
sub edi,eax
dec ecx
.endw
.endw
pop edi
mov eax,hBit
ret

Ln:
;Set black grid pixels on the line
mov eax,bicx
shl eax,2
mov ecx,Gridcx
shl ecx,2
push edi
.while eax
mov dword ptr [edi],0
add edi,ecx
sub eax,ecx
.endw
pop edi
retn

MakeBitmap endp
Posted on 2002-02-08 03:04:55 by KetilO