Rubrik: Grafik & Zeichnen | 15.11.01 |
GetBrushOrgEx-Funktion Diese Funktion ermittelt die aktuelle Einstellung des Pinselursprungs innerhalb eines Brush's (8x8 Pixel großes Bitmap)... | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 7.071 |
Deklaration:
Declare Function GetBrushOrgEx Lib "gdi32.dll" ( _ ByVal hdc As Long, _ lpPoint As POINTAPI) As Long
Beschreibung:
Diese Funktion ermittelt die aktuelle Einstellung des Pinselursprungs innerhalb eines Brush's (8x8 Pixel großes Bitmap), der über die SetBrushOrgEx-Funktion gesetzt worden ist.
Parameter:
hdc | Gibt den gewünschten Gerätekontext an. |
lpPoint | Erwartet eine POINTAPI-Struktur, die mit den ermittelten Daten gefüllt wird. |
Rückgabewert:
Ist die Funktion erfolgreich, wird "1", andernfalls "0"zurückgegegebn.
Beispiel:
Private Declare Function CreateHatchBrush Lib "gdi32" ( _ ByVal nIndex As Long, _ ByVal crColor As Long) As Long Private Declare Function GetBrushOrgEx Lib "gdi32" ( _ ByVal hDC As Long, _ lpPoint As POINTAPI) As Long Private Declare Function SetBrushOrgEx Lib "gdi32" ( _ ByVal hDC As Long, _ ByVal nXOrg As Long, _ ByVal nYOrg As Long, _ lppt As POINTAPI) As Long Private Declare Function SelectObject Lib "gdi32" ( _ ByVal hDC As Long, _ ByVal hObject As Long) As Long Private Declare Function Rectangle Lib "gdi32" ( _ ByVal hDC As Long, _ 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 Const HS_BDIAGONAL = 3 ' Diagonal von linksunten nach rechtsoben (/) Private Const HS_CROSS = 4 ' Kreuz (+) Private Const HS_DIAGCROSS = 5 ' Diagonales Kreuz (x) Private Const HS_FDIAGONAL = 2 ' Diagonal von rechtunten nach linksoben (\) Private Const HS_HORIZONTAL = 0 ' Horizontal (-) Private Const HS_VERTICAL = 1 ' Vertikal (|) Private Type POINTAPI x As Long y As Long End Type Private RetVal As Long Private hBrushNew As Long Private hBrushOld As Long Private OldOrginPt As POINTAPI Private NewOrginPt As POINTAPI
' Lädt die neuen Brusheigenschaften und speichert die ' alten in den Variablen ' AutoReDraw muss False sein !!! Private Sub Form_Load() Me.ScaleMode = vbPixels ' Ersteinmal fragen wir den aktuellen Pinselursprung ab, ' den wir zum Schluss wiederherstellen müssen RetVal = GetBrushOrgEx(Me.hDC, OldOrginPt) ' Danach setzen wir den neuen Pinselursprung With NewOrginPt .x = 4 .y = 4 RetVal = SetBrushOrgEx(Me.hDC, .x, .y, NewOrginPt) End With ' Dann erstellen wir einen neuen Brush in Blau hBrushNew = CreateHatchBrush(HS_DIAGCROSS, vbBlue) ' Nun weisen wir den neuen Brush dem Fernster zu ' und erhalten den Alten aus dr Funktions-Rückgabe hBrushOld = SelectObject(Me.hDC, hBrushNew) End Sub
' Zeichnet den neuen Brush innerhalb eines Rechteckes Private Sub Form_Paint() ' Forminhalt löschen Me.Cls ' Weil beim Maximieren und Minimieren die From den alten ' Brush immer wiederherstellt, müssen wir ihn jedesmal erneut ' zuweisen, um sicher zu stellen, dass der gewollte Brush auch ' das Rechteck ausfüllt SelectObject Me.hDC, hBrushNew ' Nun zeichnen wir ein Rechteck in der mitte der Form RetVal = Rectangle(Me.hDC, Me.ScaleWidth / 3, Me.ScaleHeight / 3, _ Me.ScaleWidth / 3 * 2, Me.ScaleHeight / 3 * 2) End Sub
' Erzwingt, dass beim Maximieren das "Form_Paint" ' Ereignis ausgelöst wird Private Sub Form_Resize() If Me.WindowState = vbmxaximized Then Me.Refresh End If End Sub
' Stellt den Orginalbrush wieder her Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) ' Hier stellen wir den alten Brush und dessen ' Pinselursprung wieder her DeleteObject SelectObject(Me.hDC, hBrushOld) With OldOrginPt RetVal = SetBrushOrgEx(Me.hDC, .x, .y, OldOrginPt) End With End Sub