AW: Maus mit Excel steuern
18.03.2005 09:32:03
Ramses
Hallo
"...Aber das wäre dann im Detail zu lösen..."
Das sieht mir einfach zu sehr nach Auftragsprogrammierung aus
"...Wenn Du etwas Positives beitragen kannst,..."
Denke ich schon, ob du damit allerdings was anfangen kannst, bezweifle ich.
"...Dein Hinweis, dass mein Wissensstand für meine Aufgabe unterentwickelt ist, hilft niemandem weiter..."
Wenn du fliegen lernen willst, solltest du nicht mit einem Kampfjet beginnen :-)
Auch ich habe deine bisherigen Beiträge gelesen ;-)
"...Es hilft mir nicht, weil es mich nicht weiter bringt..."
In der Recherche sind dazu einige Artikel zu finden
Ob deine Variante mit "gesteuerten Mausklick" überhaupt sinnvoll ist, wage ich trotzdem zu beweifeln. Das ist viel zu unsicher.
Ich gebe dir hier mal einige Codebeispiele:
Finden einer Applikation
Option Explicit
'Listet alle aktiven Fenter / Applikation auf
Private Declare Function GetWindow Lib "user32" _
(ByVal appWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal appWnd As Long, ByVal wIndx As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" _
(ByVal appWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal appWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Private Function GetWindowTitle(ByVal appWnd As Long) As String
Dim appResult As Long, appTempStr As String
appResult = GetWindowTextLength(appWnd) + 1
appTempStr = Space(appResult)
appResult = GetWindowText(appWnd, appTempStr, appResult)
GetWindowTitle = Left(appTempStr, Len(appTempStr) - 1)
End Function
Sub CheckWindow()
Dim x As Variant
Dim appName As String
Dim Qe As Integer
'Mit Parameter 0 wird nur True oder False
'bei der Suche nach dem Programm Namen zurückgegeben
'Mit Parameter 1 erfolgt die Ausgabe aller
'gefundenen Fenster in eine MsgBox
appName = "Excel"
appName = InputBox("Bitte geben Sie die Applikation ein, die gesucht werden soll", _
"Suche nach geöffneter Applikation", appName)
Qe = MsgBox("Soll nur geprüft werden ob die Application: " & appName & " geöffnet ist?", _
vbQuestion + vbYesNo, "Prüfung")
If Qe = vbYes Then
MsgBox "Applikation: """ & appName & """ ist geöffnet: " & GetWindowList(appName, 0)
Else
x = GetWindowList("EXCEL", 1)
End If
End Sub
Public Function GetWindowList(findApp As String, kindMsg As Integer) As Boolean
'Gibt True zurück wenn die Applikation aktiv ist
Dim app() As Long
Dim appWnd As Long, appTitle As String, appStyle As Long, appTask_name() As String
Dim appCount As Integer, appIndex As Integer, appFound As Boolean
Dim msgTxt As String
appWnd = FindWindow(ByVal 0&, ByVal 0&)
appWnd = GetWindow(appWnd, GW_HWNDFIRST)
'1. Initialisierung
GetWindowList = False
Do
'Loop starten durch alle geöffneten Fenster
appFound = False
appStyle = GetWindowLong(appWnd, GWL_STYLE)
appStyle = appStyle And (WS_VISIBLE Or WS_BORDER)
appTitle = GetWindowTitle(appWnd)
'Alle gefundenen Applicationen in einen Array aufnehmen
If (appStyle = (WS_VISIBLE Or WS_BORDER)) = True Then
If Trim(appTitle) "" Then
For appIndex = 1 To appCount
If appTask_name(appIndex) = appTitle Then
appFound = True
Exit For
End If
Next appIndex
If Not appFound Then
appCount = appCount + 1
ReDim Preserve appTask_name(1 To appCount)
appTask_name(appCount) = appTitle
ReDim Preserve app(1 To appCount)
app(appCount) = appWnd
End If
End If
End If
appWnd = GetWindow(appWnd, GW_HWNDNEXT)
Loop Until appWnd = 0
'Durchsuchen des erstellten Arrays nach der Application
If kindMsg = 0 Then
For appIndex = 1 To appCount
'Es wird nur der übergebene String in "appTask_Name" gesucht
'Die Instanz selbst wird nicht identifiziert.
'Dazu müsste noch der String "Microsoft" geprüft werden
If InStr(1, appTask_name(appIndex), findApp) > 1 Then
'Application gefunden = Ende der Schleife
GetWindowList = True
Exit Function
End If
Next appIndex
ElseIf kindMsg = 1 Then
For appIndex = 1 To appCount
msgTxt = msgTxt & "Aktiv: " & appTask_name(appIndex) & Chr$(13)
Next appIndex
MsgBox msgTxt
GetWindowList = True
End If
End Function
Function Check_Open_Application(appName As String) As Boolean
'Test Function
If GetWindowList(appName) Then
Check_Open_Application = True
Else
Check_Open_Application = False
End If
End Function
Sub Start_Run_Check()
If Check_Open_Application(InputBox _
("Geben Sie den Programmtitel ein." & Chr$(13) & _
"ACHTUNG: Case Sensitiv !!", "Suche Application", "Excel")) = True Then
Debug.Print "Test erfolgreich"
Else
Debug.Print "Test nicht erfolgreich"
End If
End Sub
Sub Open_Test_File()
Dim s$, AppExec As Long
s = "c:\test.txt"
If GetWindowList("Editor") Then
'AppExec = ShellExecute(2140, vbNullString, s, "", "", 1)
Debug.Print "OK"
Else
MsgBox "Applikation nicht aktiv"
End If
End Sub
Mausbewegung steuern
'Mausposition auslesen
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Sub WhereAmI_Mausposition_auslesen()
Dim pTargetPoint As POINTAPI
Dim lRetVal As Long
lRetVal = GetCursorPos(pTargetPoint)
MsgBox "Meine Position:" & vbLf & pTargetPoint.x & "," & pTargetPoint.y
End Sub
Function MausZeigerMove()
Dim i As Integer
Dim MousePosition As POINTAPI
GetCursorPos MousePosition
For i = MousePosition.x To MousePosition.x + 20 Step 1
SetCursorPos i, MousePosition.y
Sleep 20
Next
End Function
'Beliebiges Fenster in Vordergrund holen
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
'von Chris B.
Sub Vordergrund()
wHandle = FindWindow(vbNullString, "Rechner")
Call SetWindowPos(wHandle, -1, 0, 0, 0, 0, 3)
End Sub
Viel Spass damit :-)
Gruss Rainer