Tutorial
Lutz Ifers WinAPI Tutorial
von MOD | Seite 7 von 16 |
Kapitel 2.4: Bitmaps blitten
''' Lutz Ifers WinAPI-Tutorial
''' Lizenz: WTFPL
'''
''' Kapitel 2.4 - "Bitmaps blitten"
#include "windows.bi"
const ProgrammName = "Bitmaps blitten"
declare function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
dim as WNDCLASS wcMeinFenster
with wcMeinFenster
.style = CS_HREDRAW or CS_VREDRAW
.lpfnWndProc = ProcPtr(Fenster)
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = GetModuleHandle(NULL)
.hCursor = LoadCursor(NULL, IDC_ARROW)
.hIcon = LoadIcon(NULL, IDI_APPLICATION)
.hbrBackground = GetStockObject(WHITE_BRUSH)
.lpszClassName = StrPtr(ProgrammName)
.lpszMenuName = NULL
end with
RegisterClass @wcMeinFenster
dim as HWND hMeinFenster = CreateWindow(_
ProgrammName, "Titelzeile", WS_OVERLAPPEDWINDOW,_
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,_
NULL, NULL, GetModuleHandle(NULL), NULL)
ShowWindow hMeinFenster, SW_NORMAL
UpdateWindow hMeinFenster
dim as MSG msg
do while getmessage(@msg, NULL, 0, 0) <> 0
DispatchMessage @msg
loop
end msg.wParam
function Fenster(byval hWnd as HWND, byval message as UINTEGER,_
byval wParam as WPARAM, byval lParam as LPARAM) as LRESULT
static as HBITMAP hBitmap
static as HDC hDC2
dim as HDC hDC
select case message
case WM_DESTROY
DeleteDC(hDC2)
DeleteObject(hBitmap)
PostQuitMessage 0
return 0
case WM_CREATE
hDC = GetDC(hWnd)
hBitmap = CreateCompatibleBitmap(hDC, 300, 300)
hDC2 = CreateCompatibleDC(hDC)
ReleaseDC(hWnd, hDC)
SelectObject(hDC2, hBitmap)
PatBlt(hDC2, 0, 0, 800, 800, WHITENESS)
dim as INTEGER ix, iy
for ix = 0 to 255
for iy = 0 to 255
SetPixel hDC2, ix, iy, RGBA(ix, iy, 128, 0)
next
next
for iy = 100 to 200
dim as INTEGER iColor = GetPixel(hDC2, 100, iy)
SetPixel hDC2, 299, iy, iColor
next
dim as HPEN hpenDickRot = CreatePen(ps_solid, 3, RGBA(0,0,255,0))
dim as HPEN hpenBlau = CreatePen(ps_dot, 1, RGBA(255,0,0,0))
MoveToEx hDC2, 5, 260, NULL : LineTo hDC2, 250, 260
SelectObject hDC2, hpenDickRot
MoveToEx hDC2, 5, 270, NULL : LineTo hDC2, 250, 270
SelectObject hDC2, hpenBlau
MoveToEx hDC2, 5, 280, NULL : LineTo hDC2, 250, 280
DeleteObject hpenDickRot
DeleteObject hpenBlau
return 0
case WM_PAINT
dim as PAINTSTRUCT pnt
hDC = BeginPaint(hWnd, @pnt)
BitBlt hDC, 0, 0, 300, 300, hDC2, 0, 0, SRCCOPY
EndPaint(hWnd, @pnt)
return 0
end select
return DefWindowProc(hWnd, message, wParam, lParam)
end function
(Hier muss auf die Größe des Feldes geachtet werden. Der Bildbuffer wurde auf 300 x 300 Pixel gesetzt, das bedeutet, dass das Feld von 0 bis 299 geht.)
Links:
In der MSDN: ,
In der FreeBasic-Referenz: END, WITH, WHILE
Zusätzliche Informationen und Funktionen |
- Das Tutorial wurde am 17.09.2009 von MOD angelegt.
- Die aktuellste Version wurde am 17.07.2013 von Sebastian gespeichert.
|
|