Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

dirty rectangles

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dirty rectangles

    PBWIn 9 - see thread http://www.powerbasic.com/support/pb...292#post309292
    Code:
    ' To demonstrate "dirty regions" - invalidating then redrawing regions
    ' rather than the whole client area
    ' It's a faster way of refreshing the display if only a small part needs
    ' to be redrawn.
    '
    ' Thanks to Chris Boss for pointing this technique out to me.
    '
    ' Chris Holbrook Feb 2009
    '
    ' Place the cursor on the dialog's client area, and hold the left button
    ' down then drag the mouse a little way. Release the left button, and the
    ' area defined will be overwritten by a region of corresponding size from the
    ' top left of the dialog's client area.
    '
    #compile exe
    #dim all
    #debug display on
    
    #include "win32api.inc"
    global ghD              as dword ' window handle for dialog
    global ghStatic         as dword ' window handle for label control
    global gHCDC            as dword ' memory DC
    global ghMemBMP         as dword ' compatible bitmap
    global gOriginalProc    as dword ' original WndProc for label control
    '-----------------------------------------------------------------
    function LBCB ( byval hWnd as dword, byval wMsg as dword, byval wParam as dword, byval lParam as long) as long
        local hdc, hbrush, holdbrush as dword
        local i, W, H as long
        local r as rect
        local PS as PAINTSTRUCT
        local s as string
        static paintcount as long
        static OrgX, OrgY, DestX, DestY as long
        
        select case wMsg
            case %wm_user + 400                     ' initialisation
                's = "starting..."
                'sendmessage ghD, %wm_settext, 0, byval strptr(s)
                'sleep 1000
                hdc = getdc(ghStatic)               ' set up the comaptible memory DC and bitmap
                gHCDC = createcompatibleDC(hDC)
                getclientrect ghStatic, byval varptr(r)
                W = r.nright - r.nleft
                H = r.nbottom - r.ntop
                ghMemBMP = CreateCompatibleBitmap(hdc, W, H)
                selectobject(gHCDC, ghMemBMP)
                setbkmode gHCDC, %transparent
                patblt gHCDC, 0, 0, W, H, %WHITENESS
                '
                s = "@@@@@@@@ABCDEFGHIJKLMNOPQRSYUVWXYZabcdefghijklmnopqrstuvwxyz" ' draw text on memory DC
                for i = 0 to 21
                    'movetoEx ghCDC, i * 25, 2, byval 0
                    TextOut ghCDC, 2, i * 18, byval strptr(s), len(s)
                next
                invalidaterect ghStatic, byval 0, 0
            '
            case %wm_lbuttondown
                DestX = 0: DestY = 0
                's = "drawing"
                'sendmessage ghD, %wm_settext, 0, byval strptr(s)
                OrgX = lo(word,lparam)
                OrgY = hi(word,lparam)
            '
            case %wm_lbuttonup
                DestX = lo(word,lparam)
                DestY = hi(word,lparam)
                setrect r, min(OrgX, DestX), min(OrgY, DestY), max(DestX, OrgX), max(DestY,OrgY)
                invalidatergn (ghStatic, CreateRectRgnIndirect(byval varptr(r)), 0)
            '
            case %wm_paint
                hDC = BeginPaint(ghStatic, PS)
                local lBGColor as long
                lBGColor = rnd(0, &HFFFFFF)
                bitblt HDC, PS.rcPaint.nleft, PS.rcPaint.ntop, _
                            PS.rcPaint.nright - PS.rcPaint.nleft, _
                            PS.rcPaint.nbottom - PS.rcPaint.ntop, gHCDC, _
                            0, 0, %SRCCOPY
                endpaint ghStatic, ps
                function = 1
                exit function
        end select
        function = CallWindowProc(gOriginalProc, hWnd, wMsg, wParam, lParam)
       
    end function
    '-----------------------------------------------------------------
    function pbmain () as long
        dialog new pixels, 0, "dirty rectangles                                                Chris Holbrook Feb 2009", 100, 100, 500, 400, %ws_sysmenu to ghD
        control add label, ghD, 101, "", 0, 0, 500, 400, %ss_notify
        ghStatic = getDlgItem(ghD, 101)
        gOriginalProc  = SetWindowLong(ghStatic, %GWL_WNDPROC, codeptr(LBCB)) ' Subclasses Graphic control
        sendmessage ghStatic, %wm_user + 400, 0, 0 ' initialise WndProc
    
        dialog show modal ghD
    
    end function
    Last edited by Chris Holbrook; 11 Feb 2009, 04:30 PM.
Working...
X