Win95 system API function big secret Win95 with its new and exquisite appearance, simple and easy way of operation, let you enjoy the fun of action platform. Visual Basic, which is Microsoft, is more than just a computer language, but also a powerful integrated development environment integrating application development, testing, and error changing, millions of programmers benefited from this. Visual Basic A powerful feature is that it has functions that call reside in the Dynamic Library (DLL) file, including all functions provided and used by Windows. The access to hundreds of functions and other functions contained in the DLL have expanded the function of Visual Basic, and its functions are far beyond other languages, and there is really a kind of "belonging to", after all, Visual Basic is Microsoft's ""嫡 嫡 部. " You can use the hundreds of API interface functions provided by the Windows API in your application to accelerate the establishment of the application, reduce the repetitability of the program development (Bill Gats to find you copyright lawsuits, you can not gather it! - - Oh!) The so-called API is "Application Programing Interface), which is some function that is written by the operating system itself with the C language. The Windows API function consists of many "dynamic connection libraries" or DLL. In 32-bit Windows, the core Windows API DLL has the following: GDI32.DLL -------- graphic display interface APIkernel32.dll ---- Handling low-level tasks (such as memory and task management) APIUSER32 .dll ------- Processing window and message (Visual Basic programmer can constantly have new APIs, processing new operating system extensions, such as E-mail, networking And new peripherals. Since the Windows API function is not a Visual Basic internal function, it must be explicitly declared before use. To get the correct format declaration, you can access the file Win32API.txt in the WinAPI directory. This article only describes the Win95 system API function and calls WIN95 built-in functionality. For example, we can directly call standardized "Restart", "Disk Format", call and change the standard "About Window", view "Properties", set "Wallpaper", establish shortcut, determine memory, read and write "registry ", In establishing a status bar icon, etc. • Restart Some applications are required to be restarted once, so that the settings take effect, and can be implemented using the exitwindowsex function. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPrivate Sub Command1_Click () ExitWindowsEx & H43, 0End Sub? When a disk is formatted, right-click "3.5 diskette A" and select "Format When "is displayed, the standard" Disk Format "window is popped up. We can also use the function to easily call the Windows 95 Standard's "Disk Format" window to implement the corresponding operation functionality of the disk.
Form add the following code: Private Sub Form_Click () FormatFloppyEnd Sub tagging the following modules: Public Const WM_CLOSE = & H10Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As LongDeclare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongDeclare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongDeclare Function GetDesktopWindow Lib "user32" () As LongDeclare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As LongDeclare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongDeclare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Type RECTLeft As LongTop As LongRight As LongBottom As LongEnd TypeType POINTAPIX As Longy As LongEnd TypeConst SWP_NOSIZE = & H1Const SWP_NOZORDER = & H4Public Sub FormatF loppy () Dim sBuffer As String, Windir As String, Procs As String, XDim lResult As LongsBuffer = String $ (255, 0) lResult = GetWindowsDirectory (sBuffer, Len (sBuffer)) Windir = Trim (sBuffer) Procs = Left (Windir , Lresult) & "/Rundll32.exe shell32.dll, shFormatdrive" Call CenterDialog ("Format - 3? Floppy (A :)") x = shell (procs, 1) Call CenterDialog ("Format - 3? Floppy (A: ")") ") K = LOCKWINDOWUPDATE (0) End Subpublic SUB CenterDialog (Wintext As String) Doeventson Error Resume Nextdim D3 As longd3 =
LockWindowUpdate (GetDesktopWindow ()) Dim wdth% Dim hght% Dim Scrwdth% Dim Scrhght% Dim lpDlgRect As RECTDim lpdskrect As RECTDim hTaskBar As LonghTaskBar = FindWindow (0 &, WinText) Call GetWindowRect (hTaskBar, lpDlgRect) wdth% = lpDlgRect.Right - lpDlgRect .Lefthght% = lpDlgRect.Bottom - lpDlgRect.TopCall GetWindowRect (GetDesktopWindow (), lpdskrect) Scrwdth% = lpdskrect.Right - lpdskrect.LeftScrhght% = lpdskrect.Bottom - lpdskrect.TopX% = (Scrwdth% - wdth%) / 2y% = (ScRHGHT% - hGHT%) / 2Call setWindowpos (htaskbar, 0, x%, y%, 0, 0, swp_nozorder or swp_nosize) DoEventsend Sub? Call the "About" window In the Help menu, select "About XXX" will pop up Standard "About" window, using the shellabout function can not only call the standard "About" window, but also change the content at will! Shellabout declares as follows: HWND Settings window handle, "caption" of the SZAPP settings window, SzothersTUFF adds additional descriptions between "Copyright" and "Use rights". Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As LongPrivate Sub Form_Load () Call ShellAbout (hWnd, "Hefa Wu angel work Room! "," Call the standard for the window "& VBCRLF &" God is the same! Amitabha! " Regedit, according to the following path: HKEY_LOCAL_MACHINE → Software → Microsoft → Windows → CurrentVersion → Version, you will find the general settings of the "About" version in your computer, you can change the content of Version to your favorite setting, such as "Hefu Angel Work "" Hefa Wusi Wolf Studio ", etc. View "Properties" Win95 Add a new concept - "Properties", each object has its own "property", in the Properties window, is a detailed description of the object, and different object "properties" The description of the window is different. We can call the "Properties" standard window with the shellexecuteEx function. The following program functions are equivalent to popping the standard "Properties" window when the right mouse button is "AutoExec.bat" under the root directory.
The form is added as follows: private sufim filename as stringFileName = "c: /autoexec.bat" r = showproperties (filename, me.hwnd) if r <= 32 THEN MSGBOX "Error" End Sub joins following code module: Option ExplicitType SHELLEXECUTEINFOcbSize as LongfMask as Longhwnd as LonglpVerb as StringlpFile as StringlpParameters as StringlpDirectory as StringnShow as LonghInstApp as LonglpIDList as Long lpClass as String hkeyClass as Long dwHotKey as Long hIcon as Long hProcess as Long End TypePublic Const SEE_MASK_INVOKEIDLIST = & HCPublic Const SEE_MASK_NOCLOSEPROCESS = & H40Public Const SEE_MASK_FLAG_NO_UI = & H400Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" _ (SEI As SHELLEXECUTEINFO) As LongPublic Function ShowProperties (FileName As String, OwnerhWnd As Long) As LongDim SEI As SHELLEXECUTEINFODim r As LongWith SEI.cbSize = LEN (SEI) .fmask = See_mask_nocloseprocess or see_mask_invokeidlist or see_mask_flag_no_ui.hwnd = OwnerhWnd.lpverb = "Properties" .lpfile = filename.lpparameters = VBNULL CHAR.LPDIRECTORY = VBNULLCHAR.NSHOW = 0.HINSTAPP = 0.lpidList = 0nd withr = shellexecuteEx (SEI) showproperties = sei.hinstapp end function? Setting wallpaper wallpaper is a picture or image displayed on the desktop, is an important window of Win95. You can choose a multi-color wallpaper by changing the files in the list. Wallpaper is a beautiful veil for Win95, we can use the SystemParametersInfo function to uncover its "mysterious veil" and create a different style for her.
List1 increase control on a form, the form was added the following code: Option ExplicitPrivate Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As LongConst SPI_SETDESKWALLPAPER = 20Const SPIF_UPDATEINIFILE = & H1 'update Win.ini ConstantConst SPIF_SENDWININICHANGE = & H2' update Win.ini and tell everyonePrivate Sub Form_Load () Dim Temp As StringTemp = InputBox ( "Please Input A Directory", "Changer", "C: / WINDOWS / ") IF TEMP =" "THEN END 'CANCEL CLICKEDIF RIGHT $ (Temp, 1) <>" / "Ten Temp = Temp " /"List1.tag = TempTemp = Temp "* .bmp"' set the file FILTER (Path * .bmp) Temp = DIR $ (TEMP) Do While Temp $> "" Temp = DIR $ IF TEMP = "" The EXIT DOLIST1.ADDITEM TEMPLOOPLIST1.ADDITEM "" showlist1.setfocuslist1.listIndex = 0End SubPrivate Sub list1_dblclick () Dim Temp As StringDim BMPFile As StringTemp = Tag If List1.Text = "(none)" ThenBMPFile = "(none)" ElseBMPFile = Temp (List1) End IfSystemParametersInfo SPI_SET Deskwallpaper, 0, ByVal Bmpfile, Spif_Updateinifileend Subprivate Sub List1_KeyPress (Keyascii As Integer) If Keyascii = 13 THEN LIST1_DBLClickend Sub Try now, change your wallpaper on the spot (no money)! Cool! • Establishing shortcuts WIN95 shortcuts provide access to common programs and documents, and you can add shortcuts for any program, document, or printer in your desktop or folder. The FcreateshellLink function can be quickly established to establish a shortcut for common programs and documents in VB5.
FCreateShellLink statement is: Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As LongLpstrFolderName setting shortcut folder name, lpstrLinkName settings shortcut The title name, LPSTRLINKPath sets the directory and file name of the application pointed to by the shortcut. In short, the following format: FcreateshellLink (DestinationPath, Shortcutname, SourcePathappname, "") The following code is built on the "D: /Path/Appname.exe" application on the desktop "Shortcut Title" shortcut. Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As LongPrivate Sub Form_Click () lResult = fCreateShellLink ( ".... / WINDOWS / DESKTOP "" Shortcut Title "," D: /Path/appname.exe "," ") End Sub Tips: If you want to build shortcuts on the Desktop, you should establish the target directory should be" .... / Windows / Desktop "; if you want to create a shortcut in the Start menu, establish the target directory should be" .... / windows / start menu "; if you want to create a shortcut in the Program menu, establish the target directory should To the corresponding ".... C: / Windows / Start Menu / Programs", this is pushed. • Determine the memory we often visit Windows managed memory. The maximum impact on the performance of the application is available in memory capacity. It is very useful when there is a large file similar to the bitmap file, because the program is swap file (SWAP) method, can get the actual memory Larger memory. After you know how memory is allocated, you can read the memory value and operate large digital files. You can use a rich Win32 API function to determine Windows global memory and manipulate data files, which is very useful for determining whether the program can work properly.
DWLENGTH data structure DWMEMORYLOAD memory Using a percentage DWTOTALPHYS Actual memory total byte number DWAVAILPHYS Available actual memory bytes DWTOTALPAGEFILE page file Total number DWTOTALTALTUAL Virtual memory total byte DWAVALVIRTUAL DVALVIRTUAL Available Virtual Memory memory modules of code bytes is added as follows: Type MEMORYSTATUSdwLength as LongdwMemoryLoad as LongdwTotalPhys as LongdwAvailPhys as LongdwTotalPageFile as LongdwAvailPageFile as LongdwTotalVirtual as LongdwAvailVirtual as LongEnd TypeDeclare Sub GlobalMemoryStatus Lib "kernel32" add the following code (lpBuffer as MEMORYSTATUS) form: Private Sub Form_Click () DIM m as membratestatusm.dwlength = len (m) GlobalMemoryStatus MPRINT "The length of the data structure", M.dwlengthprint "Percentage", M.dwMemoryLoadprint "actual memory total byte", M.dwtotalphysprint "available actual Memory Byro ", M.Dwavailphysprint" Paging file total byte ", M.dwtotalpageFilePrint" Paging file available bytes ", M.dwavailPageFilePrint" Virtual memory total byte ", M.dwtotalVirtualPrint" available virtual Memory Biometers, M.DWAVAILVIRTUALEND SUB? Read Write Registry WIN95 and NT Registry Database (registry) is a very important component in the system, which sets the parameters of Win95 and NT, including user information, system hardware configuration And applications and other information. The registry system replaces multiple INI files in the old version of Windows. (Warning: If you are not familiar with the registration table, don't modify it at will. If the registry project is wrong, it will crash, and even destroy the operating system itself.) The REG function processing in the Win32 API is a general reading process of the registry database. : 1, use regopenkey or regreatekey to open or create a key; 2. If the last step is successful, use the value of the subkey using RegQueryValue (or RegqueryValueex), use the regSetValue (or regvSetValueex) to set the sub-key value, use RegenumKey to get all sub-keys Use RegdeleteKey to delete a key; 3. Use the RegcloseKey Close button after completing the operation. The following application demonstrates how to generate a key, store value and obtain registry data. Generate three sub-keys TEST / MASTERING VB5, Windows Width, Windows HEIGHT, and Windows Width, Windows HEIGHT, which are used to store the form size at the last execution.
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPrivate Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As LongPrivate Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As LongPrivate Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long 'Note that if you declare the lpData parameter as String, you must pass it By Value.Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long 'Note that if you declare the lpData parameter AS String, you must pass it By Value.Const ERROR_SUCCESS = 0 & Const ERROR_BADDB = 1009 & Const ERROR_BADKEY = 1010 & Const ERROR_CANTOPEN = 1011 & Const ERROR_CANTREAD = 1012 & Const ERROR_CANTWRITE = 1013 & Const ERROR_REGISTRY_RECOVERED = 1014 & Const ERROR_REGISTRY_CORRUPT = 1015 & Const ERROR_REGISTRY_IO_FAILED = 1016 & Const HKEY_CLASSES_ROOT = & H80000000Const HKEY_CURRENT_USER = & H80000001Const HKEY_LOCAL_MACHINE = & H80000002Const regkey = "Test / MASTERING VB5 "
Private Sub Form_Load () Dim retValue As LongDim result As LongDim keyValue As StringDim keyId As LongDim subKey As StringDim bufSize As LongLabel6.Caption = regkeyretValue = RegCreateKey (HKEY_LOCAL_MACHINE, regkey, keyId) If retValue = 0 ThensubKey = "Windows Width" retValue = RegQueryValueEx (keyId, subKey, 0 &, reg_sz, 0 &, bufSize) If bufSize <2 ThenkeyValue = Me.WidthretValue = RegSetValueEx (keyId, subKey, 0 &, reg_sz, ByVal keyValue, Len (keyValue) 1) ElsekeyValue = String (bufSize 1 , "") retValue = RegQueryValueEx (keyId, subKey, 0 &, reg_sz, bykeyvalue, bufSize) keyValue = Left $ (keyValue, bufSize - 1) Me.Width = keyValueEnd IfLabel4.Caption = subKeyLabel5.Caption = Me.WidthsubKey = "Widows Height "retValue = RegQueryValueEx (keyId, subKey, 0 &, reg_sz, 0 &, bufSize) If bufSize <2 ThenkeyValue = Me.HeightretValue = RegSetValueEx (keyId, subKey, 0 &, reg_sz, ByVal keyValue, Len (keyValue) 1) ElsekeyValue = String (Bufsize 1, ") RetValue = RegQueryValueex (Keyid, Subkey, 0 &, Reg_sz, Byval KeyValue, bufSize - 1) Me.Height = keyValueEnd IfLabel8.Caption = subKeyLabel7.Caption = Me.HeightEnd IfEnd SubPrivate Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer) Dim keyValue As StringDim retValue As LongDim keyId As LongretValue = RegCreateKey (HKEY_LOCAL_MACHINE, regkey, keyId) keyValue = Me.WidthretValue = RegSetValueEx (keyId, "Windows Width", 0 &, reg_sz, ByVal keyValue, Len (keyValue) 1) keyValue = Me.HeightretValue = RegSetValueEx (keyId, "Windows Height", 0 &, reg_sz, BYVAL KeyValue, Len (KeyValue)
1) End Sub? Set up the icon WIN95 in the "Status Zone" as "Volume", Date "," Screen ", etc., can establish a shortcut icon on the Win95 status bar (TRAY). If the mouse stays on the icon, the corresponding tooltip is displayed, and when the user clicks (or double-click) the left button on the icon, the software will implement the corresponding function, click the right click, it will achieve its simple Features. TRAY is also called Systray, Trayicon, Notifyicon, Status Area, etc. It is a special area on the task bar of Win95 / NT. Many software is running in TRAY to join your own icon, and another special place in this area is that you can Drag files from the resource manager and place it in this area. It is because of these features, TRAY programming has special status in Win95 / NT. TRAY programming is relatively special, mainly including three major aspects: icons, tooltips and messages. It belongs to a part of the shell program, mainly using the shell_notifyicon function in the Shell API. The shell_notifyicon function is this declared: Type NotifyicondatAcbsize As Long Structure The byte number hWnd as long Accept the TRAY tray icon message window handle UID AS Long by the application-defined icon identifier UFLAGS AS Long flag UCALLBACKMESSAGE AS LONG By the application defined message hIcon As Long TRAY icon handle szTip As string * 64 tooltip string End TypeDeclare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long this structure is uFlags Important, it has three values: NIF_ICON, NIF_MESSAGE and NIF_TIP, indicating that Hicon, UcallbackMessage and Sztip parameters are valid, used to modify icons, messages, and tool tips. These three values can be used simultaneously (three parameters or) or can be used separately. In order to implement a response to the user's mouse operation, you need to process the messages defined in the program. The long parameter LPARAM contains the mouse message defined by WIN32. If there are multiple icons, short parameter wparam represents the icon identifier. There is a SYSTRAY.OCX control in the VB CD / Tools / Unsupprt / Systray directory. Generate the SYSTRAY.OCX control after compiling. Now we apply the SYSTRAY.OCX control for TRAY programming. First establish a "project", follow: "Project" - "Part" (or right-click "Parts" on "Toolbox"), then check the System Tray Control Csystray, Csystray Control, appears in Tool "In the box." The SYSTRAY.OCX control has MouseDblclick, MouseDown, Mousemove, Mouseup four events, responds, for mousemove, mousedown, mouseup, mousedblclick. The following programming clearly shows their response time order.