Hallo!
Hab in der Zwischenzeit mal einige Code-Ausschnitte zu einem Test-Programm zusammengefügt.
Was funktioniert: Ich bekomme ein Explorer-Fenster auf ein Panel in eigener Anwendung
Folgende ungelösten Probleme:
1. Darstellungsfehler meiner eigenen Form, der zwei Buttons und der Titelleiste des Explorer-Fensters.
2. Ordnungsgemäßes Schliessen der Form (werd ich warscheinlich mit SendMessage() und WM_Close machen)
3. Größenänderung meines Panels soll ExplorerWindow ebenfalls ändern
4. Die 3 Buttons des Explorer-Fensters deaktivieren oder ausblenden (Minimieren, Maximieren, Schliessen)
5. Steuern der Ansicht (Listenansicht) evtl. über SendKey??
6. Explorerfenster versteckt starten und versteckt wieder lösen, beim Schliessen meiner Form
Hier der Code: (einfache Form mit einem Panel und 2 Buttons)
ublic Class Form1
Public hWndEx As IntPtr
Public Class Win32Api
Public Const SW_MAXIMIZE As Int32 = 3
Public Const SW_HIDE As Int32 = 0
Public Const SW_SHOW As Int32 = 5
Public Const SW_MINIMIZE As Int32 = 6
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow _
As Integer) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal _
hWndNewParent As _
IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal _
lpWindowName As String) As Int32
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function FindWindowEx(ByVal hWnd1 As Int32, ByVal hWnd2 _
As _
Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
End Function
Public Shared Function FindExplorerWindow(ByVal Path As String) As _
IntPtr
Dim tempProcesses As Process()
tempProcesses = Process.GetProcesses()
For Each proc As Process In tempProcesses
If proc.ProcessName = "explorer" AndAlso proc.MainWindowTitle = _
Path Then Return (proc.MainWindowHandle)
Next
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim HandleFromPoint As IntPtr = Win32Api.FindWindows("C:\")
hWndEx = HandleFromPoint
Win32Api.SetParent(HandleFromPoint, Panel1.Handle)
''Fenster anzeigen.
Win32Api.ShowWindow(HandleFromPoint, Win32Api.SW_MAXIMIZE)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Explorer-Handle freigeben...
Win32Api.ShowWindow(hWndEx, Win32Api.SW_HIDE)
Win32Api.SetParent(hWndEx, IntPtr.Zero)
'Schliessen...
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Dim Prog As New ProcessStartInfo
Prog.Arguments = "/e,/select," & "C:\Temp"
Prog.FileName = "explorer.exe"
'Process starten
Dim hProcess As System.Diagnostics.Process = _
System.Diagnostics.Process.Start(Prog)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
'Explorer-Handle freigeben...
Win32Api.ShowWindow(hWndEx, Win32Api.SW_MINIMIZE)
'Win32Api.SetParent(hWndEx, IntPtr.Zero)
End Sub
End Class Kann evtl. jemand das nachvollziehen warum da Darstellungsfehler auftreten und wie man das besser lösen kann?
Schü
System: Windows 7_64 Ultimate, VB2008 Express Ed. SP1 |