vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück
Rubrik: Grafik & Zeichnen22.03.05
CreatePolygonRgn-Funktion

Diese Funktion erstellt eine dreieckige Region und gibt das Handle zu dieser zurück.

Betriebssystem:  Win95, Win98, WinNT 3.1, Win2000, WinMEViews:  8.741 

Deklaration:

Declare Function CreatePolygonRgn Lib "gdi32.dll" ( _
  lpPoint As POINT_TYPE, _
   ByVal nCount As Long, _
  ByVal nPolyFillMode As Long) As Long

Beschreibung:
Diese Funktion erstellt eine dreieckige Region und gibt das Handle zu dieser zurück.

Parameter:
lpPointErwartet ein Array von POINTAPI-Strukturen, die mit den Koordinaten desDreiecks gefüllt sind.
nCountErwartet die Anzahl der Felder der "POINTAPI"-Struktur.
nPolyFillModeErwartet eine der "nPolyFillMode"-Konstanten, die beschreiben wie das Dreieck mit den entsprechenden Funktionen gefüllt werden soll.

nPolyFillMode Konstanten:

Const ALTERNATE = 1
' Alternative zwischen gefüllt und ungefüllt
 
Const WINDING = 2
' Das Dreieck normal gefüllt

Rückgabewert:
Ist die Funktion erfolgreich, so liefert sie das Handle zu der neu erstellten Region, andernfalls wird derWert "0" zurückgegeben.

Beispiel:

Private Declare Function CreateRoundRectRgn Lib "gdi32.dll" ( _
  ByVal X1 As Long, _
  ByVal Y1 As Long, _
  ByVal X2 As Long, _
  ByVal Y2 As Long, _
  ByVal X3 As Long, _
  ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgnIndirect Lib "gdi32.dll" ( _
  lpRect  As RECT) As Long
Private Declare Function GetWindowRgn Lib "user32.dll" ( _
  ByVal hwnd As Long, _
   ByVal hRgn As Long) As Long
Private Declare Function SetWindowRgn Lib "user32.dll" ( _
  ByVal hwnd As Long, _
   ByVal hRgn As Long, _
  ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" ( _
  ByVal hObject As Long)  As Long
Private Declare Function CreatePolygonRgn Lib "gdi32.dll" ( _
  lpPoint As POINTAPI, _
  ByVal nCount As Long, _
  ByVal nPolyFillMode As Long) As Long
Private Declare Function GetWindowRect Lib "user32" ( _
  ByVal hwnd As Long, _
   lpRect As RECT) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32.dll" ( _
  lpRect As RECT) As Long
Private Declare Function InflateRect Lib "user32.dll" ( _
  lpRect As RECT, _
   ByVal x As Long, _
  ByVal y As Long) As Long
Private Declare Function CopyRect Lib "user32.dll" ( _
  lpDestRect As RECT, _
   lpSourceRect As RECT) As Long
Private Declare Function EqualRgn Lib "gdi32.dll" ( _
  ByVal hSrcRgn1 As Long, _
   ByVal hSrcRgn2 As Long) As Long
Private Declare Function SetRect Lib "user32.dll" ( _
  lpRect As RECT, _
  ByVal X1  As Long, _
  ByVal Y1 As Long, _
  ByVal X2 As Long, _
  ByVal Y2 As Long) As Long
 
Private Type POINTAPI
  x As Long
  y As Long
End Type
 
Private Type RECT
  left As Long
  top As Long
  right As Long
  bottom As Long
End Type
 
' CreatePolygonRgn nPolyFillMode-Konstanten
Private Const ALTERNATE = 1 ' Alternative zwischen gefüllt und ungefüllt
Private Const WINDING = 2 ' Das Dreieck normal gefüllt
 
' GetWindowRgn Rückgabe Konstanten
Private Const ERROR = 0 ' Die Funktion konnte nicht ausgeführt werden
Private Const NULLREGION = 1 ' Es ist keine Region zugewiesen
Private Const SIMPLEREGION = 2 ' Die Region ist eine simple Region (RECT)
Private Const COMPLEXREGION = 3 ' Die Region ist eine komplexe Region
 
Dim RectRgn As Long, EllipticRgn As Long
Dim PolygonRgn As Long, RoundRectRgn As Long
Dim BufferRgn As Long
' Erstellt vier Regionen
Private Function CreateRgns()
  Dim Retval As Long, WndRect As RECT
  Dim Polygon(2) As POINTAPI, TmpRect As RECT
 
  ' Fensterkoordinaten ermitteln und Breite und Höhe ausrechnen
  Retval = GetWindowRect(Me.hwnd, WndRect)
  Retval = SetRect(WndRect, 0, 0, WndRect.right - WndRect.left,  _
  WndRect.bottom - WndRect.top)
 
  ' Eine Region zum Empfangen von Regiondaten erstellen
  BufferRgn = CreateRectRgnIndirect(TmpRect)
 
  ' Kopie der Fensterkoordinaten anlegen und verkleinern
  Retval = CopyRect(TmpRect, WndRect)
  Retval = InflateRect(TmpRect, -50, -50)
 
  ' Rechteckige Region erstellen
  RectRgn = CreateRectRgnIndirect(TmpRect)
 
  ' Elliptische Region erstellen
  EllipticRgn = CreateEllipticRgnIndirect(WndRect)
 
  ' Region mit abgerundeten Ecken erstellen
  With WndRect
    RoundRectRgn = CreateRoundRectRgn(.left, .top, .right, .bottom,  _
    50, 50)
  End With
 
  ' Dreieckige Region erstellen
  With Polygon(0)
    .x = 0
    .y = 0
  End With
  With Polygon(1)
    .x = WndRect.right
    .y = 0
  End With
  With Polygon(2)
    .x = WndRect.right / 2
    .y = WndRect.bottom
  End With
  PolygonRgn = CreatePolygonRgn(Polygon(0), 3, WINDING)
End Function
' Regionen erstellen und Info ausgeben
Private Sub Form_Load()
 
  ' Regionen erstellen
  Call CreateRgns
 
  ' Text auf die Form zeichnen für die Anweisungen
  Me.AutoRedraw = True
  Me.Print "Klicken sie mehrmals auf die Form"
End Sub
Private Sub Form_Click()
  Static NextOp As Long
  Dim Retval As Long
 
  ' Aktuell gesetzte Region ermitteln und alte entfernen
  Retval = GetWindowRgn(Me.hwnd, BufferRgn)
 
  NextOp = NextOp + 1
  If NextOp < 5 Then NextOp = 1
 
  ' neue Region setzen
  Select Case NextOp
  Case 1
    Retval = SetWindowRgn(Me.hwnd, EllipticRgn, True)
  Case 2
    Retval = SetWindowRgn(Me.hwnd, PolygonRgn, True)
  Case 3
    Retval = SetWindowRgn(Me.hwnd, RoundRectRgn, True)
  Case 4
    Retval = SetWindowRgn(Me.hwnd, RectRgn, True)
  Case 5
    Retval = SetWindowRgn(Me.hwnd, 0&, True) ' Der Form keine Region 'zuweisen 
    Call CreateRgns ' Regionen erneut erstellen
  End Select
End Sub
' Erstellte Regionen wieder entfernen
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  DeleteObject EllipticRgn
  DeleteObject PolygonRgn
  DeleteObject RoundRectRgn
  DeleteObject StdRgn
  DeleteObject BufferRgn
End Sub

Diese Seite wurde bereits 8.741 mal aufgerufen.

nach obenzurück
 
   

Druckansicht Druckansicht Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel