Größe fremder Fenster ermitteln
[Windows 95/98/NT/2000]

11.08.1999


Mit Hilfe folgender Anweisungen können Sie die Größe
    fremder Fenster ermitteln.
    Entweder die Größe des aktiven Fensters,
    oder aber
die Größe eines bestimmten Fensters kann man ermitteln:

ERFORDERLICHE OBJEKTE
   1 Timer (Timer1)
   2 Labels (lblTitel, lblGröße)

 FORM-CODE
   Private Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
   End Type
   Private Declare Function GetForegroundWindow Lib _
      "user32" () As Long
   Private Declare Function GetWindowTextLength Lib _
      "user32" Alias "GetWindowTextLengthA" _
      (ByVal hwnd As Long) As Long
   Private Declare Function GetWindowText Lib "user32" Alias _
      "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
      As String, ByVal cch As Long) As Long
   Private Declare Function GetWindowRect Lib "user32" _
      (ByVal hwnd As Long, lpRect As RECT) As Long
   Private Declare Function FindWindow Lib "user32" Alias _
      "FindWindowA" (ByVal lpClassName As String, _
      ByVal lpWindowName As String) As Long
   Sub Timer1_Timer()
      Dim hwCurr As Long
      Dim intLen As Long
      Dim strTitle As String
      Dim Size As RECT
      'aktives Fenster
      hwCurr = GetForegroundWindow
      'oder spezielles Fenster
      'hwCurr = FindWindow(vbNullString, "Papierkorb")
      intLen = GetWindowTextLength(hwCurr) + 1
      strTitle = Space$(intLen)
      intLen = GetWindowText(hwCurr, strTitle, intLen)
      lblTitel.Caption = strTitle
      Handle = GetWindowRect(hwCurr, Size)
      Breite = Size.Right - Size.Left
      Höhe = Size.Bottom - Size.Top
      lblGröße.Caption = Breite & "*" & Höhe
   End Sub
 

 

Download - 2 KB