Rubrik: Fenster | 22.03.05 |
GetWindowExtEx-Funktion Diese Funktion ermittelt die Breite eines Grafikgerätes in logischen Schritten. | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 7.586 |
Deklaration:
Declare Function GetWindowExtEx Lib "gdi32" ( _ ByVal hdc As Long, _ lpSize As POINTAPI) As Long
Beschreibung:
Diese Funktion ermittelt die Breite eines Grafikgerätes in logischen Schritten.
Parameter:
hdc | Erwartet das Handle des Gerätes, dessenlogische Schritte ermittelt werden sollen. |
lpSize | Erwartet eine POINTAPI-Struktur, die mit denMaßen der horizontalen und vertikalen Schritten gefüllt wird. |
Rückgabewert:
Ist die Funktion erfolgreich, so wird ein Wert "ungleich 0" zurückgegeben, andernfalls derWert "0". Unter Windows NT, 2000 und XP können Sie die GetLastError-Funktion für erweiterte Fehlerinformationen aufrufen.
Beispiel:
Private Declare Function SetMapMode Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nMapMode As Long) As Long Private Declare Function GetMapMode Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function GetWindowExtEx Lib "gdi32" ( _ ByVal hdc As Long, _ lpSize As POINTAPI) As Long Private Declare Function SetWindowExtEx Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nX As Long, _ ByVal nY As Long, _ lpSize As Any) As Long Private Declare Function GetViewportExtEx Lib "gdi32" ( _ ByVal hdc As Long, _ lpSize As POINTAPI) As Long Private Declare Function SetViewportExtEx Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nX As Long, _ ByVal nY As Long, _ lpSize As Any) As Long Private Declare Function Polyline Lib "gdi32" ( _ ByVal hdc As Long, _ lpPoint As POINTAPI, _ ByVal nCount As Long) As Long Private Declare Function GetClientRect Lib "user32" ( _ ByVal hwnd As Long, _ lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI x As Long y As Long End Type ' Get- / SetMapMode Rückgabe- / nMapMode-Konstanten Private Const MM_ANISOTROPIC = 8 ' Benutzerdefiniert, X- und Y-Achse haben verschiedene Skalierungen. ' Benutzen Sie die Get-/SetViewPortExtEx-Funktion und die ' Get-/SetWindowExtEx-Funktion, um die Maßeinheiten zu definieren Private Const MM_HIENGLISH = 5 ' Jeder logische Schritt ist 0,001 Inch Private Const MM_HIMETRIC = 3 ' Jeder logische Schritt ist 0,01 Millimeter Private Const MM_ISOTROPIC = 7 ' Benutzerdefiniert, X- und Y-Achse haben die selben Skalierungen. ' Benutzen Sie die Get-/SetViewPortExtEx-Funktion und die ' Get-/SetWindowExtEx-Funktion, um die Maßeinheit zu definieren Private Const MM_LOENGLISH = 4 ' Jeder logische Schritt ist 0,01 Inch Private Const MM_LOMETRIC = 2 ' Jeder logische Schritt ist 0,1 Millimeter Private Const MM_TEXT = 1 ' Jeder logische Schritt ist ein Pixel Private Const MM_TWIPS = 6 ' Jeder logische Schritt ist ein Twip Dim OldMapMode As Long, OldWindowExt As POINTAPI, OldViewport As POINTAPI Dim TmpPT(5) As POINTAPI, ClientR As RECT
' Skalierung der Form ermitteln Private Sub Form_Load() Dim RetVal As Long ' Aktuelle Skalierung ermitteln OldMapMode = GetMapMode(Me.hdc) Call GetViewportExtEx(Me.hdc, OldViewport) Call GetWindowExtEx(Me.hdc, OldWindowExt) ' Figur festlegen (Sechseck) TmpPT(0).x = 50 TmpPT(0).y = 2 TmpPT(1).x = 98 TmpPT(1).y = 35 TmpPT(2).x = 79 TmpPT(2).y = 90 TmpPT(3).x = 21 TmpPT(3).y = 90 TmpPT(4).x = 2 TmpPT(4).y = 35 TmpPT(5).x = 50 TmpPT(5).y = 2 End Sub
' Figur zeichnen (2 logische Schritte Abstand zu jedem Rand) Private Sub Form_Paint() Me.Cls ' Fensterbereich ermitteln Call GetClientRect(Me.hwnd, ClientR) ' Neue Skalierung der Form setzen (100/92 Schritte = Fensterbreite / Höhe) Call SetMapMode(Me.hdc, MM_ANISOTROPIC) ' Benutzerdefinierten Typen wählen Call SetWindowExtEx(Me.hdc, 100, 92, ByVal 0&) ' Das Fenster soll ' 100/92 logische Schritte hoch und breit sein Call SetViewportExtEx(Me.hdc, ClientR.Right, ClientR.Bottom, ByVal 0&) _ ' Die 100/92 Schritte ergeben sich aus der Fensterhöhe und Breite Call Polyline(Me.hdc, TmpPT(0), 6) ' Figur Zeichnen Me.CurrentX = 10 Me.CurrentY = 10 Me.Print "Hallo" End Sub
Private Sub Form_Resize() Me.Refresh End Sub
' Alte Skalierung wieder herstellen Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Call SetMapMode(Me.hdc, OldMapMode) Call SetViewportExtEx(Me.hdc, OldViewport.x, OldViewport.y, ByVal 0&) Call SetWindowExtEx(Me.hdc, OldWindowExt.x, OldWindowExt.y, ByVal 0&) End Sub