FreeBASIC マニュアルのトップに戻る

FreeBASIC SrcPgGfxNull



Windows で GFX_NULL ドライバを使います。

ウィンドウのクライアント領域は GfxLib を使って更新されます。
メニュー、ツールバー、ダイアログは、通常の Win API 呼び出しを使って、ウィンドウに加えることができます。

'' Example of use of the GFX_NULL driver in windows
'' The GfxLib is set up in the ON_Create sub
'' The GFXLib buffer is drawn  to screen in th On_Paint Sub
'' The GfXLib is updated in the event loop

#include ""
#include once ""

Using fb

Dim Shared bmi As bitmapv4header
Dim Shared mywin As rect

Function on_paint(ByVal hwnd As HWND,ByVal wparam As WPARAM,ByVal lparam As LPARAM) As Integer

    Dim rct As RECT
    Dim pnt As PAINTSTRUCT
    Dim hDC As HDC

    'draw the gfx buffer to screen
    hDC = BeginPaint(hWnd, @pnt)
    GetClientRect( hWnd, @rct )
    With rct
        StretchDIBits hDC, 0, 0,.Right-.Left+1,, 0, 0, .Right-.Left+1,_
  ,ScreenPtr,CPtr(bitmapinfo Ptr, @bmi), DIB_RGB_COLORS, SRCCOPY
    End With

    EndPaint hWnd, @pnt

    Function = 0

End Function     

Function on_Create(ByVal hwnd As HWND,ByVal wparam As WPARAM,ByVal lparam As LPARAM) As Integer
    Dim rct As RECT
    'set a gfxscreen of the size of the client area
    GetClientRect( hWnd, @mywin)
    ScreenRes mywin.right+1,mywin.bottom+1, 32, 1, GFX_NULL
    'and create a bmp header,required to paint it yo screen
    With bmi
      .bV4Size = Len(BITMAPV4HEADER)
      .bv4height=-(mywin.bottom+1)   'negative value=>top to bottom bmp
      '(standard BMP's are bottom to top)
      .bv4planes=  1
      .bV4RedMask = &h0F00
      .bV4GreenMask = &h00F0
      .bV4BlueMask = &h000F
      .bV4AlphaMask = &hF000
    End With

    Function = 0

End Function

Function on_Destroy(ByVal hwnd As HWND,ByVal wparam As WPARAM,ByVal lparam As LPARAM) As Integer
    'clear arrays....
    PostQuitMessage( 0 )

    Function = 0

End Function

Function WndProc ( ByVal hWnd As HWND,ByVal message As UINT, _
                   ByVal wParam As WPARAM,ByVal lParam As LPARAM ) As LRESULT
    Function = 0

    Select Case As Const  message
    Case WM_CREATE
        Function = On_create(hwnd,wparam,lparam)
    Case WM_PAINT
        Function = On_paint(hwnd,wparam,lparam)
        Function = On_destroy(hwnd,wparam,lparam)
    Case Else
        Function = DefWindowProc( hWnd, message, wParam, lParam )   
    End Select

End Function

''main program create window + event loop

    Dim wMsg As MSG
    Dim wcls As WNDCLASS     
    Dim szAppName As ZString * 30 => "Random Rectangles"
    Dim hWnd As HWND
    Dim i As Integer

    With wcls
        .style         = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc   = @WndProc
        .cbClsExtra    = 0
        .cbWndExtra    = 0
        .hInstance     = GetModuleHandle( null )
        .hIcon         = LoadIcon( NULL, IDI_APPLICATION )
        .hCursor       = LoadCursor( NULL, IDC_ARROW )
        .hbrBackground = GetStockObject(WHITE_BRUSH )
        .lpszMenuName  = NULL
        .lpszClassName = @szAppName
    End With

    If( RegisterClass( @wcls ) = FALSE ) Then
    End If

    'make a non-resizable screen
    hWnd = CreateWindowEx( 0,szAppName,"Example of GFX_NULL",_
        WS_OVERLAPPEDWINDOW And Not (WS_sizebox Or ws_maximizebox),_
        NULL,NULL, wcls.hinstance,NULL )

    ShowWindow( hWnd, SW_NORMAL )
    UpdateWindow( hWnd )

    While 1
        If PeekMessage( @wMsg, NULL, 0,0, PM_Remove) Then   
            If wmsg.message=WM_QUIT Then
                Exit While
            End If
            TranslateMessage( @wMsg )
            DispatchMessage( @wMsg )
            'update the gfx buffer
            Line (Rnd*mywin.right,Rnd*mywin.bottom)-(Rnd*mywin.right,Rnd*mywin.bottom),_
            redrawwindow (hwnd,0,0,rdw_invalidate)
        End If

    End wMsg.wparam 

SCREEN (描画) に戻る
←リンク元に戻る プログラム開発関連に戻る

ページ歴史:2016-02-10 16:14:01
日本語翻訳:WATANABE Makoto、原文著作者:AntoniGual