ImageSearch und keine Variablen im Dateinamen?

  • Hey,

    ich habe mir versucht ein kleines Script zu schreiben, welches für mich Icons auf dem Desktop verschiebt (kA wieso aber meine Icons machen sich beim hochfahren des Rechners immer selbstständig..) Nun habe ich auch alles soweit hinbekommen, nur leider stellt sich folgendes Problem:

    Ich lasse das Script nach einem variablen Bild suchen. Folgender Maßen: Das Bild wird in den Script-Ordner getan und Icon1-Icon10 genannt. Nun soll das Script mit Hilfe von ImageSearch nach diesen Icons suchen und sie an die entsprechende vordefinierte Stelle vom Desktop bewegen. Leider hängt es genau da -.-' Alles funktioniert einwandfrei, auch wenn ich folgender maßen die Daten ausgeben lasse :

    [autoit]

    MsgBox(64,"Info","Gesuchtes Icon: Icon"&$t&".bmp")

    [/autoit]


    wobei "t" für die entsprechende Zahl steht.

    Hier der ganze Code:

    Spoiler anzeigen
    [autoit]

    #include <ImageSearch.au3>
    #include <Array.au3>
    HotKeySet("{NUMPADSUB}","Ende")
    Sleep(2000)
    Dim $x=664
    Dim $y=346
    Dim $x1=0
    Dim $y1=0
    Dim $S1=498 ;~ Desktop Wunsch Platz X-Koord
    Dim $S2=360 ;~ Desktop Wunsch Platz Y-Koord
    $u=0
    $t=1
    Do
    For $i = 0 to 39
    Sleep(50)
    If ($i=5) OR ($i=10) OR ($i=15) OR ($i=20) OR ($i=25) OR ($i=30) OR ($i=35) OR ($i=40) Then
    $y=$y+32
    $S2=$S2+32
    $x=696
    $S1=530
    Sleep(100)
    $res=_ImageSearchArea("Icon"&$t&".bmp",1,$x,$y,$x+25,$y+25,$x1,$y1,10)
    If $res = 1 Then
    $u=$u+1
    MouseMove($x1,$y1,0)
    Sleep(1000)
    MouseMove($S1,$S2,0)
    Sleep(1000)
    EndIf
    Else
    $x=$x+32
    $S1=$S1+32
    Sleep(100)
    $res=_ImageSearchArea("Icon"&$t&".bmp",1,$x,$y,$x+25,$y+25,$x1,$y1,10)
    If $res = 1 Then
    $u=$u+1
    MouseMove($x1,$y1,0)
    Sleep(1000)
    MouseMove($S1,$S2,0)
    Sleep(1000)
    EndIf
    EndIf
    TrayTip("Momentane Position","Versuch: "&$i&", Position X: "&$x&", Position Y: "&$y,2) ;~ dient nur der Übersicht während dem laufendem Script
    Next
    If $res=0 Then
    $y=346
    $S2=360
    $t=$t+1
    EndIf
    Until $t=10

    [/autoit] [autoit][/autoit] [autoit]

    Func Ende()
    Exit
    EndFunc

    [/autoit]

    Warum funktioniert das nicht? Wie gesagt wenn ich die Icon Nr mit ner MsgBox ausgeben lasse funktionierts...aber das Script sucht nicht nach Icon1-10 warum nicht?

    Pls help

    Wong

  • Weiß keiner darauf ne Antwort ? Ich versuch da jetzt seit 2 Wochen hinter zu kommen, aber egal was ich mache: Es klappt nicht -.-

    • Offizieller Beitrag

    Wie sollen in deinem Script die Icons verschoben werden ? Ausser MouseMove machst du doch nichts. Was hällst du davon auch einen MouseClick oder z.b. Mousedown oder MouseUp zu machen. Bis jetzt wird bestenfalls der Mauszeiger hin- und herbewegt.

  • Aso jo sry ^^ Hab zum Testen (weil das Script mir Anfangs richtiges Chaos auf den Bildschirm gezaubert hat) nur nen MouseMove Befehl genutzt. In der finalen Version kommt natürlich MouseClickDrag ;) Aber erstmal muss die ImageSearchArea Funktion die var zwischen "Icon" und ".bmp" annehmen...Lösungshilfen?

    • Offizieller Beitrag

    Was hällst du davon die ImageSearch.au3 auch in deinem Thead zu stellen ? Oder sollen wir uns die ausdenken ?

  • hmm wusste nicht das die hier im Forum unbekannt ist...ist aber nicht mein ImageSearch.au3 .. die habe ich von jemandem über ICQ zugesandt bekommen...kA wo der die her hat.

    Hier:

    Spoiler anzeigen
    [autoit]

    #include-once
    ; ------------------------------------------------------------------------------
    ;
    ; AutoIt Version: 3.0
    ; Language: English
    ; Description: Functions that assist with Image Search
    ; Require that the ImageSearchDLL.dll be loadable
    ;
    ; ------------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Find the position of an image on the desktop
    ; Syntax: _ImageSearchArea, _ImageSearch
    ; Parameter(s):
    ; $findImage - the image to locate on the desktop
    ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ; image differ from desktop. e.g GIF
    ; $resultPosition - Set where the returned x,y location of the image is.
    ; 1 for centre of image, 0 for top left of image
    ; $x $y - Return the x and y location of the image
    ;
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0
    ;
    ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
    ; a desktop region to search
    ;
    ;===============================================================================
    Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)

    [/autoit] [autoit][/autoit] [autoit]

    ; If error exit
    if $result[0]="0" then return 0

    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0],"|")

    $x=Int(Number($array[2]))
    $y=Int(Number($array[3]))
    if $resultPosition=1 then
    $x=$x + Int(Number($array[4])/2)
    $y=$y + Int(Number($array[5])/2)
    endif
    return 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Wait for a specified number of seconds for an image to appear
    ;
    ; Syntax: _WaitForImageSearch, _WaitForImagesSearch
    ; Parameter(s):
    ; $waitSecs - seconds to try and find the image
    ; $findImage - the image to locate on the desktop
    ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ; image differ from desktop. e.g GIF
    ; $resultPosition - Set where the returned x,y location of the image is.
    ; 1 for centre of image, 0 for top left of image
    ; $x $y - Return the x and y location of the image
    ;
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
    sleep(100)
    $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
    if $result > 0 Then
    return 1
    EndIf
    WEnd
    return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Wait for a specified number of seconds for any of a set of
    ; images to appear
    ;
    ; Syntax: _WaitForImagesSearch
    ; Parameter(s):
    ; $waitSecs - seconds to try and find the image
    ; $findImage - the ARRAY of images to locate on the desktop
    ; - ARRAY[0] is set to the number of images to loop through
    ; ARRAY[1] is the first image
    ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ; image differ from desktop. e.g GIF
    ; $resultPosition - Set where the returned x,y location of the image is.
    ; 1 for centre of image, 0 for top left of image
    ; $x $y - Return the x and y location of the image
    ;
    ; Return Value(s): On Success - Returns the index of the successful find
    ; On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
    for $i = 1 to $findImage[0]
    sleep(100)
    $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
    if $result > 0 Then
    return $i
    EndIf
    Next
    WEnd
    return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]
    • Offizieller Beitrag

    Boah muß man alles aus dir rauskitzeln ? Wo ist die ImageSearchDLL.dll ? Die wird nämlich auch gebraucht .

  • ...hier haste das gesamte rar Archiv so wie ich es bekommen hab :)...

    €dit: Bin erstmal schlafen...

    Einmal editiert, zuletzt von MrWong (31. Januar 2009 um 01:27)

  • Ah jetz weiß ich woher es ist ^^ Wie gesagt habs per ICQ bekommen...hmm kann jemand helfen? Hab auch schon versucht den Pfad fürs Bild als Var in die ImageSearch einzubauen, aber da is das selbe Prob wie vorher auch...der nimmt es nicht an...

  • Hi,
    McPoldy hat mal ein Script zum wiederherstellen von Desktopicons geschrieben ...

    Spoiler anzeigen
    [autoit]

    ;#################################################################################################
    ;
    ; Titel: Restore-IconPos-Desktop
    ; Datum: 15. Feb. 2008
    ; Version: 1.0
    ;
    ; Anmerkungen:
    ;
    ; - Die Position der Icons und der Titel wird in einer INI Datei gespeichert
    ; - Das Script wird über Parameter aufgerufen:
    ; -save = Speichert die Positionen
    ; -restore = Plaziert die Icons wieder da wo sie waren
    ;
    ;#################################################################################################

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; Einfügen der Include Dateien
    ;#################################################################################################
    #include <Array.au3>
    #include <File.au3>
    #include <GuiListView.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; Optionen setzen
    ;#################################################################################################
    #NoTrayIcon ;Kein TrayIcon anzeigen
    Opt("MustDeclareVars", 1) ;Variablen müssen deklariert werden

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; Variablen deklarieren
    ;#################################################################################################
    Local $handle ;Handle für den Desktop
    Local $anzIcons ;Anzahl der Icons auf dem Desktop
    Local $arrIcons[1] ;Array für Restore
    Local $arrayPos ;Position im Array
    Local $txt ;Für das zwischenspeichern von Texten
    Local $int ;Als Zähler Variable
    Local $icon ;Name des Icon
    Local $posX ;X Position
    Local $posY ;y Position
    Local $Mode = "Help" ;In welchem Modus das Script gestartet wurde
    Local $iniFile = @ScriptDir & "\icons.ini" ;Pfad zu der Ini-Datei

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; Programm Einstigspunkt (POE)
    ;#################################################################################################
    If $CmdLine[0] > 0 Then
    $Mode = $CmdLine[1]
    _CheckIniExsit()
    Switch $CmdLine[1]
    Case "-save"
    ToolTip("Positionen der Icons werden gespeichert!",0,0,"Info")
    Sleep(1000)
    _SavePos()
    Case "-restore"
    ToolTip("Icons werden wieder hergestellt!",0,0,"Info")
    Sleep(1000)
    _RestorePos()
    Case Else
    _ShowHelp()
    EndSwitch
    Else
    _ShowHelp()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Exit 0 ;Programm wird verlassen

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; _CheckIniExsit
    ; Diese Funktion prüft ob die INI Datei vohanden ist, falls Nein, wird eine leere Datei
    ; erstellt. Ist eine vorhanden, wird gelöscht und eine neue erstellt, aber nur bei -save
    ;#################################################################################################
    Func _CheckIniExsit()
    IF Not FileExists($iniFile) Then
    _FileCreate($iniFile)
    If @error Then
    MsgBox(48,"Fehler","INI-Datei konnte nicht erstellt werden.")
    Exit 1
    EndIf
    ElseIf $Mode = "-save" Then
    If FileDelete($iniFile) = 0 Then
    MsgBox(48,"Fehler","INI-Datei konnte nicht gelöscht werden.")
    Exit 1
    EndIf
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; _ShowHelp
    ; Wenn das Script ohne Parameter gestartet wird, wird diese Hilfe angezeigt, oder wenn ein
    ; falscher Parameter übergeben wurde.
    ;#################################################################################################
    Func _ShowHelp()
    $txt = "Parameter:" & @CRLF
    $txt &= "-save = Speichert die Positionen" & @CRLF
    $txt &= "-restore = Plaziert die Icons wieder da wo sie waren"
    MsgBox(64,"Hilfe - Restore-IconPos-Desktop", $txt)
    Exit 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; _SavePos
    ; Speichern der Icon Positionen in der INI Datei
    ;#################################################################################################
    Func _SavePos()
    $handle = ControlGetHandle("Program Manager", "", "SysListView321")
    $anzIcons = _GUICtrlListView_GetItemCount ($handle) - 1
    IniWrite($iniFile,"Global","Anzahl",$anzIcons)
    For $int = 0 To $anzIcons
    IniWrite($iniFile,"IconPos" & $int,"Icon",_GUICtrlListView_GetItemText($handle,$int))
    IniWrite($iniFile,"IconPos" & $int,"X-Pos",_GUICtrlListView_GetItemPositionX ($handle,$int))
    IniWrite($iniFile,"IconPos" & $int,"Y-Pos",_GUICtrlListView_GetItemPositionY ($handle,$int))
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;#################################################################################################
    ; _RestorePos
    ; Speichern der Icon Positionen in der INI Datei
    ;#################################################################################################
    Func _RestorePos()
    $anzIcons = IniRead($iniFile,"Global","Anzahl",-1)
    If $anzIcons = -1 Then
    MsgBox(48,"Fehler","INI-Datei ist leer.")
    Exit 1
    Else
    $handle = ControlGetHandle("Program Manager", "", "SysListView321")
    ReDim $arrIcons[_GUICtrlListView_GetItemCount ($handle)]
    For $int = 0 To UBound($arrIcons) - 1
    $arrIcons[$int] = _GUICtrlListView_GetItemText($handle,$int)
    Next
    For $int = 0 To $anzIcons
    $icon = IniRead($iniFile,"IconPos" & $int,"Icon",-1)
    $posX = IniRead($iniFile,"IconPos" & $int,"X-Pos",-1)
    $posY = IniRead($iniFile,"IconPos" & $int,"Y-Pos",-1)
    If $icon = -1 Or $posX = -1 Or $posY = -1 Then ContinueLoop
    $arrayPos = _ArraySearch($arrIcons,$icon,0,0,1,False)
    If $arrayPos = -1 Then ContinueLoop
    _GUICtrlListView_SetItemPosition($handle,$arrayPos,$posX,$posY)
    Next
    EndIf
    EndFunc

    [/autoit]

    Vielleicht kannste ja was mit anfangen :).

    anno2008

  • Dafür erstmal ein Thx..=)

    Aber ich würde trotzdem gerne mehr über die ImageSearch Funktion lernen ^^ Daher lasse ich das Thema mal als "offen" stehen =)

    Dennoch Thx an dich anno =)

    so long
    MrWong