A set of VB practical applet functions

zhaozj2021-02-11  210

Using VB implementation of programming and unfunction function calls and Windows API functions, the following is some of the practical small routines collected by the author, they can be used directly in your actual programming, and can be expanded according to practical applications. Among them involved in the Windows API function call you can copy the function definition from the API function viewer of the VB5.0 system to avoid errors.

System form form

System type means that users cannot perform other operations before completion of current form operations, which is especially important for the compilation system password protection interface. If you want the current form system form, you need to define the API function as follows:

Declare function setsystemodalwindow lib "user" (byval hwnd as integer) AS INTEGER

Then call: Oldsystemodal = setsystemodalwindow ([form] .hwnd)

2. Get the type of drive

The code is as follows:

DECLARE FUNCTION GETDRIVETYPE LIB "KERNEL" (Byval NDRIVE AS INTEGER) AS INTEGERGLOBAL Const Drive_removeable% = 2, drive_fixed% = 3Global const drive_remote% = 4

3. Form in

This subroutine function allows the form to position in the center of the screen, and anyone in the form is just joined in the form:

"CenterWindow.me" can be called successfully.

Public Sub CenterWindow (F AS Form) F.Top = (Screen.Height * .5) - (F.Height * .5) f.Left = (Screen.width * .5) - (F.Width * .5) End Sub

4. Define variables

Many programmers are accustomed to defining the variables below:

Dim Inum, INEXTNUM, ILASTNUM AS INTEGER

In fact, only the last variable is set to integrate, the first two variables are the default Variant data type of the system, while the Variant data type can be used to replace any data type, clearly disadvantageous for the refined programming. The correct way is as follows:

Dim Inum As INTEGERDIM INEXTNUM AS INTEGERDIM ILASTNUM AS INTEGER

5. Make the text highlight

This subroutine is selected for text, such as text, tag, etc.

Public SUB setSelected () screen.activecontrol.selstart = 0screen.activeControl.sellength = len (screen.activecontrol.text) End Sub

6. Close other programs

The following code can turn off other programs in memory

Title = "myApp" 'Defines the title of the program window you need to close

IHWND = FindWindow (0 &, Title) htask = getWindowTask (IHWND) IRET = PostappMesSage (Ihtask, Wm_quit, 0, 0 &)

7. No file exists?

This function returns to the file that is found.

Function FileExist (filename as string) as booleanfileexist = IIF (DIR (filename <> ", true, false) end function

8. The main program is unique

Use the code provided below for your main program to prevent multiple execution of the application, you should put it in your code module that needs it needs.

Public Sub Main () if app.previnstance thenbringwindowtotop frmmain.hwndelseload frmmaund ifnd Sub

The above exquisite code is very practical for professional programmers, I hope you can get inspiration.

The above code from: the source code database (SourceDataBase) Current Version: 1.0.392 Author: Shawls profile: Http://Shawls.Yeah.Net E-Mail: ShawFile@163.Net QQ: 9181729

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

New Post(0)