Jump to content

Implementing Windows Explorer right pane


LarsJ
 Share

Recommended Posts

Cancel drag/drop functionality

A drag operation in Windows Explorer right pane window based on IExplorerBrowser interface (virtual listview on Vista and later) can be identified by a 0x04CB message. In the Wine Wiki "List of Windows Messages" this message is described with the name IE_GETGESTURE. It's probably the message that's used to generate the drag image.

The drag operation can be canceled with this code:

; Cancel drag
Switch $iMsg
  Case $WM_MOUSEMOVE, $WM_TIMER, $WM_PAINT
    Return 0
  Case 0x04CB ; Send when drag/drop operation is initiated
    ControlSend( $hExplorerWin, "", $hExplorerLvWin, "{ESC}" ) ; Cancel drag
    Return 0
EndSwitch

In a right pane window based on a SysListView32 listview a drag operation can be identified by a LVN_BEGINDRAG notification.

A drop operation can be identified by WM_USER (0x0400) messages and a pressed primary mouse button. This applies to both a virtual and a SysListView32 listview.

The drop operation can be canceled with this code:

; Cancel drop
Switch $iMsg
  Case $WM_TIMER
    Return 0
  Case $WM_PAINT
    If $fWM_USER Then Return 0
  Case $WM_USER
    If $fWM_USER Then Return 0
    If Not BitAND( DllCall( $dllUser32, "short", "GetAsyncKeyState", "int", $iMouseBut )[0], 0x8000 ) Then Return 0
    MouseClick( "secondary" ) ; Cancel drop
    $fWM_USER = 1
    Return 0
  Case Else
    $fWM_USER = 0
EndSwitch

WM_USER is accompanied by WM_TIMER and WM_PAINT messages. Several WM_USER messages are generated. The drop operation should only be canceled once. This code works on XP and Vista and later.

A complete example for Vista and later is included in the zip. When I get time I'll add an example to each of the three implementations in first post, that shows how to cancel drag/drop.

Windows Explorer example.7z

Edited by LarsJ
Link to comment
Share on other sites

Thank you. I agree. It works surprisingly well. And it provides some more opportunities.

For example, you can add a drop area to your GUI. Since the drop function is canceled in the Explorer control, the user is forced to drop the files in the drop area. In this area you can get a list of full names of the files and implement validation e.g. file type and source folder, before the files are copied to the folder in the Explorer control. Files that do not meet the conditions are skipped. This could be an answer to your question about replacing the default drop function with your own function.

The drop function is canceled immediately after it is detected. If the function is detected very near the border of the Explorer control a possibility is to move the mouse just outside the Explorer control instead of canceling the entire drag/drop operation. That would be a little bit more user friendly, if the user is dragging files from one window to another and accidentally drag over the Explorer control. This gives him a chance to drag around the Explorer control.

The drag function in the Explorer control is canceled directly on initiation. Another possibility is to just set a flag that a drag operation is started. Only if the files are dragged outside the Explorer control, the drag operation is canceled. In that way you could allow drag/drop internally in the Explorer control, while dragging files to an external program, or dropping files from an external program is not allowed.

Since it's easy to detect initiation of a drag operation in the Explorer control, and it's easy to get a list of selected files and folders, it would also be easy to implement validation of a drag selection. E.g. a drag selection containing folders is not allowed and is canceled.

I'll definitely test some of these opportunities. If it works good, I'll probably add an example.

Your question turned out to be very interesting. Let me know if there are any issues.

Regards, Lars.

Link to comment
Share on other sites

  • 2 months later...

Wow... Amazing... Thank you for sharing!

Could someone help me, how to use this script like an embedded FileSelectFolder-func ? Means not to show files, only folders and return the clicked folderpath ...?

Best regards!

Thomas

Link to comment
Share on other sites

In this example the file filter is modified to exclude all files. And code is added to return the path when a folder is double clicked (or press Enter key) in the listview. Here the path is just shown in the label. Note that the default code on double click (to browse to the folder) is still executed.

The GUI looks like this:

Example_zpsbxdvkkmu.png

Windows Explorer example.7z

Regards, Lars.

Edited by LarsJ
Link to comment
Share on other sites

This is the same as the code in post 66, but the default code (to browse to the folder) is not executed when you double click or press Enter in the listview. This means that you have to do all the browsing in the treeview, and you can only select the folder in the listview.

Windows Explorer example.7z

Regards, Lars.

Edited by LarsJ
Link to comment
Share on other sites

  • 6 months later...

Hi LarsJ,

I've recently understood the pattern of a bad behaviour in W7 Explorer.  If I browse using the arrow keys in the treeview, when I expand a folder it scrolls the treeview so that folder is 2 lines above the bottom of the window. (Even if you were half-way up the treeview to start with.)  Now the sub-folders you want to see are off the bottom of the screen.  Sadly your explorer does this as well, presumably inherited from W7.  Is this something that you can change? (I hope).

best regards,

RichardL

 

Link to comment
Share on other sites

RichardL, I'm working on another project for the moment which has priority. When the project is finished in 2 - 3 weeks I'll look into this issue. I cannot promise you an answer before mid-March.

Link to comment
Share on other sites

  • 1 month later...

A little late. Sorry.

I'm seeing the same behaviour. But there is an easy workaround. Press left arrow to collapse the folder. Press right arrow to expand the folder. If there are many subfolders in the parent folder (I've been testing with Windows and System32 on C-drive), the parent folder will now be the topmost visible folder in the treeview.

The next time you expand the folder, you don't need the workaround. The folder will automatically be positioned as the topmost visible folder.

It seems as if Windows Explorer needs the number of subfolders to position the parent folder as the topmost folder in the treeview. The first time a folder is expanded the number is not known, and the parent folder is positioned 2 lines above the bottom of the treeview window. When the folder is expanded the number of subfolders is counted. The next time the same folder is expanded the number of subfolders is known and the parent folder can be positioned as the topmost folder.

I've tried to automate the workaround by sending left and right arrow key presses to the treeview control. And this works. The parent folder is now the topmost visible folder in the treeview. But the parent folder is not the selected folder anymore. The selected folder is important when you navigate the treeview with the keyboard. All navigation is relative to the selected folder. The selected folder must be set to the proper parent folder. Because the treeview is a normal TreeView32 control the folder can easily be selected with ControlTreeView "Select" command. But guess where the parent folder is positioned after this command: 2 lines above the bottom of the treeview window. This means that I've not found a way to automate the workaround.

Link to comment
Share on other sites

  • 7 years later...

I need to call the Windows dialog box for selecting multiple files and folders.
The problem is that standard functions don't allow for this, so I have to look for other tools.

In a thread I created, a kind person named Melba23 suggested a good working solution "UDF ChooseFileFolder", but I would like my version to work like the standard Windows file selection window.. That's why I turned my attention to this post.

In the "Context Menu" example, the "Selected" option can display selected files using "_ArrayDisplay". Most likely, using this feature, it is possible to create a "Select files/folders" button in the "4. Toolbar example" or "6. Cut-copy-paste" example that will produce a list of file names, similar to what "FileOpenDialog" or the "Select" option in the "Context Menu" example does.

Thank you in advance for your help.
If there is a simpler solution to this problem, I would greatly appreciate your advice here.

Link to comment
Share on other sites

"4. Toolbar example" is great as it displays icons to navigate through folders, like Windows Explorer do.

"5. Context menu" is also great as it adds 2 new menu items at the very end of the Windows Explorer context menu (one of them is the interesting "Display files and folders" as shown in the pic below)

I tried to combine both examples (Toolbar + Context menu) leading to this :

Lars-J-Toolbar-and-Context-Menu.png

The result is a list of folders / files names displayed in an ArrayDisplay window, as you already experimented. Let's wait for LarsJ to have his opinion about this (additional icon, combining both examples, maybe another alternative etc...) :)
Link to comment
Share on other sites

17 hours ago, pixelsearch said:

"4. Toolbar example" is great as it displays icons to navigate through folders, like Windows Explorer do.

I think it would be great to add a panel with a folder tree on the left and a working directory address bar on the top for more convenient navigation.😊
Like this:
AllPanes_zpstnpdi2jp.png

And Replacing the bottom pane with details and meta information with a panel that includes "open" and "cancel" buttons and allows filtering by file extension would be ideal.
image.png

I believe LarsJ has created a good tool that can be customized to resemble Windows Vista/7-style dialog boxes. However, I'm not sure if it's possible to implement a fully functional "openfiles" window similar to the fileopendialog in this case, but it would be really cool.😊

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...