Embedding a File Explorer Instance in a Windows Forms Application Form

Embedding a File Explorer instance in a Windows Forms application form

In order to handle renaming, deleting and make other customization you need to write your own file explorer. WebBrowser control is not suitable for your needs. It's just a wrapper over ActiveX component.

You should check this codeproject article. It contains an implementation of file explorer. There are few more samples of file browser:

one

two

Opening Windows Form app from .bat file places it behind Windows Explorer

You have few options:

Form.TopMost Property

Form.Activate Method

Or combination of those:

this.Show();
this.WindowState = FormWindowState.Normal;
this.BringToFront();
this.Activate();

opening Directories like in windows explorer on windows form?

There are a number of articles on codeproject.com showing how to create a Windows Explorer like UI using standard Winform controls. These look promising:

Windows Explorer in C#

A Windows Explorer in a user control

There are others though.

I'd start with one of these and modify to suit your needs.

How to set the Explorer window of a specific file as a child window of TopMost form?

This is the solution to it using FindWindowW e SetWindowPos Api.
It is showing Explorer folder on top of top most form.

   <DllImport("user32.dll", EntryPoint:="FindWindowW")>
Public Shared Function FindWindowW(<MarshalAs(UnmanagedType.LPTStr)> ByVal lpClassName As String, <MarshalAs(UnmanagedType.LPTStr)> ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")>
Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As Boolean
End Function
Shared ReadOnly HWND_TOPMOST As IntPtr = New IntPtr(-1)
Const SWP_NOSIZE As UInt32 = &H1
Const SWP_NOMOVE As UInt32 = &H2
Const SWP_SHOWWINDOW As UInt32 = &H40
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Dim inptr = FindWindowW("CabinetWClass", Nothing)
SetWindowPos(inptr, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End Sub

How to create an Explorer-like folder browser control?

Microsoft provides a walkthrough for creating a Windows Explorer style interface in C#.

There are also several examples on Code Project and other sites. Immediate examples are Explorer Tree, My Explorer, File Browser and Advanced File Explorer but there are others. Explorer Tree seems to look the best from the brief glance I took.

I used the search term windows explorer tree view C# in Google to find these links.

Display Different Windows Within a Panel in a Form (Windows Forms Application)

Rather than instantiate the controls for each application, hide them all, and just show the ones from the selected "application", consider this: design your main selector panel as a placeholder. When the user selects an application, assign the application panel instance in place of the selector panel instance and allow the application to execute to completion. After it exits, restore the placeholder instance.

Why can't I embed these Applications in my Form?

This code works for most applcations. I embedded the file explorer simply using a webbrowser control on my form and set its url to a file location. The internet explorer control magically turns into a file explorer then.

This is my final code, feel free to use this for you own projects.

IntPtr EmbedProcess(Control Panel, string Path)
{
string Name = NameFromPath(Path);

foreach (Process Task in Process.GetProcesses())
{
if (NameFromPath(Task.ProcessName).Contains(Name))
{
try { Task.Kill(); }
catch (Exception e) { }
}
}

try
{
Process Task = Process.Start(Path);
Task.WaitForInputIdle();
IntPtr Handle = new IntPtr();
for (int i = 0; Handle == IntPtr.Zero && i < 10; i++) { Handle = Task.MainWindowHandle; Thread.Sleep(100); }
SetParent(Handle, Panel.Handle);
SetWindowLong(Handle, GWL_STYLE, (int)(WS_VISIBLE + (WS_MAXIMIZE | WS_BORDER)));

MoveWindow(Handle, 0, 0, Panel.Width, Panel.Height, true);

Panel.Resize += new EventHandler(delegate(object sender, EventArgs e) { MoveWindow(Handle, 0, 0, Panel.Width, Panel.Height, true); });

this.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
{
SendMessage(Handle, 83, 0, 0);
Thread.Sleep(100);
Handle = IntPtr.Zero;
});

return Handle;
}
catch (Exception e) { MessageBox.Show(this, e.Message, "Error"); }
return new IntPtr();
}

I somebody is interested in the hole C# classes for embedding window processes and console processes into your form, check out this github repository.



Related Topics



Leave a reply



Submit