Solved

How to simulate a windows explorer?

Posted on 2010-11-30
11
657 Views
Last Modified: 2012-05-10
Hi,

We would like extract video content from an editing tool using his existing drag&drop function. This Editing tool is able to export content (automatically converted in good format) if destination is a specific windows folder. You can do that with right-click and export menu (Save As …) or just with a Drag&Drop in on a windows folder.

To keep control on these exports in our workflow, we would like create a small “OnTop” application and allow user to drag&drop videocontent from Editing tool (external application) on this small application. But to trig the Editing tool (to fake an export to Windows folder), we have to simulate “Windows Explorer” container.

Any idea ?  
0
Comment
Question by:Dnx_7
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Accepted Solution

by:
ricovox earned 250 total points
ID: 34241680
Hi. What you want to do is provide an OLE Drop target. This will allow you to drag and drop files from your editing program (or any other program that is an OLE drop source provider, including windows explorer and many others).

You can do this very simply by setting the "AllowDrop" property of a System.Windows.Forms Control to true and then implementing event handlers for the Drag/Drop events.

Now, OLE drag/drop can be quite complicated, because programs can provide Data objects in many different formats--even custom, non-standard formats. So there is not a 100% guarantee you will be able to easily consume the Data objects provided by your editing program.

However, it is quite likely that your editing program does use one of the standard formats, such as "FileDrop", so you should be able to do what you want.

I have developed a small test application for you. You can use it do find out what formats can be dragged & dropped from your editing application. If it uses the standard "FileDrop" format, I have already even written the code necessary to automatically copy the exported files to a folder of your choice.

Here is a screenshot of the program in action:
Test Program Main Window
For convenience I have listed the content of the main form below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace OleDropTest {
	public partial class TestForm : Form {
		public TestForm() {
			InitializeComponent();
			grpDrop.AllowDrop = true;
		}

		private void grpDrop_DragEnter(object sender, DragEventArgs e) {
			StringBuilder info = new StringBuilder();
			e.Effect = e.AllowedEffect & DragDropEffects.Copy;

			string[] formats = e.Data.GetFormats(false);

			info.AppendFormat("Operations: {0}\r\n\r\nFormats:\r\n{1}", e.AllowedEffect, string.Join("\r\n", formats));

			if (Array.IndexOf(formats, DataFormats.FileDrop) != -1) {
				string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
				info.AppendFormat("\r\n\r\nFiles:\r\n{0}", string.Join("\r\n", fileNames));
			}

			txtInfo.Text = info.ToString();
		}

		private void grpDrop_DragDrop(object sender, DragEventArgs e) {
			//if the drop operation is complete, attempt to copy the files.
			try {
				string[] dropFilePaths = (string[])e.Data.GetData(DataFormats.FileDrop);

				e.Effect = DragDropEffects.None; //unless we change it below.

				//make sure the checkbox is checked and that the data contains files.
				if (!chkCopyFiles.Checked | dropFilePaths == null)
					return;

				string dstFolder = txtFolder.Text;
				if (!Directory.Exists(dstFolder)) {
					MessageBox.Show("The specified destination folder does not exist.");
					e.Effect = DragDropEffects.None;
					return;
				}

				//copy the files or folders
				CopyPathItems(dropFilePaths, dstFolder);
			} catch (Exception ex) {
				MessageBox.Show("Drop Error: " + ex.Message);
			}
		}

		static void CopyPathItems(string[] srcPaths, string dstFolder) {
			if (!Directory.Exists(dstFolder)) Directory.CreateDirectory(dstFolder);

			foreach (string srcPath in srcPaths) {
				string name = Path.GetFileName(srcPath);
				string newPath = Path.Combine(dstFolder, name);
				if (Directory.Exists(srcPath)) //srcPath is a folder. recursively copy all sub-items
					CopyPathItems(Directory.GetFileSystemEntries(srcPath), newPath);
				else //srcPath is a file
					File.Copy(srcPath, newPath);
			}
		}

	}
}

Open in new window



And you can download the full project for testing here:
OleDropTest.zip

Instructions for use:

Run the program and attempt to drag and drop from another application onto the designated drop area.

When you initially drag over the box, you will see information about the dragged data. This includes the allowable operations (such as Move, Copy, Link etc).

It will also list all of the available data formats that can be dropped.

If the available formats includes the "FileDrop" format, it also lists all available files and folders that can be dropped.

When you release the mouse button, the dragged data will be "dropped". If you have checked the "Copy Files To" box and you have specified a valid destination folder, then all available files will be copied into that folder.

If however, your application does NOT have the "FileDrop" format, there are still a number of other formats that can be used, including the "FileName" format. You will just need to post the list of available formats back here and I will take a look to see what we can do to move forward.

Good luck!
0
 
LVL 4

Expert Comment

by:ricovox
ID: 34241693
BTW, That project contains full C# source code in a VS2008 project.
If you cannot open or compile it, I can provide a download link for the executable for testing.
0
 
LVL 2

Author Comment

by:Dnx_7
ID: 34243023
Thank you Ricovox but this is a basic drag & drop implementation and of course as you said, it works with any files coming from external files but the problem is that the item dragging from the external program only react when we drop the item in the windows explorer that's why we have to create something like the windows explorer.

0
 
LVL 4

Expert Comment

by:ricovox
ID: 34243341
Hi Dnx,

Have you tested the program I sent?
It not only works with File drag & drop, but from applications also.

My application isn't just specific for file drag & drop. It is a general solution. This is how all OLE drag & drop works. So even if your editing application doesn't expose the files directly, you should still be able to use OLE techniques to get your export  to work. The process of exporting your editing data to Windows Explorer uses the same techniques

For example, you can open a zip file and drag items from the archive onto my program. Even though they are not actual files in the file system, they will still work because the archive program creates the files on-the-fly when the drop occurs. I have tested this with 7-zip and it works great.

I assume your editing application works the same. Once the drop operation occurs, it will write the file to a specified location and it will notify my program of that location.

It will also work with other types of data. You just have to know what the data object format is.

Can you please try the drag & drop from your editing application and list the output from my application here? It is important to see which operations are supported and to find the list of data formats that are supported.
Perhaps your editing program expects the "Move" operation instead of the "Copy" operation that my program uses.
0
 
LVL 4

Expert Comment

by:ricovox
ID: 34243352
Can you please tell me which editing program you use?
Is it something I can download to see the behavior your discussing?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:ricovox
ID: 34243531
As another example: You can drag an image from a webpage and drop it onto my application, and it will save the image file to the specified folder.
0
 
LVL 2

Author Comment

by:Dnx_7
ID: 34244049
Thank you for your help and explanation Ricovox
and yes, i tested your test project and it doesn't trigger like we drop onto the windows explorer.

it is an external application made for broadcast systems and i cannot send the application since it's very huge and need database/servers etc...

btw, to be simple, we need to create a window/control to act like the windows explorer because when we drop the item (from the extenal application) it reacts only when we drop into a windows explorer and nothing else...
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 34246489
Use this Shell Extensions Viewer to see if there is an extension installed by that software.

http://www.nirsoft.net/utils/shexview.html
0
 
LVL 2

Author Comment

by:Dnx_7
ID: 34246725
Hi, there is nothing installed in the windows shell
For example, i use a webbrowser and set the URL to "C:\" then it becomes a "windows explorer"
i dragged the item and it reacts as we want it to reacts
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34247131
Windows Explorer has a pluggable architecture. Developers can develop their own extensions for the explorer to handle stuff different. Drop targets is one class of those extensions. Did you try the viewer?
0
 
LVL 4

Expert Comment

by:ricovox
ID: 34249810
Hi Dnx_7

I understand what you are saying about trying to simulate a Windows Explorer folder window because your program recognizes that for the export. But what we need to figure out is exactly WHAT needs to be simulated. That is, we need to find out exactly how your program "knows" what the drop target is.

I assumed that your program is using OLE drag & drop, because that is a standard technology. If that is true, we should be able to figure out how to trick your application into thinking you are dropping on windows explorer.

However your application COULD be doing something completely NON-standard. For example, it is possible for your application to monitor what type of window is below the mouse cursor (by using APIs like WindowFromPoint, GetWindowInfo, GetClassName, etc) and it exports only when the window is the SysListView32 or SysTreeView32 type used in windows explorer.

But I HIGHLY doubt that is the case. OLE drag & drop is so easy for developers to implement, that I really don't think they would have done something non-standard like that in your external program.

Can you please answer the following questions, so I can think of some alternative methods we can use to test what your program is doing:

1)  When you did drag & drop onto my application from your editing program, did you see ANYTHING appear in the information textbox? (Such as the Operation and Formats list?)

2) What operating system are you using, and what CPU architecture (32 or 64 bit)?
Can you test out your program on a Windows 7 machine? I'm asking because some "Explorer Windows" in Windows 7 are NOT the standard explorer windows found in XP and 2000. So we can see if your program will still work with the new windows that do not have the same window classes as the old ones.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now