Live-Forum - Die aktuellen Beiträge
Datum
Titel
29.03.2024 13:14:12
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1128to1132
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Fensterposition ermitteln

Fensterposition ermitteln
marspoki
Hallo,
ich habe mal eine Frage. Gibt es eine Möglichkeit die Aktuelle Fensterposition eines Programms (z.B. Word) auszulesen und diese dann in A1 und B1 einzutragen?
Vielen Dank für eure Hilfe
Gruß
marspoki

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Fensterposition ermitteln
13.01.2010 14:16:20
Björn
Hallo,
ich weiß nicht genau wie es geht, du kannst aber über Application die Eigenschaften Left und Top abfragen bzw. setzen.
Das gibt dann den Abstand zur linken oberen Ecke an.
Gruß
Björn B.
AW: Fensterposition ermitteln
13.01.2010 14:24:21
marspoki
Vielen Dank
Leider weiß ich nicht wie man das macht? :-(
Hat jemand einen Rat
AW: Fensterposition ermitteln
13.01.2010 14:36:44
marspoki
Nur noch vorab.
Ich hole mir das Fenster mit folgendem Code in Vordergrund
Option Explicit
Option Explicit
Private Declare Function SetForegroundWindow _
Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow 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 GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As _
Long) As Long
Private Declare Function ShowWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Const GWL_STYLE& = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Const GW_HWNDNEXT& = 2
Const GW_CHILD& = 5
Const iNormal& = 1
Const iMinimized& = 2
Const iMaximized& = 3
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Sub mouse_event Lib "user32.dll" _
(ByVal dwFlags As Long, ByVal dx As Long, _
ByVal dy As Long, ByVal dwdata As Long, _
ByVal dwExtraInfo As Long)
Private Declare Function SetCursorPos Lib "user32" _
(ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As Maus_Pos) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Type Maus_Pos
X As Long
Y As Long
End Type
Private Function GetWindowInfo(ByVal hwnd&, STitel$, Optional booVisible As Boolean = True) As  _
Long
Dim Result&, Style&, Title$
'Darstellung des Fensters
Style = GetWindowLong(hwnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
'Fensetrtitel ermitteln
Result = GetWindowTextLength(hwnd) + 1
Title = Space$(Result)
Result = GetWindowText(hwnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
'prüfen ob Fenster Sichtbar
If (Style = (WS_VISIBLE Or WS_BORDER)) Or booVisible = False Then
If Title Like "*" & STitel & "*" Then
GetWindowInfo = hwnd
Exit Function
End If
End If
GetWindowInfo = 0
End Function

Sub FensterHolen()
Dim hwnd As Long
Dim STitel As String
'hier einen Teil vom Titel angeben ******************
STitel = "Microsoft Word"
hwnd = GetDesktopWindow()
hwnd = GetWindow(hwnd, GW_CHILD)
'2. Param. Fenstertitel (nur ein Teil erforderlich)
'3. Param. optional True nur Sichtbare, False alle
GetWindowInfo hwnd, STitel, True
Do While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
If GetWindowInfo(hwnd, STitel, True) = hwnd Then
ShowWindow hwnd, iNormal 'maximieren
SetForegroundWindow hwnd 'aktivieren
End If
Loop
End Sub

Anzeige
AW: Fensterposition ermitteln
13.01.2010 14:37:16
marspoki
Hat jemand eine idee? Vielen Dank
AW: Fensterposition ermitteln
15.01.2010 07:07:40
Anton
Hallo marspoki,
probier's hiermit:
Code:

Private Type RECT
  Left As Long  
  Top As Long  
  Right As Long  
  Bottom As Long  
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long      
Private Declare Function GetForegroundWindow Lib "user32" () As Long      
Sub fensterposition_auslesen()
  Dim Rec As RECT  
  Shell "winword", vbNormalFocus
  GetWindowRect GetForegroundWindow, Rec  
  MsgBox "Links:" & Rec.Left & vbCr & _
         "Oben:" & Rec.Top & vbCr & _
         "Rechts:" & Rec.Right & vbCr & _
         "Unten:" & Rec.Bottom
End Sub  


mfg Anton
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige