Visual Basic for Windows 3.0 (referred to as VB) is currently one of the most effective tools for developing WINDOWS application software. It comprehensively uses the BAIC language and new visual design tools. It is not only powerful but also easy to learn. Secondly, VB has an event-driven programming mechanism, which makes full use of the characteristics of the WINDOWS graphical environment and allows developers to quickly construct powerful applications.
So how to fully expand the functions of VB when developing VB application software? This requires making good use of the most powerful and distinctive parts of VB at different levels:
●Call the dynamic link library at the function layer.
●Use VBX at the control layer. ●Execute other applications at the application layer.
1. Call the functional link library (DLL) at the function layer
The WINDOWS operating system is actually composed of many powerful dynamic link libraries (DLLs). VB considers that some tasks are beyond the capabilities of its own language, so it provides the ability to directly call these DLL subroutines in the operating system. For example: Under normal circumstances, the window's control menu provides seven functions: restore, move, size, minimize, maximize, close and switch. In actual applications, we hope that the window will be displayed according to the designed size, and users are not allowed to change the window size at will, nor are they allowed to switch to other windows. This requires that the control menu must be deleted during design except for "Move" and "Close". All control menu items except ” option. To accomplish this task, we can first set the MaxButton property and MinButton property of the form to False, which will not allow the form to be minimized and maximized, and the form cannot be restored. Then set the Bordersstyle property of the form to 1-FixedSingle or 3-FixedDouble, which does not allow the form to change size. But VB itself cannot delete the "switch" option and the two dividing lines. Fortunately, this is easy to do by calling WINDOWSDLL.
Usually, to use WINDOWSDLL, you must first specify the DLL subroutine to be used. We can specify the DLL subroutine used in two places, that is, in the global module, or in the description part of the form layer. Its format is:
DeclareSub subroutine name Lib "library name" [Alias "alias"] [([parameter])]
DeclareFunction subroutine name Lib "library name" [Aliass "alias"] [([parameter])] [AS data type]
The first format indicates that the procedure has no return value, and the second format indicates that the procedure returns a value, which can be used in expressions. If the library name is a library in the WINDOWS operating environment (in the System directory), such as "USER .EXE", "KERNEL.EXE" or "GDI.EXE", etc., use this name as the library name. If you are using a DLL from other sources, use the file name including the path (for example: "C:WINDOWSBRUSH.DLL"). Alias (Alias) allows the use of other names to call subprograms. It is especially useful when the name of the foreign subprogram is the same as a VB reserved word. The parameter refers to the parameter value and data type to be passed to the subprogram. Refers to the data type of the function return value, which may be Integer, Long, Single, Double, Currency or String. The following is a description of the DLL subroutine to be used:
DeclareFunctionGetSystemMenu%Lib"User"(ByValhWnd%,ByValbRevert%)
DeclarefunctionRemoveMenu%Lib"User"(ByValhMenu%, ByValnPosition%, ByValwFlags%)
After describing the DLL subroutine, the method of executing the DLL subroutine is the same as executing a general procedure (function) in VB. Next, we write a process named Remove-Items-From-System to complete the functions mentioned in the above example. In the process, the two DLL subroutines explained above are called:
Subremove-Items-From-Sysmenu (A-FormAsForm)
'Get the form system menu sentence Bing
HSysMenu=GetSystemMenu(A-Form.hWnd, 0)
'Delete all menu items except "Move" and "Close", you must start from the last menu item when deleting
R=RemoveMenu(HSysMenu,8,MF-BYPOSITION)'Delete switch
R=RemoveMenu(HSysMenu,7,MF-BYPOSITION)'Delete the first dividing line
R=RemoveMenu(HSysMenu,5,MF-BYPOSITION)'Remove the second dividing line
EndSub
With this process, adding the following line of code to the Form-Load event of any form can delete all control menu items of the form except the "Move" and "Close" options:
Remove-Items-From-SysmenuMe
2. Use VBX at the control layer
The second part of the powerful function of VB is the use of VBX, that is, its openness and unlimited expansion characteristics. Although the VB toolbox (ToolBox) has tried its best to include the tools required for designing application software, in order to continuously expand the functions of VB, VB provides a set of development tools (CustomControlDevelopmentKit) for third-party developers to design the required controls. After designing the control file (its file extension is ".VBX"), you can select the "AddFile..." command from the menu "file" item. As a result, an "AddFile" dialog box will appear on the screen. Double-click the required VBX The file name can be used to add the VBX to VB. After these controls are loaded into VB, VB will add these foreign controls to the original toolbox and merge them with other controls. It is precisely because of this technology that VB can continue to develop, and programming with VB is more convenient, faster and more effective. This is one of the main features of VB that distinguishes it from other program development environments. Since the launch of VB, third-party software companies have designed a large number of new controls. Here are several very useful VBX when developing WINDOWS applications:
●Three-dimensional controlThreed.vbx
It provides six three-dimensional controls including command buttons, check boxes, radio buttons, frames, push-down buttons and panels. Using these controls can make the form more three-dimensional.
●Graphic control Graph.vbx
After sending data to the graphic control, the graphic control can draw two-dimensional or three-dimensional pie charts, histograms, and trend charts, and can be printed or copied to the clipboard.
●Communication control Mscomm.vbx
It provides serial communication capabilities and can be used to transmit and receive data between serial ports.
●Data grid control Truegrid.vbx
It can be used as a general data display table, or it can connect a database and a grid. It is an ideal tool for making database browsers or data displays.
2. Execute other applications at the application layer
When compiling complex large-scale software, we often need to have some special programs with relatively independent and complete functions, such as editing programs, and these programs are usually universal, popular and tested in practice. If these programs are rewritten by developers, not only will the program workload and debugging process be greatly increased, but it will also be difficult to match the functions of these general programs. Obviously, it would be ideal if we could call these programs directly. Fortunately, VB provides a Shell function that can be used to call other applications, so that some functions of VB can be directly completed by other applications, thus greatly reducing programming tasks.
The format is Shell (command string [, window type])
The command string is the name of the application to be executed. The extension of the executable file is limited to ".COM", ".EXE", ".BAT", ".PIF". The default extension is .EXE file. The window type is an integer value, which corresponds to the display window style when the program is executed. It is optional. There are five choices:
window type value
Window type 1, 5, 9
Normal window, with pointer 2
Minimum window with pointer (default) 3
Maximum window, with pointers 4, 8
Normal window, no pointers 6, 7
Minimal window, no pointer
When the Shell function successfully calls an application, it returns a task ID (TaskID), which represents the unique identification of the executing program.
[example]
X=Shell("C:WINDOWS/NOTEPAD.EXE", 1)
This statement calls NOTEPAD.EXE in the WINDOWS attachment as an editing program and returns an ID value to X. ->