Rubrik: Grafik & Zeichnen | 22.03.05 |
CreateBrushIndirect-Funktion Diese Funktion erstellt ein Brush und gibt dessen Handle zurück. | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 6.624 |
Deklaration:
Declare Function CreateBrushIndirect Lib "gdi32" ( _ lpLogBrush As LOGBRUSH) As Long
Beschreibung:
Diese Funktion erstellt ein Brush und gibt dessen Handle zurück.
Parameter:
lpLogBrush | Erwartet eine gefüllte LOGBRUSH-Struktur, die den Brush beschreibt, der erstellt werden soll. |
Rückgabewert:
Ist die Funktion erfolgreich, so wird der Handle zu dem neu erstelltem Brush zurückgegeben, andernfallsist der Rückgabewert "0".
Beispiel:
Private Declare Function CreateBrushIndirect Lib "gdi32" ( _ lpLogBrush As LOGBRUSH) As Long Private Declare Function SelectObject Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" ( _ ByVal hObject As Long) As Long Private Declare Function PatBlt Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal x As Long, _ ByVal y As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ ByVal dwRop As Long) As Long Private Type LOGBRUSH lbStyle As Long lbColor As Long lbHatch As Long End Type ' LOGBRUSH lbStyle-Konstanten Private Const BS_HATCHED = 2 ' Gemusterter Brush Private Const BS_NULL = 1 ' Leerer Brush Private Const BS_SOLID = 0 ' Solider Brush ' LOGBRUSH lbHatch-Konstanten Private Const HS_BDIAGONAL = 3 ' Diagonal von links unten nach rechts oben (/) Private Const HS_CROSS = 4 ' Kreuz (+) Private Const HS_DIAGCROSS = 5 ' Diagonales Kreuz (x) Private Const HS_FDIAGONAL = 2 ' Diagonal von rechts unten nach links oben (\) Private Const HS_HORIZONTAL = 0 ' Horizontal (-) Private Const HS_VERTICAL = 1 ' Vertikal (|) ' PatBlt dwRop-Konstanten Private Const PATCOPY = &HF00021 ' Kopiert den Brush auf das Ziel Private Const PATINVERT = &H5A0049 ' Kopiert den Brush invertiert auf das Ziel Private Const DSTINVERT = &H550009 ' Invertiert das Ziel und Kopiert den Brush darauf Private Const BLACKNESS = &H42 ' Das Ziel wird mit Schwarz und dann mit dem Brush gefüllt Private Const WHITENESS = &HFF0062 ' Das Ziel wird mit Weiß und dann mit dem Brush gefüllt
' Zeichnen eines gemusterten Rechtecks auf die Form Private Sub Form_Load() Dim Retval As Long, hBrush As Long, hOldBrush As Long, LB As LOGBRUSH Me.AutoRedraw = True Me.ScaleMode = vbPixels ' Brush erstellen With LB .lbColor = vbGreen .lbHatch = HS_DIAGCROSS .lbStyle = BS_HATCHED End With hBrush = CreateBrushIndirect(LB) ' Brush der Form zuweisen und Ergebnis (Alter Brush) zwischenspeichern hOldBrush = SelectObject(Me.hdc, hBrush) ' Rechteck zeichnen Retval = PatBlt(Me.hdc, 10, 10, Me.ScaleWidth - 20, Me.ScaleHeight - _ 20, PATINVERT) ' Alten Brush wiederherstellen Call SelectObject(Me.hdc, hOldBrush) ' erstellten Brush zerstören Call DeleteObject(hBrush) End Sub