Hi Charles
I get really strange error about parameter mismatch
for gdi function CreateDIBSection()
in declaration i have exactly 6 params also as in setting subroutine
i am asking you what I made wrong ?
'fast GDI with DIB section
$ filename "FastGDI.exe"
include "RTL32.inc"
include "awinh037.inc"
#lookahead
' struct pixel
type PIXEL
ubyte b
ubyte g
ubyte r
ubyte a
=
int value
end type
type BITMAPINFOHEADER
DWORD biSize
LONG biWidth
LONG biHeight
WORD biPlanes
WORD biBitCount
DWORD biCompression
DWORD biSizeImage
LONG biXPelsPerMeter
LONG biYPelsPerMeter
DWORD biClrUsed
DWORD biClrImportant
end type
type RGBQUAD
BYTE rgbBlue
BYTE rgbGreen
BYTE rgbRed
BYTE rgbReserved
end type
type BITMAPINFO
BITMAPINFOHEADER bmiHeader
RGBQUAD bmiColors
end type
! CreateDIBSection Lib "gdi32.dll" (ByVal hDC As Long,byref pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
% DIB_RGB_COLORS = 0
' Window client size
int width = 375
int height = 375
% BI_RGB = 0
' Target fps, though it's hard to achieve this fps
' without extra timer functionality unless you have
' a powerfull processor. Raising this value will
' increase the speed, though it will use up more CPU.
int fps = 50
' Global Windows/Drawing variables
INT hbmp
INT hTickThread
INT hwnd
INT hdc
INT hdcMem
INT wstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
' Pointer to pixels (will automatically have space allocated by CreateDIBSection
PIXEL pixels
INT win
'reg class & create window using awinh037.inc ---------------------------------------
win = SetWindow("Fast_GDI", 300, 200, width, height, 0, wstyle)
'------------------------------------------------------------------------------------
RECT rcClient, rcWindow
POINTAPI ptDiff
' Get window and client sizes
GetClientRect( win, rcClient )
GetWindowRect( win, rcWindow )
' Find offset between window size and client size
ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right
ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom
' Resize client
MoveWindow( win, rcWindow.left, rcWindow.top, width + ptDiff.x, height + ptDiff.y, -1)
UpdateWindow( win )
' wmsg loop >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
while GetMessage(wm, 0, 0, 0)
TranslateMessage wm
DispatchMessage wm
wend
' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Function WndProc( sys hwnd, wmsg, wParam, lParam) as sys callback
SELECT hwnd
CASE win
select wmsg
case WM_CREATE
' MakeSurface( hwnd )
case WM_PAINT
PAINTSTRUCT ps
hdc = BeginPaint( win, ps )
' Draw pixels to window when window needs repainting
BitBlt( hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY )
EndPaint( win, ps )
case WM_CLOSE
DestroyWindow( win )
case WM_DESTROY
'TerminateThread( hTickThread, 0 )
PostQuitMessage( 0 )
'case else
'return DefWindowProc( hwnd, wmsg, wParam, lParam )
end select
END SELECT
Return DefWindowProc(hwnd,wMsg,wParam,lParam)
End Function
'..................................................................
SUB MakeSurface(INT wnd)
' Use CreateDIBSection to make a HBITMAP which can be quickly
' blitted to a surface while giving 100% fast access to pixels before blit.
' Desired bitmap properties
BITMAPINFOHEADER bmi
bmi.biSize = sizeof(BITMAPINFOHEADER)
bmi.biWidth = width
bmi.biHeight = -height ' Order pixels from top to bottom
bmi.biPlanes = 1
bmi.biBitCount = 32 ' last byte not used, 32 bit for alignment
bmi.biCompression = BI_RGB
bmi.biSizeImage = 0
bmi.biXPelsPerMeter = 0
bmi.biYPelsPerMeter = 0
bmi.biClrUsed = 0
bmi.biClrImportant = 0
BITMAPINFO bmci
bmci.bmiColors[0].rgbRed = 0
bmci.bmiColors[0].rgbGreen = 0
bmci.bmiColors[0].rgbBlue = 0
bmci.bmiColors[0].rgbReserved = 0
hdc = GetDC( win )
lPtr as long
' Create DIB section to always give direct access to pixels
hbmp = CreateDIBSection( hdc, bmi, DIB_RGB_COLORS, pixels , 0, 0 )
DeleteDC( hdc )
' Create a new thread to use as a timer
'hTickThread = CreateThread( NULL, NULL, &tickThreadProc, 0, 0, 9 )
END SUB