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: 3 + 76 = ? followed by the letter: F 



About Me
More Blogs
Main Site
Posts: (year)
2024 (1)
     RegJump Vb
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     py4vb
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 (2)
     Obscure VB
     VB6 IDE SP6
2020 (4)
     NTFileSize
     BSTR from C Dll to VB
     Cpp Memory Manipulation
     ActiveX Binary Compatability
2019 (5)
     Console tricks
     FireFox temp dir
     OCX License
     Extract substring
     VB6 Console Apps
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
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)
     C# self register ocx
     VB6 Class Method Pointers
     Duktape Debug Protocol
     QtScript 4 VB
     Vb6 Named Args
     vb6 Addin Part 2
     VB6 Addin vrs Toolbars
     OpenFile Dialog MultiSelect
     Duktape Example
     DukTape JS
     VB6 Unsigned
     .Net version
     TitleBar Height
     .NET again
     VB6 Self Register OCXs
2014 (25)
     Query Last 12 Mos
     Progid from Interface ID
     VB6 to C Array Examples
     Human Readable Variant Type
     ScriptBasic COM Integration
     CodeView Addin
     ScriptBasic - Part 2
     Script Env
     MSCOMCTL Win7 Error
     printf override
     History Combo
     Disable IE
     API Hooking in VB6
     Addin Hook Events
     FastBuild Addin
     VB6 MemoryWindow
     Link C Obj Files into VB6
     Vb6 Standard Dlls
     CStr for Pascal
     Lazarus Review
     asprintf for VS
     VB6 GlobalMultiUse
     Scintilla in VB6
     Dynamic Highlight
     WinVerifyTrust, CryptMsgGetParam VB6
2013 (4)
     MS GLEE Graphing
     printf for VB6
     C# App Config
     Tero DES C# Test
2012 (10)
     VC 2008 Bit Fields
     Speed trap
     C# Db Class Generator
     VB6 vrs .NET (again)
     FireFox Whois Extension
     git and vb6
     Code Additions
     Compiled date to string
     C# ListView Sorter
     VB6 Wish List
2011 (7)
     C# Process Injection
     CAPTCHA Bots
     C# PE Offset Calculator
     VB6 Async Download
     Show Desktop
     coding philosophy
     Code release
2010 (11)
     Dll Not Found in IDE
     Advanced MSScript Control
     random tip
     Clipart / Vector Art
     VB6 Callback from C#
     Binary data from VB6 to C#
     CSharp and MsScriptControl
     HexDumper functions
     Js Beautify From VB6 or C#
     vb6 FormPos
     Inline Asm w VB6
2009 (3)
     The .NET Fiasco
     One rub on computers
     Universal extractor