Tutorial
Lutz Ifers WinAPI Tutorial
von MOD | Seite 8 von 16 |
Kapitel 2.5: Bitmaps laden
''' Lutz Ifers WinAPI-Tutorial
''' Lizenz: WTFPL
'''
''' Kapitel 2.5 - "Bitmaps laden"
#include "windows.bi"
const ProgrammName = "Bitmaps laden"
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 hbmpLutz
static as BITMAPINFO POINTER hbmiLutz
select case message
case WM_DESTROY
PostQuitMessage 0
return 0
case WM_CREATE
open "lutz.bmp" for binary as #1
dim as INTEGER iFileLength = lof(1)
dim as BYTE bvBuffer(iFileLength)
get #1,, bvBuffer() : close #1
dim as BITMAPFILEHEADER PTR bmpFileHeader = _
cptr(BITMAPFILEHEADER PTR, @bvBuffer(0))
hbmiLutz = cptr(BITMAPINFO PTR, bmpFileHeader +1)
hbmpLutz = CreateDIBitmap(_
GetDC(hWnd), @hbmiLutz->bmiHeader, CBM_INIT, _
cptr(BYTE PTR, bmpFileHeader) + bmpFileHeader->bfOffBits,_
hbmiLutz, DIB_RGB_COLORS)
return 0
case WM_PAINT
dim as PAINTSTRUCT pnt
dim as HDC hDC = BeginPaint(hWnd, @pnt)
dim as HDC bmpDC = CreateCompatibleDC(hDC)
dim hOldObject as HGDIOBJ = SelectObject(bmpDC, hbmpLutz)
BitBlt(hDC, 0, 0,_
@hbmiLutz->bmiHeader.biWidth, @hbmiLutz->bmiHeader.biHeight,_
bmpDC, 0, 0, SRCCOPY)
SelectObject bmpDC, hOldObject
DeleteDC bmpDC
EndPaint(hWnd, @pnt)
return 0
end select
return DefWindowProc(hWnd, message, wParam, lParam)
end function
(Download des Beispielbilds: lutz.bmp)
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.
|
|