Drop in ein Image

  • Hallo *.*

    Folgendes will ich realisieren, vielleicht gibts dazu schon eine Vorlage.

    Gekürztes Beispiel, Prinzip bleibt aber gleich :

    GUI enthält ein Bild, 3 Radiobuttons, ein Editfield und OK/Ende Button.
    Per drag&drop will ich eine Datei auf das Bild ziehen und dabei soll folgendes passieren :
    Der Dateiname (mit vollem Pfad) soll im Edifield erscheinen, gleichzeitig soll einer der 3 Radiobuttons gesetzt werden und zwar in
    Abhängigkeit vom Namen. Radiobutton1 hat z.b den Namen "C", Radiobutton2 "D" und Radiobutton3 "E". Wird einen Datei gezogen die von Laufwerk D: kommt (d:\test.txt), so soll der Radiobutton2 aktiviert werden.

    Es hängt noch mehr dran, aber dies vereinfacht als Beispiel.

    any ideas, Stichwort "GUICtrlSetOnEvent"


    Grüße
    Jonny

    Einmal editiert, zuletzt von Jonny (28. Oktober 2009 um 19:18)

  • So was?

    Spoiler anzeigen
    [autoit]


    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    Opt('MustDeclareVars', 1)

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

    Global $msg, $w, $h, $Input, $Radio1, $Radio2, $Radio3, $Button, $file
    $w = 640
    $h = 480
    GUICreate("Test", $w, $h, -1, -1, $WS_SIZEBOX + $WS_SYSMENU, $WS_EX_ACCEPTFILES)

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

    GUICtrlCreatePic(@SystemDir & "\oobe\msoobe.jpg", 0,0, $w, $h - 80)

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

    $Input = GUICtrlCreateInput("", 8, 430, 517, 21, $ES_READONLY)
    $Radio1 = GUICtrlCreateRadio("C:\", 8, 408, 57, 17)
    $Radio2 = GUICtrlCreateRadio("D:\", 304, 408, 57, 17)
    $Radio3 = GUICtrlCreateRadio("E:\", 568, 408, 57, 17)
    $Button = GUICtrlCreateButton("OK", 560, 430, 57, 21)

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

    GUIRegisterMsg(0x0233, "WM_DROPFILES") ;0x0233 = $WM_DROPFILES

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

    GUISetState()

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

    While 1
    $msg = GUIGetMsg()

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

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()

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

    Func WM_DROPFILES($hwnd, $msg, $wParam, $lParam)
    Local $tBuffer = DllStructCreate("char[256]")
    Local $iString

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

    ;Get dropped items count
    Local $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", -1, "ptr", 0, "int", 0)

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

    ;Getting name only from 1st dropped item
    DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", 0, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer))
    $iString = DllStructGetData($tBuffer, 1)
    DllCall("shell32.dll", "none", "DragFinish", "int", $wParam)

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

    GUICtrlSetData($Input, $iString)
    If StringLeft($iString, 1) = "c" Then GUICtrlSetState($Radio1, $GUI_CHECKED)
    If StringLeft($iString, 1) = "d" Then GUICtrlSetState($Radio2, $GUI_CHECKED)
    If StringLeft($iString, 1) = "e" Then GUICtrlSetState($Radio3, $GUI_CHECKED)

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

    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_DROPFILES

    [/autoit]

    Eventuell musst du noch den Pfad des Bildes anpassen!

    Gruß,
    UEZ

    • Offizieller Beitrag

    Bei nur einer "Drag"-Datei reichen auch die Standard-AutoIt-Funktionen (ohne GuiRegisterMsg):

    Spoiler anzeigen
    [autoit]


    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    Opt('MustDeclareVars', 1)

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

    Global $msg, $w, $h, $Input, $Radio1, $Radio2, $Radio3, $Button
    $w = 640
    $h = 480
    GUICreate("Test", $w, $h, -1, -1, $WS_SIZEBOX + $WS_SYSMENU, $WS_EX_ACCEPTFILES)

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

    GUICtrlCreatePic(@WindowsDir & "\Santa Fe-Stuck.bmp", 10, 10, 250, 250)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

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

    $Input = GUICtrlCreateInput("", 8, 430, 517, 21, $ES_READONLY)
    $Radio1 = GUICtrlCreateRadio("C:\", 8, 360, 57, 17)
    $Radio2 = GUICtrlCreateRadio("D:\", 8, 380, 57, 17)
    $Radio3 = GUICtrlCreateRadio("E:\", 8, 400, 57, 17)
    $Button = GUICtrlCreateButton("OK", 560, 430, 57, 21)

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

    GUISetState()

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

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_DROPPED
    Switch StringLeft(@GUI_DragFile, 2)
    Case 'c:'
    GUICtrlSetState($Radio1, $GUI_CHECKED)
    Case 'd:'
    GUICtrlSetState($Radio2, $GUI_CHECKED)
    Case 'e:'
    GUICtrlSetState($Radio3, $GUI_CHECKED)
    EndSwitch
    GUICtrlSetData($Input, @GUI_DragFile)
    EndSwitch
    WEnd

    [/autoit]
  • Hi subbi, danke euch beiden. Oscar sein Teil genügt genau für den Zweck und funktioniert. Die Zauberwörter waren "$GUI_EVENT_DROPPED" und "@GUI_DragFile". Die haben mir gefehlt :thumbup:

    Grüße
    Jonny