|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic Win32 Shell Routines keybd_event: Find All Files Dialog |
|
Posted: | Wednesday October 6, 1999 |
Updated: | Monday December 26, 2011 |
Applies to: | VB4-32, VB5, VB6 |
Developed with: | VB6, Windows NT4 |
OS restrictions: | None |
Author: | VBnet - Randy Birch |
Prerequisites |
None. |
|
Although
this topic has already been covered on other VBnet pages as part of larger API methods, it appears to remains popular enough to now
warrant its own entry.
There are three known ways to display the "Find: All Files" dialog using the API ... by calling keybd_event, by calling ShellExecute, or through the undocumented APIs for ordinal #90 (ordinal #91 will display the Find Computer dialog). This page deals only with the first two methods. The keybd_event method takes no parameters, and so opens the dialog at the last-used "Look in" path. By contrast, the ShellExecute method's lpFile member can be either a qualified drive letter, a qualified path, or vbNullString (which on my system always opens the dialog pointing to the first partition - aka drive C:). The drive or path passed as lpFile must end in a trailing slash. The keybd_event method always causes the dialog to appear; the ShellExecute method will only succeed if the path specified actually exists. Virtual folders (Desktop, My Computer) are not valid items for the lpFile parameter. (The undocumented APIs by contrast take pidl's as the two parameters in those calls, allowing the dialog to display the Find starting at virtual folders.) To date I have not found a way to either obtain the list of returned files, nor how to read a saved .fnd file format ... perhaps a project to contemplate over a cold dark winter. For now, adding this to a project is just one more way to provide added convenience for your users. |
BAS Module Code |
None. |
|
Form Code |
Toss two command buttons onto a form, along with a textbox. The frames shown are for clarity only. Add the following code to the form: |
|
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Const SW_SHOWDEFAULT As Long = 10 Private Const VK_ACTION = &H46 Private Const VK_LWIN = &H5B Private Const KEYEVENTF_KEYUP = &H2 Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function ShellExecute Lib "shell32" _ 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 Declare Sub keybd_event Lib "user32" _ (ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwFlags As Long, _ ByVal dwExtraInfo As Long) Private Sub Command1_Click(Index As Integer) Call keybd_event(VK_LWIN, 0, 0, 0) Call keybd_event(VK_ACTION, 0, 0, 0) Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0) End Sub Private Sub Command2_Click() Dim hWndDesk As Long Dim success As Long Dim sFile As String 'the start-in directory to search sFile = Text1.Text 'the desktop will be the 'default for error messages hWndDesk = GetDesktopWindow() 'do it success = ShellExecute(hWndDesk, "find", _ sFile, _ vbNullString, _ vbNullString, _ SW_SHOWNORMAL) End Sub |
Comments |
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |