Ejecutar Explorador de Windows dentro de Winforms
Publicado por haf (178 intervenciones) el 27/07/2010 13:45:23
Amigos del Foro, Necesito ejecutar el explorer.exe (explorador de Windows) pero que este se ejecute dentro de una ventana o un panel de mi formulario, y no he logrado hacerlo.
Para llamar al explorer.exe utilizo este código:
dim directorio as string ="c:\documentos"
If Directory.Exists(Directorio) Then
Try
Process.Start("explorer.exe", "/n,/e," + Directorio)
Catch ex As Exception
MessageBox.Show("Error al abrir el explorador de windows", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Ahora bien: Para ejecutar un programa dentro de un panel he encontrado el código que detallo a continuación (funciona perfectamente para el Notepad.exe pero cuando le cambio el notepad.exe por el explorer.exe me abre el explorado normalmente y fuera del panel ¿me pueden ayudar ?
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Private Const SWP_NOSIZE As Integer = &H1
Dim p As Process = Process.Start("notepad.exe")
Thread.Sleep(600)
' Allow the process to open it's window
SetParent(p.MainWindowHandle, Panel1.Handle)
Para llamar al explorer.exe utilizo este código:
dim directorio as string ="c:\documentos"
If Directory.Exists(Directorio) Then
Try
Process.Start("explorer.exe", "/n,/e," + Directorio)
Catch ex As Exception
MessageBox.Show("Error al abrir el explorador de windows", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Ahora bien: Para ejecutar un programa dentro de un panel he encontrado el código que detallo a continuación (funciona perfectamente para el Notepad.exe pero cuando le cambio el notepad.exe por el explorer.exe me abre el explorado normalmente y fuera del panel ¿me pueden ayudar ?
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Private Const SWP_NOSIZE As Integer = &H1
Dim p As Process = Process.Start("notepad.exe")
Thread.Sleep(600)
' Allow the process to open it's window
SetParent(p.MainWindowHandle, Panel1.Handle)
Valora esta pregunta


0