Four Different Methods to Display the Find Files Dialog

This article from Ovidiu Crisan shows four different methods of displaying the 'Find Files' dialog from within a Visual Basic Program.

screen-shot

If you want to use 'Find Files' standard dialog, in your programs you can choose between the following four methods.

  • Using DDE: it's needed an label control, even invisible.
  • Private Sub Command1_Click()
        With Label1
        .LinkTopic = "Folders|AppProperties"
        .LinkMode = vbLinkManual
        .LinkExecute "[OpenFindFile(,)]"
      End With
    End Sub
    
    Private Sub Form_Load()
      Label1.Visible = False
      Command1.Caption = "Find File (1)..."
      Me.Caption = "Find File (1)"
    End Sub
    
  • Using keybd_event API function to simulate Win + 'F':
  • Private Declare Sub keybd_event Lib "user32" _
        (ByVal bVk As Byte, _
        ByVal bScan As Byte, _
        ByVal dwFlags As Long, _
        ByVal dwExtraInfo As Long)
    '
    Private Const VK_LWIN = &H5B
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_APPS = &H5D
    '
    Private Sub Command1_Click()
        Call keybd_event(VK_LWIN, 0, 0, 0)
        Call keybd_event(&H46, 0, 0, 0)       'F
        Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
    End Sub
    '
    Private Sub Form_Load()
      Command1.Caption = "Find File (2)..."
      Me.Caption = "Find File (2)"
    End Sub
    
  • Using MS Q183903 (http://support.microsoft.com/support/kb/articles/q183/9/03.asp)
  • Private Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hwnd As Long, _ 
         ByVal lpOperation As String, _
         ByVal lpFile As String, _
         ByVal lpParameters As String, _
         ByVal lpDirectory As String, _
         ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_SHOWMINIMIZED = 2
    Private Const SW_SHOWMAXIMIZED = 3
    Private Const SW_SHOW = 5
    Private Const SW_MINIMIZE = 6
    Private Const SW_SHOWMINNOACTIVE = 7
    Private Const SW_SHOWNA = 8
    Private Const SW_RESTORE = 9
    Private Const SW_SHOWDEFAULT = 10
    
    Private Sub Command1_Click()
       Call ShellExecute(Me.hwnd, _
          "find", _
          Dir1.Path, _
          vbNullString, _
          vbNullString, _
          SW_SHOWNORMAL)
    End Sub
    
    Private Sub Drive1_Change()
       Dir1.Path = Drive1.Drive
    End Sub
    
    Private Sub Form_Load()
       Command1.Caption = "Find File (3)..."
    End Sub
    
  • Using undocumented function SHFindFiles and SHSimpleIDListFromPath from Shell32.dll:
  • Private Declare Function SHFindFiles Lib "Shell32" _
        Alias "#90" _
        (pidlRoot As Long, pidlSavedSearch As Long) As Long
    Private Declare Function SHSimpleIDListFromPath Lib _
        "Shell32" Alias "#162" _
        (ByVal lpszPath As String) As Long
    '
    Private Sub Command1_Click()
      Dim l As Long
      l = SHSimpleIDListFromPath(Dir1.Path)
      SHFindFiles ByVal l, ByVal 0
    End Sub
    
    Private Sub Drive1_Change()
      Dir1.Path = Drive1.Drive
    End Sub
    
    Private Sub Form_Load()
      Command1.Caption = "Find File (4)..."
      Me.Caption = "Find File (4)"
    End Sub
    

For the last two methods you need to add a DriveListBox and a DirListBox
control. With this methods you can give the start path for searching.

Download Zipped Project File (12k)



Comments

  • ok

    Posted by Legacy on 10/17/2001 12:00am

    Originally posted by: sabirmajor

    good for other like goog for yourselves
    thanks

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds