• Welcome to Theos PowerBasic Museum 2017.

Paint rectangle without creating a brush

Started by Paul Squires, August 05, 2007, 11:04:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paul Squires

#Compile Exe

#Include "win32api.inc"

'//  Fast way to paint a rectangular area without using a brush
Sub PaintRect( ByVal hdc As Dword, rc As Rect, ByVal colour As Dword) Export
   Local oldcr As Dword
   oldcr = SetBkColor( hdc, colour )
   ExtTextOut hdc, 0, 0, %ETO_OPAQUE, rc, "", 0, 0
   SetBkColor hdc, oldcr
End Sub

Function PBMain() As Long

  Local hDlg As Dword
  Dialog New 0, "PaintRect Demo",,, 160, 155, _
             %WS_CAPTION Or %WS_SYSMENU Or %WS_THICKFRAME, 0 To hDlg

  Dialog Show Modal hDlg Call DlgProc

End Function

CallBack Function DlgProc() As Long

  Select Case As Long CbMsg

        Local hDC As Dword
        Local rc  As Rect
        ' Paint the background ourselves. Rather than creating a brush
        ' and having to destroy it when finished, we simply call the
        ' PaintRect function. This function is most useful when creating
        ' more involved drawing actions because it reduces the code
        ' needed.
        ' Fill the entire screen with blue and then create a smaller
        ' rectangle in an rgb color.

        hDC = CbWParam
        GetClientRect CbHndl, rc
        PaintRect hDC, rc, %Blue
        ' Create the smaller rectangle
        SetRect rc, 5, 5, 50, 100
        PaintRect hDC, rc, RGB( 100, 200, 0 )
        Function = %TRUE
  End Select

End Function

Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor

Kent Sarikaya