Visual Basic > Forms
Display the 'Setup Prompt for Disk' dialog
Display the 'Setup Prompt for Disk' dialog Often it is useful during a setup to ask the user to locate a specific file. The following code displays a standard setup "find this file" dialog. Private Declare Function SetupPromptForDisk Lib "setupapi.dll" Alias "SetupPromptForDiskA" (ByVal hwndParent As Long, ByVal DialogTitle As String, ByVal DiskName As String, ByVal PathToSource As String, ByVal FileSought As String, ByVal TagFile As String, ByVal DiskPromptStyle As Long, ByVal PathBuffer As String, ByVal PathBufferSize As Long, ByRef PathRequiredSize As Long) As Long 'Available values for DiskPromptStyle Public Const IDF_CHECKFIRST = &H100 'Check for the file/disk before displaying the prompt dialog box, and, if present, return DPROMPT_SUCCESS immediately. Public Const IDF_NOBEEP = &H200 'Prevent the dialog box from beeping to get the user's attention when it first appears. Public Const IDF_NOBROWSE = &H1 'Do not display the browse option. Public Const IDF_NOCOMPRESSED = &H8 'Do not check for compressed versions of the source file. Public Const IDF_NODETAILS = &H4 'Do not display detail information. Public Const IDF_NOFOREGROUND = &H400 'Prevent the dialog box from becoming the foreground window. Public Const IDF_NOSKIP = &H2 'Do not display the skip option. Public Const IDF_OEMDISK = &H80000000 'Prompt for a disk supplied by a hardware manufacturer. Public Const IDF_WARNIFSKIP = &H800 'Warn the user that skipping a file may affect the installation. 'Purpose : Prompts the user to find a specific file. 'Inputs : sDiskName The name of the disk/application requesting the file. ' sFileName The file name to search for. ' [sTitle] The title of the dialog display ' [sDefaultPath] The initial path displayed by the dialog. If empty uses current path. ' [lDiskPromptStyle] One of the above Public IDF_ constants. 'Outputs : The path to the file or an empty string if the file wasn't located. Function SetupDiskPrompt(sFileName As String, Optional sDiskName As String, Optional sTitle As String = "Please insert disk...", Optional sDefaultPath As String, Optional lDiskPromptStyle As Long = IDF_WARNIFSKIP) As String Const clMaxPath As Long = 255 Dim sResult As String * 255, lLenResult As Long On Error Resume Next If Len(sDefaultPath) = 0 Then sDefaultPath = CurDir$ End If If SetupPromptForDisk(0&, sTitle, sDiskName, sDefaultPath, sFileName, vbNullString, lDiskPromptStyle, sResult, clMaxPath, lLenResult) = 0 Then SetupDiskPrompt = Left$(sResult, lLenResult - 1) If Right$(SetupDiskPrompt, 1) <> "\" Then SetupDiskPrompt = SetupDiskPrompt & "\" End If End If End Function 'Demonstration routine Sub Test() 'Find the file Autoexec.bat Debug.Print SetupDiskPrompt("Autoexec.bat") End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows