DirList Single Click


Author: Dave
Date: 07.08.16 - 2:27am



Its pretty rare than I use the VB6 dirlist control. It feels a bit old but it is easy to use. This morning I am creating a replacement for the Windows BrowseFolder dialog and using the default VB directory list control as part of it.

One behavior that I dont really care for in it is that it requires you to double click on a folder in order to select it. I find myself selecting the wrong directory on occasion because it looks selected in the control, yet it is not really the actively selected directory.

The question: is there an easy way to have the control auto select the folder you click on with a single click instead of a double click without subclassing?

Answer: yes its easy

Private Declare Sub mouse_event Lib "user32" ( _
						ByVal dwFlags As Long, _
						ByVal dX As Long, _
						ByVal dY As Long, _
						ByVal cButtons As Long, _
						ByVal dwExtraInfo As Long)
						
Private Const LEFTDOWN = &H2, LEFTUP = &H4
Private ignoreAutomation As Boolean

Private Sub Dir1_Click()
   
    If ignoreAutomation Then
        ignoreAutomation = False
    Else
        ignoreAutomation = True
        mouse_event LEFTDOWN, 0&, 0&, 0&, 0&
        mouse_event LEFTUP, 0&, 0&, 0&, 0&
        DoEvents
        mouse_event LEFTDOWN, 0&, 0&, 0&, 0&
        mouse_event LEFTUP, 0&, 0&, 0&, 0&
    End If
    
End Sub





Comments: (3)

On 08.21.16 - 12:20pm Aurel Cortez wrote:
This works but if there is a subdirectory underneath the main folder it highlights the that subdir but the content of the filelistbox is the that of the main folder.

On 08.22.16 - 6:47am Dave wrote:
Hi, thanks for the bug report. I did not notice this behavior. To fix this visual display bug I had to work a little winapi voodoo. The fix can be found at the following link:

https://github.com/dzzie/libs/blob/master/BrowseFolderReplacement/frmDlg.frm#L335

The bug was visible if you clicked on a sub directory that itself had many sub directories. If the list was long enough to still have an entry under the current mouse position (which does not move when the list compacts and re-expands), then whatever entry that was currently under the mouse would be visually highlighted in the control, even though that was not the one set in teh dir1.path property.

This control is a little low rent in its behavior but I think I ironed it out.

On 08.28.16 - 7:55am Aurel Cortez wrote:
I must say its a huge undertaking that involves WinAPI, PointAPI, Rect Structs for a very small feature. ) But it works great though. Thanks for the effort.

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 54 + 9 = ? followed by the letter: M 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 1 )
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 (22)
     VB6 CDECL
     UDT Tricks pt2
     Remote Data Extraction
     Collection Extender
     VB6 FindResource
     CDO.Message
     DirList Single Click
     Reset CheckPoint VPN Policy
     VB6 BSTR Oddities Explained
     SafeArrays in C
     BSTR and Variant in C++
     Property let optional args
     Misc Libs
     Enum Named Pipes
     Vb6 Collection in C++
     VB6 Overloaded Methods
     EXPORT FUNCDNAME Warning
     VB6 Syncronous Socket
     Simple IPC
     VB6 Auto Resize Form Elements
     Mach3 Automation
     Exit For in While
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )