Buchempfehlung
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
"Der" Petzold, das über 1000 Seiten starke Standardwerk zum Win32-API - besonders nützlich u. a. bei der GUI-Programmierung in FreeBASIC! [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

Tutorial

Lutz Ifers WinAPI Tutorial

von RedakteurMODSeite 8 von 16

Kapitel 2.5: Bitmaps laden
Kap2.5

''' 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: BefehlsreferenzeintragEND, BefehlsreferenzeintragWITH, BefehlsreferenzeintragWHILE

 

Gehe zu Seite Gehe zu Seite  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  
Zusätzliche Informationen und Funktionen
  • Das Tutorial wurde am 17.09.2009 von RedakteurMOD angelegt.
  • Die aktuellste Version wurde am 17.07.2013 von AdministratorSebastian gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen