Results 1 to 4 of 4

Thread: custom fillstyle/brush

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    Question

    Hi there,
    I could use a little help because I've only just started using the API.

    I have to create my own fillstyle. I ought to look like the standard API-fillstyle HS_CROSS (VisualBasic Fillstyle=6).
    I found an example on the web using the API-function CreatePatternBrush. However I wasn't able to change the bitmap so that it looks like HS_CROSS.

    So, is CreatePatternBrush the right API-funtion to use?
    If so, how do I create a bitmap?

    This is what I've been experimenting with so far:
    Code:
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
    Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    Dim bBytes(1 To 8) As Byte
    
    Private Sub Form_Paint()
        Dim R As RECT, mBrush As Long, hBitmap As Long
        For mBrush = 1 To 8
            bBytes(mBrush) = 127
        Next
        
        'Create a memory bitmap
        hBitmap = CreateBitmap(8, 8, 1, 1, bBytes(1))
        
        'Create the pattern brush
        mBrush = CreatePatternBrush(hBitmap)
        SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
        
        'Fill the form
        FillRect Me.hdc, R, mBrush
        
        'Clean up
        DeleteObject mBrush
        DeleteObject hBitmap
    End Sub

    Thanks a lot!
    Nina

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The api's are in place, it's just that the bitmap confused me for some time. I managed to create a cross using a 16 byte array, or to which i changed later, integer array with 8 elements (bBytes(0 To 7) As Integer)
    Code:
        For n = 0 To 7
            bBytes(n) = 127
        Next n
        bBytes(0) = 0
    Here's a pattern editor i made at the same time, otherways i would never have understood how the bits were placed.
    Code:
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        On Error Resume Next
        If Button = 1 Then
            bBytes(Int(Y / Picture1.ScaleHeight * 8)) = bBytes(Int(Y / Picture1.ScaleHeight * 8)) Or 2 ^ (Int(X / Picture1.ScaleWidth * 8))
        ElseIf Button = 2 Then
            bBytes(Int(Y / Picture1.ScaleHeight * 8)) = bBytes(Int(Y / Picture1.ScaleHeight * 8)) And Not 2 ^ ((Int(X / Picture1.ScaleWidth * 8)))
        End If
        Form_Paint
        For X = 0 To 7: For Y = 0 To 7
            Picture1.Line (Y * Picture1.ScaleWidth \ 8, X * Picture1.ScaleHeight \ 8)-Step(Picture1.ScaleWidth \ 8, Picture1.ScaleHeight \ 8), QBColor(2 + CBool(bBytes(X) And (2 ^ Y))), BF
        Next Y: Next X
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    Thumbs up

    thanks!!!

    Is there a way to change the color of the grid?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah, you could change the bits to 24 and use a long array of 64 instead but i'm not sure, haven't used CreateBitmap before as createcompatiblebitmap or createdibitmap
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width