Exemple #1
0
        private void HandleDragDropMessage(Message m)
        {
            var  sb       = new StringBuilder(260);
            uint numFiles = DragQueryFile(m.WParam, 0xffffffffu, sb, 0);
            var  list     = new List <string>();

            for (uint i = 0; i <= numFiles - 1; i++)
            {
                if (DragQueryFile(m.WParam, i, sb, Convert.ToUInt32(sb.Capacity) * 2) > 0)
                {
                    list.Add(sb.ToString());
                }
            }

            POINT p = default(POINT);

            DragQueryPoint(m.WParam, ref p);
            DragFinish(m.WParam);

            var args = new ElevatedDragDropArgs();

            args.HWnd  = m.HWnd;
            args.Files = list;
            args.X     = p.X;
            args.Y     = p.Y;

            if (ElevatedDragDrop != null)
            {
                ElevatedDragDrop(this, args);
            }
        }
Exemple #2
0
        private void panelDropFile_ElevatedDragDropHandler(object sender, ElevatedDragDropArgs e)
        {
            if (e.Files == null || e.Files.Count < 1) return;

            var path = e.Files[0];

            if (!File.Exists(path))
            {
                Console.WriteLine("not exist");
                return;
            }

            if (IsDirectory(path))
            {
                Console.WriteLine("Is Directory");
                return;
            }

            string resultPath = null;

            if (Path.GetExtension(path).Equals(".exe", StringComparison.CurrentCultureIgnoreCase)
                || Path.GetExtension(path).Equals(".msc", StringComparison.CurrentCultureIgnoreCase))
            {
                resultPath = path;
            }
            else if (Path.GetExtension(path).Equals(".lnk", StringComparison.CurrentCultureIgnoreCase))
            {
                string target;

                //Console.WriteLine("first Try");
                target = GetLnkTargetSimple(path);
                /*Console.WriteLine(target);
                if (target.Equals(""))
                {
                    try
                    {
                        Console.WriteLine("Second Try");
                        target = GetLnkTarget(path);
                    }
                    catch (Exception)
                    {
                        target = "";
                    }

                }*/

                if (!File.Exists(target))
                {
                    Console.WriteLine("target not exists");
                    return;
                }

                if (IsDirectory(target))
                {
                    Console.WriteLine("target is a directory");
                    return;
                }

                if (!Path.GetExtension(target).Equals(".exe", StringComparison.CurrentCultureIgnoreCase)
                    && !Path.GetExtension(target).Equals(".msc", StringComparison.CurrentCultureIgnoreCase))
                {
                    Console.WriteLine("wrong format");
                    return;
                }

                resultPath = target;
            }
            else
            {
                Console.WriteLine("wrong format");
                return;
            }

            HandleSelectedApp(resultPath, Path.GetFileNameWithoutExtension(path));
        }
Exemple #3
0
        private void panelDropFile_ElevatedDragDropHandler(object sender, ElevatedDragDropArgs e)
        {
            if (e.Files == null || e.Files.Count < 1)
            {
                return;
            }

            var path = e.Files[0];

            if (!File.Exists(path))
            {
                Console.WriteLine("not exist");
                return;
            }

            if (IsDirectory(path))
            {
                Console.WriteLine("Is Directory");
                return;
            }

            string resultPath = null;

            if (Path.GetExtension(path).Equals(".exe", StringComparison.CurrentCultureIgnoreCase) ||
                Path.GetExtension(path).Equals(".msc", StringComparison.CurrentCultureIgnoreCase))
            {
                resultPath = path;
            }
            else if (Path.GetExtension(path).Equals(".lnk", StringComparison.CurrentCultureIgnoreCase))
            {
                string target;

                //Console.WriteLine("first Try");
                target = GetLnkTargetSimple(path);

                /*Console.WriteLine(target);
                 * if (target.Equals(""))
                 * {
                 *  try
                 *  {
                 *      Console.WriteLine("Second Try");
                 *      target = GetLnkTarget(path);
                 *  }
                 *  catch (Exception)
                 *  {
                 *      target = "";
                 *  }
                 *
                 * }*/

                if (!File.Exists(target))
                {
                    Console.WriteLine("target not exists");
                    return;
                }

                if (IsDirectory(target))
                {
                    Console.WriteLine("target is a directory");
                    return;
                }

                if (!Path.GetExtension(target).Equals(".exe", StringComparison.CurrentCultureIgnoreCase) &&
                    !Path.GetExtension(target).Equals(".msc", StringComparison.CurrentCultureIgnoreCase))
                {
                    Console.WriteLine("wrong format");
                    return;
                }

                resultPath = target;
            }
            else
            {
                Console.WriteLine("wrong format");
                return;
            }

            HandleSelectedApp(resultPath, Path.GetFileNameWithoutExtension(path));
        }
        private void HandleDragDropMessage(Message m)
        {
            var sb = new StringBuilder(260);
            uint numFiles = DragQueryFile(m.WParam, 0xffffffffu, sb, 0);
            var list = new List<string>();

            for (uint i = 0; i <= numFiles - 1; i++)
            {
                if (DragQueryFile(m.WParam, i, sb, Convert.ToUInt32(sb.Capacity) * 2) > 0)
                {
                    list.Add(sb.ToString());
                }
            }

            POINT p = default(POINT);
            DragQueryPoint(m.WParam, ref p);
            DragFinish(m.WParam);

            var args = new ElevatedDragDropArgs();
            args.HWnd = m.HWnd;
            args.Files = list;
            args.X = p.X;
            args.Y = p.Y;

            if (ElevatedDragDrop != null)
            {
                ElevatedDragDrop(this, args);
            }
        }