Rubrik: Grafik & Zeichnen | 22.03.05 |
CreatePenIndirect-Funktion Diese Funktion erstellt einen Pen und gibt das Handle zu diesem zurück. | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 6.330 |
Deklaration:
Declare Function CreatePenIndirect Lib "gdi32.dll" (lpLogPen As LOGPEN) As Long
Beschreibung:
Diese Funktion erstellt einen Pen und gibt das Handle zu diesem zurück.
Parameter:
lpLogPen | Erwartet eine LOGPEN-Struktur, die mit Informationen über den zu erstellenden Pen gefüllt ist. |
Rückgabewert:
Ist die Funktion erfolgreich, so liefert sie das Handle des erstellten Pen, andernfalls wird derWert "0" zurückgegeben. Unter Windows NT, 2000 und XP können Sie die GetLastError-Funktion für erweiterte Fehlerinformationen aufrufen.
Beispiel:
Private Declare Function Chord Lib "gdi32.dll" ( _ ByVal hdc As Long, _ ByVal nLeftRect As Long, _ ByVal nTopRect As Long, _ ByVal nRightRect As Long, _ ByVal nBottomRect As Long, _ ByVal nXRadial1 As Long, _ ByVal nYRadial1 As Long, _ ByVal nXRadial2 As Long, _ ByVal nYRadial2 As Long) As Long Private Declare Function CreatePenIndirect Lib "gdi32.dll" ( _ lpLogPen As LOGPEN) As Long Private Declare Function DeleteObject Lib "gdi32.dll" ( _ ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32.dll" ( _ ByVal hdc As Long, _ ByVal hObject As Long) As Long Private Type POINTAPI x As Long y As Long End Type Private Type LOGPEN lopnStyle As Long lopnWidth As POINTAPI lopnColor As Long End Type Private Const PS_SOLID = 0 Private Const PS_DASH = 1 Private Const PS_DOT = 2 Private Const PS_DASHDOT = 3 Private Const PS_DASHDOTDOT = 4 Private Const PS_NULL = 5 Private Const PS_INSIDEFRAME = 6
Private Sub Form_Load() Dim Retval As Long, hPen As Long, hOldPen As Long, PenInfo As LOGPEN Me.AutoRedraw = True Me.ScaleMode = vbPixels ' Pen definieren With PenInfo .lopnColor = vbRed .lopnStyle = PS_DASHDOTDOT End With ' Pen erstellen hPen = CreatePenIndirect(PenInfo) ' Pen der Form zuweisen und alten zwischenspeichern hOldPen = SelectObject(Me.hdc, hPen) ' Halbkreis zeichnen Retval = Chord(Form1.hdc, 10, 10, Me.ScaleWidth - 20, Me.ScaleHeight - _ 20, (Me.ScaleWidth - 20) / 2, 10, (Me.ScaleWidth - 20) / 2, _ Me.ScaleHeight - 20) ' Alten Pen wiederherstellen Call SelectObject(Me.hdc, hOldPen) ' erstellten Pen zerstören DeleteObject hPen End Sub