VB == Quick call system dialog (all)

zhaozj2021-02-08  227

(Author: Gan Jiping, 2000 at 17:46 on December 21)

The Windows system gives us a lot of very useful features, and is in the form of a dialog box, such as: finding files, browsing the selection, execute the program, etc. ... If we can simply in the program The code quickly calls them, you can get the need for the purpose of the flowers. In this way, the process of removing the cumbersome code again, but also allows the program to perform quickly (call the system kernel module, can you not be ^ _ ^). The following examples list the following examples: ● Quick call "Find file dialog" ● Quick call "System Restart dialog" ● Quick call "Program Run Dialog" ● Quick call "File Properties dialog" ● Quick call " Soft Disk Format dialog box "● Quick call" Network Resource Mapping Dialog "● Quick Call" Find File Dialog "Quick Call" Find File Dialog box "In the Windows environment, if you want to find a file, the steps are usually taken Yes: 1. Determine the folder range in which the lookup file is located, press the hotkey F3 3, in the "Find: All File" window, enter each item. Is it a bit complicated. In the VB program, can you display a "Find: All Files" in step 3 by clicking a button? The answer is yes! Code is as follows: 'Declare API function 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 'defines a constant parameter Const SW_SHOW = 5' generic function calls Find dialog Public Sub ShowFindDialog (Optional InitialDirectory As String) ShellExecute 0, "find", _ IIf (InitialDirectory = "", "", InitialDirectory ), _ Vbnullstring, sw_show end sub calls the search dialog routine Call showfinddialog ("C: / Program Files") called code showfinddialog ("c: / program files"), very concise. Note: If the parameters in parentheses are not a legitimate directory name, this line call command will not produce any results. If the parameter is empty, it is equal to the current directory. Quick call "System Restart Dialog" We often encounter the installation of the installation when installing the application, when the user will restart the machine's confirmation dialog, then the system will restart according to the user's selection, or temporarily exit installation, wait for the user Manually restart the machine.

In fact, in our application, you can use very little code to call the restart dialog box of the system itself, it is really very fast! Code: 'Declare API functions Private Declare Function SHRestartSystemMB Lib _ "shell32" Alias ​​"# 59" (ByVal hOwner As Long, ByVal _ sExtraPrompt As String, ByVal uFlags As Long) As Long' defines a system reboot constant parameter Private Const SystemChangeRestart = 4 'universal system startup Public Sub SettingsChanged (FormName As Form) SHRestartSystemMB FormName.hWnd, vbNullString, SystemChangeRestart End Sub' calling routine SettingsChanged Form1 to run to see if the actual renderings: direct use of the system of internal functions, to save themselves Go to draw a form, not only the functions of implementation can be very rigorous, but also very professional! Quick call "Program Run Dialog" in general, when we need to call an external .exe or .com program in the VB program, usually use the shell command. It provides a very simple way to let us perform a determined external program. But the disadvantage is also displayed, that is, it does not provide the user to select the function of executing the program. You may remember this experience: We click the "Start" of the left small corner of the desktop. When you select "Run", then a "Run" dialog box appears: You can directly enter the program you want to execute directly. Path, or, click the "Browse" button to select a program.

To achieve the same effect, use the following code: 'Declaration API function' reference Unprecedented DLL file shell32 private declare function shrundialog lib "shell32" _ alias "# 61" (Byval Howner As Long, BYVAL UNKNOWNP1 _ As Long Byval Sztitle _ as string, byval szprompt as string, byval uflags _ as long) AS long 'general call Run dialog process' Parameter Title represents the title of the dialog, parameter description Representation Dialog public Sub ShowRunDialog (ByRef CallingForm As Form, _ Optional Title As String, _ Optional Description As String) If Title = "" Then Title = "Run" If Description = "" Then Description = _ "Type the name of a program to open , "& _" Then Click Ok When Finished. "Shrundialog Callingform.hWnd, 0, 0, _ Title, Description, 0 end 'call routine CALL Showrundialog (ME," Run Dialog "," Choose a Program and Press OK " How is it, is it finished? Execute a look, is it very satisfied: Quick call "File Properties dialog" to view the size of a file, create time, access properties (read-only, archive, hide), etc., the steps taken are generally: 1, positioning file 2, right-click File 3, select "Properties" in the menu that appears, the file properties dialog appears. For example, after implementing the above operations for C: /autoexec.bat, the illustration is shown below: At this time, we can modify its various attribute values.

In VB development in order to achieve the above functions, to be applied to ShellExecuteEX function, as follows: 'Declare structural variables Private Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As Long End Type 'defines a constant parameter Const SEE_MASK_INVOKEIDLIST = & HC Const SEE_MASK_NOCLOSEPROCESS = & H40 Const SEE_MASK_FLAG_NO_UI = & H400' cited API functions Private Declare function ShellExecuteEX Lib " Shell32.dll "Alias ​​_" shellexecuteInfo) AS long 'universal call file properties dialog process' The first parameter is a full path to the file, the second parameter is the window handle PUBLIC SUB ShowProps (FileName As String, OwnerhWnd As Long) Dim SEI As SHELLEXECUTEINFO Dim r As Long With SEI .cbSize = Len (SEI) .fMask = SEE_MASK_NOCLOSEPROCESS Or _ SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI .hwnd = OwnerhWnd .lpVerb = "pro perties ".lpFile = FileName .lpParameters = vbNullChar .lpDirectory = vbNullChar .nShow = 0 .hInstApp = 0 .lpIDList = 0 End With r = ShellExecuteEX (SEI) End Sub Use 'routine: calling c: /autoexec.bat properties Dialog box call showprops ("c: /autoexec.bat", me.hwnd) Quickly calls "Soft Disk Format Dialog" We are familiar with the process of formatting floppy disks in Windows, steps generally: 1, open " My computer "2, right-click" 3.5-inch floppy disk a "3, in the menu that appears, select" Format "then, the dialog box shown below appears: in this window, then Select your requirements for the floppy disk formatting. In VB development, this system dialog can be called quickly through simple code, and by setting different call parameters, it is possible to directly select the form of the dialog box.

转载请注明原文地址:https://www.9cbs.com/read-3477.html

New Post(0)