Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [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 7 von 16

Kapitel 2.4: Bitmaps blitten
Kap2.1

''' 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: 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