Announcement

Collapse
No announcement yet.

How to Drag and Drop file to AMS app and get the file name?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Drag and Drop file to AMS app and get the file name?

    How to Drag and Drop file to AMS app and get the file name?
    I saw this DLL but he requires .Net and I do not want it to be depending on .Net
    Any ideas how to do this?

  • #2
    DragDrop.zip

    I dont know if this is the same dll or not but it works just fine, search the forum for determining if something is in a rectangle to create a drop zone (cant find it but its by worm I think).

    Comment


    • #3
      If it wont work it should be possible to use MemoryEx to make the main window or any object windows drag/drop complaint without dependencies.

      Comment


      • #4
        how can i use MemoryEx?

        how can i use MemoryEx?

        Comment


        • #5
          Its basically loading up the various windows dll's then using the functions, I think you just set a window style to WS_EX_ACCEPTFILES using the SetWindowLong function then subclassin the window to capture the events, more than likely you'll capture a message that will give you a pointer to a structure with the details of the file or files dropped but I haven't looked through the Microsoft site to see the notifications.

          Comment


          • #6
            Thank you very much for your help but I still do not understand and I would love for your help.

            Comment


            • #7
              It seems you just set the Extended Window Style then intercept the WM_DROPFILES message that will give you access to DragFinish, DragQueryFile, or DragQueryPoint to retrieve information about the dropped files.

              I dont mind helping you but where are you trying to drop files to and is the app you have to be run as administrator?

              Comment


              • #8
                I'm sorry I still do not understand and I must get your help. I do not want And do not need the program to run as administrator. It is really surprising that AMS in so advanced version does not support herself on drag files.

                Comment


                • #9
                  I'll post you an example shortly but it seems there is something going on with AMS as when you set the main window for drag/drop and attempt to drop a file it throws "Failed to get archive directory listing" so some related code is likely there.

                  Comment


                  • #10
                    O.K. Where can i set the main window for drag/drop in AMS???

                    Comment


                    • #11
                      Create a blank project and use this code, alter the DragDrop.OnDrop function to suite your needs.

                      Code:
                      -- GLOBAL FUNCTIONS
                      
                      
                      --[[
                      
                      Drag & Drop [MemoryEx] v1.0
                      
                      Refrences:
                      
                       WS_EX_ACCEPTFILES http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543%28v=vs.85%29.aspx
                       WM_DROPFILES      http://msdn.microsoft.com/en-us/library/windows/desktop/bb774303%28v=vs.85%29.aspx
                       DragFinish        http://msdn.microsoft.com/en-us/library/windows/desktop/bb776407%28v=vs.85%29.aspx
                       DragQueryFile     http://msdn.microsoft.com/en-us/library/windows/desktop/bb776408%28v=vs.85%29.aspx
                       DragQueryPoint    http://msdn.microsoft.com/en-us/library/windows/desktop/bb776409%28v=vs.85%29.aspx
                       SetWindowLong     http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx
                       GetWindowLong     http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584%28v=vs.85%29.aspx
                      
                      MemoryEx plugin is required:
                      
                       http://www.memoryex.net
                      
                      Notes:
                      
                       This is for Windows XP and above.
                      
                       Example shows the main window being used for Drag & Drop but any windowed object that a handle can be got could be used.
                      
                       Drag & Drop won't function when the application is run as an administrator on Windows Vista and above because in the
                       traditional NT Security model (prior to Vista), all processes on the same desktop ran with the same security token
                       and had all the same privileges, UAC changed this by allowing processes with different privilege levels on the same
                       desktop, basically the WS_EX_ACCEPTFILES message is blocked. This can likley be overcome with this:
                        http://msdn.microsoft.com/en-us/library/windows/desktop/dd388202%28v=vs.85%29.aspx
                      
                      To Do:
                      
                       An internal window border appears when Drag & Drop is enabled, needs to be removed when Drag & Drop is disabled.
                      
                      --]]
                      
                      
                      --Load Library's
                      User32Library = Library.Load("user32.dll");
                      Gdi32Library = Library.Load("Gdi32.dll");
                      Shell32Library = Library.Load("Shell32.dll");
                      
                      
                      --Set Structures
                      LONG = INT;
                      POINT  = MemoryEx.DefineStruct{
                        LONG "x";
                        LONG "y";
                      }
                      
                      
                      --Button Functions
                      AButton = {}
                      AButton.OnClick = function(bhdl)
                       if bhdl == _BONE then
                        local x, y = DragDrop.Enable(true)
                        Dialog.Message("Drag & Drop",y)
                       elseif bhdl == _BTWO then
                        local x, y = DragDrop.Enable(false)
                        Dialog.Message("Drag & Drop",y)
                       end
                      end;
                      AButton.CreateFont = function()
                       local OSnamea = System.GetOSName()
                       if OSnamea == "Windows XP" or OSnamea == "Windows Server 2003" then
                        DEFFONT = "Tahoma"
                       else
                        DEFFONT = "Segoe UI"
                       end
                       local FW_REGULAR = 400;
                       local ANSI_CHARSET = 0;
                       local OUT_DEFAULT_PRECIS = 0;
                       local CLIP_DEFAULT_PRECIS = 0;
                       local ANTIALIASED_QUALITY = 4;
                       local DEFAULT_PITCH = 0;
                       local hFont = Gdi32Library.CreateFontA(14,0,0,0,FW_REGULAR,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH,DEFFONT)
                       if hFont and (type(hFont) ~= "number") then
                        return false
                       else
                        return hFont
                       end
                      end;
                      AButton.CreateButton = function(x,y,w,h,hWnd,txt)
                        if not AButton.Font then
                         AButton.Font = AButton.CreateFont()
                        end
                        local BS_PUSHBUTTON = 0x00000000;
                        local WS_CHILD = 0x40000000;
                        local WS_VISIBLE = 0x10000000;
                        local BS_VCENTER = 0x00000C00;
                        local BS_CENTER = 0x00000300;
                        local nstyle = BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + BS_VCENTER + BS_CENTER
                        local bhdl = User32Library.CreateWindowExA(0,"BUTTON","",nstyle,x,y,w,h,hWnd,0,0,0)
                        if bhdl and (type(bhdl) ~= "number") then
                         return false
                        end
                        User32Library.BringWindowToTop(bhdl)
                        User32Library.SendMessageA(bhdl,0x0030,AButton.Font,1)
                        User32Library.SendMessageA(bhdl,0x000C,0,txt)
                        return bhdl
                      end;
                      
                      
                      --Drag Drop Functions
                      DragDrop = {}
                      DragDrop.Enabled = false;
                      DragDrop.Enable = function(bState)
                       if not bState then
                        if not DragDrop.Enabled then
                         return false, "Drag & Drop already disabled"
                        else
                         local whd = Application.GetWndHandle()
                         local x = User32Library.GetWindowLongA(whd,-20,0x00000010)
                         if x == 0 then
                          return false, "Can't disable Drag & Drop (A)"
                         else
                          if User32Library.SetWindowLongA(whd,-20,x - 0x00000010) > 0 then
                           DragDrop.Enabled = false
                           return true, "Drag & Drop disabled"
                          else
                           return false, "Can't disable Drag & Drop (B)"
                          end
                         end
                        end
                       else
                        if DragDrop.Enabled then
                         return false, "Drag & Drop already enabled"
                        else
                         local whd = Application.GetWndHandle();
                         if User32Library.SetWindowLongA(whd,-20,0x00000010) > 0 then
                          DragDrop.Enabled = true
                          return true, "Drag & Drop enabled"
                         else
                          return false, "Can't enable Drag & Drop"
                         end
                        end
                       end
                      end;
                      DragDrop.OnDrop = function(hDrop)
                       local x, dp = DragDrop.GetDropPoint(hDrop)
                       if x then
                        -- dp is a table containing the coordinates of the drop point.
                        -- 'return' here if you need to filter out areas of the window.
                        -- Dialog.Message("Drop Point","X pos: "..dp.x .."\nY pos: "..dp.y)
                       end
                       local tf = DragDrop.GetCount(hDrop)
                       if tf > 1 then
                        --Return here if you dont want multiple files.
                        --return
                       end
                       local t ={}
                       for i = 0, tf -1 do
                        local x = DragDrop.GetFile(hDrop,i)
                        table.insert(t,x)
                       end
                       -- You now have a numerically indexed table with the file paths.
                       Dialog.Message("Files Droped: "..#t,table.concat(t,"\n"))
                      end;
                      DragDrop.GetCount = function(hDrop)
                       return Shell32Library.DragQueryFileA(hDrop,-1,0,0)
                      end;
                      DragDrop.GetFile = function(hDrop,index)
                       local B = MemoryEx.Allocate(260)
                       if not B then return false end
                       local x = Shell32Library.DragQueryFileA(hDrop,index,B,260)
                       if x == 0 then
                        MemoryEx.Free(B)
                        return "Error"
                       else
                        local t = MemoryEx.String(B,-1,MEMEX_ASCII)
                        MemoryEx.Free(B)
                        return t
                       end
                      end;
                      DragDrop.GetDropPoint = function(hDrop)
                       local dpB = MemoryEx.Allocate(MemoryEx.StructSize(POINT) + 100)
                       if not dpB then
                        return false, "Can't create buffer"
                       end
                       local dpS = MemoryEx.AssignStruct(dpB + 50,POINT)
                       if not dpS then
                        MemoryEx.Free(dpB)
                        return false, "Can't create structure"
                       end
                       if Shell32Library.DragQueryPoint(hDrop,dpS:GetPointer()) == 0 then
                        dpS:Close()
                        MemoryEx.Free(dpB)
                        return false, "Can't get drop point"
                       else
                        local t = {}
                        t.x = dpS.x
                        t.y = dpS.y
                        dpS:Close()
                        MemoryEx.Free(dpB)
                        return true, t
                       end
                      end;
                      
                      
                      -- ON SHOW
                      
                      --Create Buttons
                      _BONE = AButton.CreateButton(10,5,90,23,Application.GetWndHandle(),"Enable")
                      _BTWO = AButton.CreateButton(10,35,90,23,Application.GetWndHandle(),"Disable")
                      
                      --Set Subclass
                      local s = Subclass.Create(Application.GetWndHandle(), function(hWnd,uMsg,wParam,lParam)
                      
                       -- Remove subclass on exit
                       if(uMsg == 0x0002)then --WM_DESTROY
                        Subclass.Remove(Application.GetWndHandle());
                        return 0
                       end
                      
                       -- Retrieve button on click events
                       if(uMsg == 0x0111)then --WM_COMMAND
                        if (lParam == _BONE) then
                         local wmEvent = Bitwise.And(wParam,0xFFF0);
                         if (wmEvent == 0) then --BN_CLICKED
                          AButton.OnClick(_BONE);
                          return 0;
                         end
                        end
                        if (lParam == _BTWO) then
                         local wmEvent = Bitwise.And(wParam,0xFFF0);
                         if (wmEvent == 0) then
                          AButton.OnClick(_BTWO);
                          return 0;
                         end
                        end
                       end
                      
                       -- Drag & Drop events
                       if(uMsg == 0x0233)then  --WM_DROPFILES
                        DragDrop.OnDrop(wParam)
                        return 0
                       end
                      
                       return Subclass.OldWinProc(hWnd, uMsg, wParam, lParam);
                      end)

                      Comment


                      • #12
                        First off all Wow and thank you.

                        I get an error line 42.

                        It seems really complicated and I really do not understand anything from the code. It's okay if I ask a code inside the AMS file? Please Please!!!

                        Comment


                        • #13
                          You have to install the MemoryEx plugin first, even if I posted an app you would still need to do this. Just download the plugin then install it and open a blank project and go to Project > Plugins and check MemoryEx then paste the global code on Global Functions and the on show code On Show.

                          Comment


                          • #14
                            Thank you! I did everything and now I have no error message. Just last question

                            you wrote to me to alter the DragDrop.OnDrop function, How do I do this Each time the i drag and drop file on my app??? If I receive a message which has the path of the dragged file It would be just what I need and I could get away from there.

                            Comment


                            • #15
                              For some odd reason I thought I could not export with the personal addition so Ill post an app in a new thread.

                              Look at the DragDrop.OnDrop function and you'll notice that it calls a Dialog.Message telling you each time you get files dropped so all you do is instead of a dialog just have whatever notification you want as all the files are is a table so you just manipulate it to suit yourself.

                              Comment

                              Working...
                              X