none
Open File Explorer and change its size/location RRS feed

  • Question

  • Hello,

    I want to open 2 windows of file explorer in windows 7. One should be aligned to the left side (like winkey + Left arrow), the other one to the right side.

    Each window of file explorer should show different folder.

    I can open file explorer with Process.Start, but I cannot change its location and size.

    Is there a way how to do that?

    Thursday, June 4, 2015 10:32 AM

Answers

  • Explorer windows are managed by the Windows Shell so you can't use Process window handles with PInvoke to move the windows. However, you can use the Shell Document Viewer library (SHDocVw.dll). You will need to add a Reference to this COM component to your project. The description you want to look for is Microsoft Internet Controls.

        Sub MoveAllExplorerWindows()
    
            Dim ExplorerFileName As String
    
            For Each ExplorerWindow As SHDocVw.InternetExplorer In New SHDocVw.ShellWindows()
                ExplorerFileName = Path.GetFileNameWithoutExtension(ExplorerWindow.FullName).ToLower()
                If ExplorerFileName.ToLowerInvariant() = "explorer" Then
                    ExplorerWindow.Left = 0
                    ExplorerWindow.Top = 0
                    ExplorerWindow.Width = Screen.PrimaryScreen.WorkingArea.Width / 2
                    ExplorerWindow.Height = Screen.PrimaryScreen.WorkingArea.Height
                End If
            Next ExplorerWindow
    
        End Sub


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by jakub dusek Thursday, June 4, 2015 3:37 PM
    Thursday, June 4, 2015 3:16 PM

All replies

  • Hi,

    In advance, I apologize you. The below is *not* an answer.

    If your goal is not to write code by yourself,
    but is to get the feature as a result of writing code, "Q-Dir" is good.
    But "Q-Dir" can't satisfy the spec, i.e. it can't have different font size in different window.

    Anyway, "Q-Dir" would be a sample.  Please take a look.
    http://www.softwareok.com/?Freeware/Q-Dir

    Regards,

    Thursday, June 4, 2015 11:42 AM
  • See code in this thread OpenFileDialog position on screen for moving a window.

    It's probable using Process.Start that you can provide a path as an argument for Windows Explorer (don't know what File Explorer is) so it will launch displaying a specific path.

    https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.arguments(v=vs.110).aspx

    Process.Start Method (String, String)

    Windows Explorer Command-Line Options

    Command-Line Switches for Windows Explorer

    As far as resizing a window you can probably research for that using a search engine and searching for something like "pinvoke resize window vb.net" or "set external app size using pinvoke vb.net" or whatever.

    Although this looks good movewindow (user32) -

    ''' <summary>
         ''' The MoveWindow function changes the position and dimensions of the specified window. For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. For a child window, they are relative to the upper-left corner of the parent window's client area.
         ''' </summary>
         ''' <param name="hWnd">Handle to the window.</param>
         ''' <param name="X">Specifies the new position of the left side of the window.</param>
         ''' <param name="Y">Specifies the new position of the top of the window.</param>
         ''' <param name="nWidth">Specifies the new width of the window.</param>
         ''' <param name="nHeight">Specifies the new height of the window.</param>
         ''' <param name="bRepaint">Specifies whether the window is to be repainted. If this parameter is TRUE, the window receives a message. If the parameter is FALSE, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of moving a child window.</param>
         ''' <returns>If the function succeeds, the return value is nonzero.
         ''' <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para></returns>
         <DllImport("user32.dll")> _
         Public Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
         End Function

    __________________________________________________________________________

    Update: It is possible you will not be able to retrieve the window handle of Windows Explorer without launching instances of it using specific method. Since Explorer is always running and it spawns child windows I believe for display.


    La vida loca



    Thursday, June 4, 2015 2:50 PM
  • Explorer windows are managed by the Windows Shell so you can't use Process window handles with PInvoke to move the windows. However, you can use the Shell Document Viewer library (SHDocVw.dll). You will need to add a Reference to this COM component to your project. The description you want to look for is Microsoft Internet Controls.

        Sub MoveAllExplorerWindows()
    
            Dim ExplorerFileName As String
    
            For Each ExplorerWindow As SHDocVw.InternetExplorer In New SHDocVw.ShellWindows()
                ExplorerFileName = Path.GetFileNameWithoutExtension(ExplorerWindow.FullName).ToLower()
                If ExplorerFileName.ToLowerInvariant() = "explorer" Then
                    ExplorerWindow.Left = 0
                    ExplorerWindow.Top = 0
                    ExplorerWindow.Width = Screen.PrimaryScreen.WorkingArea.Width / 2
                    ExplorerWindow.Height = Screen.PrimaryScreen.WorkingArea.Height
                End If
            Next ExplorerWindow
    
        End Sub


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by jakub dusek Thursday, June 4, 2015 3:37 PM
    Thursday, June 4, 2015 3:16 PM
  • Thank you
    Thursday, June 4, 2015 3:37 PM
  • Explorer windows are managed by the Windows Shell so you can't use Process window handles with PInvoke to move the windows. However, you can use the Shell Document Viewer library (SHDocVw.dll). You will need to add a Reference to this COM component to your project. The description you want to look for is Microsoft Internet Controls.

        Sub MoveAllExplorerWindows()
    
            Dim ExplorerFileName As String
    
            For Each ExplorerWindow As SHDocVw.InternetExplorer In New SHDocVw.ShellWindows()
                ExplorerFileName = Path.GetFileNameWithoutExtension(ExplorerWindow.FullName).ToLower()
                If ExplorerFileName.ToLowerInvariant() = "explorer" Then
                    ExplorerWindow.Left = 0
                    ExplorerWindow.Top = 0
                    ExplorerWindow.Width = Screen.PrimaryScreen.WorkingArea.Width / 2
                    ExplorerWindow.Height = Screen.PrimaryScreen.WorkingArea.Height
                End If
            Next ExplorerWindow
    
        End Sub


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Using the below code you can move seperate instances of explorer. Even embed them in panels on a Form. However the method you provided is much simpler for what the OP desires obviously.

    Process.Start("explorer", "/seperate /root,C:\Users\John\Desktop")


    La vida loca


    Thursday, June 4, 2015 6:17 PM


  • Paul ~~~~ Microsoft MVP (Visual Basic)

    Using the below code you can move seperate instances of explorer. Even embed them in panels on a Form. However the method you provided is much simpler for what the OP desires obviously.

    Process.Start("explorer", "/seperate /root,C:\Users\John\Desktop")


    La vida loca


    Hello, could you please describe your solution?

    I am interested also in embedding file explorer in form.

    Thursday, June 4, 2015 8:11 PM
  • @Mr. Monkeyboy Take care to spell 'separate' correctly, though.
    • Edited by SP1R1TM4N Wednesday, March 28, 2018 12:13 PM Added @
    Wednesday, March 28, 2018 12:11 PM
  • This may be of help: http://bit.ly/2CX6QTE

    Saturday, September 15, 2018 8:56 PM