Let the registry remember the number of uses of VFP applications

xiaoxiao2021-03-06  94

The registry is a database that saves the system's hardware information, application information, and user information in the Windows operating system, which provides the best location for the application. In the Windows operating system, when we run the "regedit.exe" file, you can see from the open registry editing window, the registry consists of the left and right parts: the first layer of the left item is called the registry Primary key, double-click the keys extending when each primary key is called the subkey; the right side of the window is the key value of each subkey, each having its corresponding default and the key represented by different key value names. Value (where the default value is named is a null).

Read and write registry data in the VFP application, you must use the Win32API function to call the Win32API function like using other VFP functions, you must first use the declare command to register each called function (declaration) ), Its format is Declare [cfunctionType] functionName in libraryname [as aliasname];

[cParamType1 [@] paramname1, cparamtype2 [@] paramname2, ...]

The meaning of each parameter is: 1CFunctionType is a function of the return value type, but SHORT, INTEGER, or LONG, SINGLE, DOUBLE, STRING, if the function does not return a value, omitting the cfunctionType; 2FunctionName points out the called Win32API function name, please note Size, otherwise the VFP will not search for this function in the .dll library (libraryName), if the function name is the same name with the VFP function, the AS clause can be used to take another legal VFP function name; 3LibraryName Specifies the external Windows. The name of the DLL, if you use Win32API, VFP is searching for functionname in kernel32.dll, gdi32.dll, user32.dll, mpr.dll, and advapi32.dll; 4CParamType specifies the type of each parameter, can be Integer or Long, Single, One of the Double, String, there are two ways to pass the parameters in the VFP in the VFP: Press value transfer and pressing the name (reference), the former only passes the value (or constant) value to the function, so inside the function The value of this variable cannot be modified; the latter is transmitted to the function of the variable (cannot use constant), so that the value of the variable can be modified inside the function, it is suitable for modifying the value of the variable in the function or placed in the variable. The case where the value is returned. In the VFP, if "@" is preceded in the variable name, "@" is transmitted, and "@" is not added to the value transfer parameters. As for each parameter in this sample program, it is known from the Declare command and function call statement by reference delivery or by value.

Every time the sample program is run once, add 1 value below the Timesforusen name of the HKEY_CURRENT_USER / SOFTWARE / LYTAPP child button in the registry until it runs 12 times:

* Each primary key corresponds to an integer value, namely: #define hkey_classes_root bitset (0,31) && - 2147483648 # define hkey_current_user bitset (0,31) 1 && - 2147483647 # Define hkey_local_machine bitset (0,31) 2 && - 2147483646 # DEFINE HKEY_USER bitset (0,31) 3 && - 2147483645 # DEFINE HKEY_CURRENT_CONFIG bitset (0,31) 5 && - 2147483643 # DEFINE HKEY_DYN_DATA bitset (0,31) 6 && - 2147483642 * key Data type: 1-string, 3-binary, 4-integer #define reg_sz 1 # define reg_binary 3 # Define REG_DWORD 4 * When the following API function returns 0, the operation is successful.

DECLARE Integer RegOpenKey IN Win32API; Integer nHKey, String @cSubKey, Integer @nResultDECLARE Integer RegCreateKey IN Win32API; Integer nHKey, String @cSubKey, Integer @nResultDECLARE Integer RegSetValueEx IN Win32API; Integer hKey, String lpszValueName, Integer dwReserved,; Integer fdwType, String lpbData, Integer cbDataDECLARE Integer RegQueryValueEx IN Win32API; Integer nHKey, String lpszValueName, Integer dwReserved,; Integer @ lpdwType, string @lpbData, Integer @ lpcbData * DECLARE Integer RegDeleteKey IN Win32API; * Integer nHKey, String @ cSubKey * DECLARE Integer RegDeleteValue IN Win32API ; * Integer nHKey, String cSubKey * DECLARE Integer RegCloseKey IN Win32API; * Integer nHKeycsubkey = 'Software / lytapp'nresult = 0 if regopenkey (HKEY_CURRENT_USER, @ csubkey, @ nresult) # 0 RegCreateKey (HKEY_CURRENT_USER, csubkey, @ nresult) endif * stored directivity subkey nResult the "HKEY_CURRENT_USER / Software / lytapp" long integer lpdwtype = 0lpbdata = space (256) lpcbdata = len (lpbdata) if RegQueryValueEx (nresult, 'TimesForUse', 0, @ lpdwtype, @ lpbdata, @ LPCBDATA) = 0do case case lpdewtype = reg_szlpbdata = left (lpbdata, lpcbdata-1) IF val (lpbdata) <12lpbdata = alltrim (Strim (Str (Val (LPBDATA) 1)) MessageBox ('This program can only be used before being registered 12 times! ' Chr (13) ' You are now the ' ; lpbdata ' times the program. ') lpbdata = lpbdata chr (0) CBDATA = LEN (LPBDATA) RegSetValueex (NResult,' Timesforuse ', 0, REG_SZ, LPBDATA, CBDATA) ELSEMESSAGEBOX ("Program has expired 作 作!" CHR (13) "Please The author contacts the registration. ") Endifcase LPDWTYPE = REG_BINARYMESSAGEBOX ('This key value is binary data."

') Case LPDWTYPE = REG_DWORDMESSAGEBOX (' This key value is long integer data, please use nn = 0 ' CHR (13) FOR i = 1 to 4' chr (13) ; 'NN = nn val ( Substr (lpbdata, i, 1) * 16 ^ (2 * i-2) ' chr (13) ;' endfor read this value. ') OtherWiseMessageBox (' unknown data! ') Endcaseelselpbdata =' 1'MessageBox 'This program can only use 12 times before unregistered!' Chr (13) 'You are now the' lpbdata 'use this program.') Lpbdata = lpbdata chr (0) RegSetValueEx (NResult, 'Timesforuse) ', 0, reg_sz, lpbdata, 2) Endif * WARNING: It is best not to modify the content when the user is not familiar with the registry, otherwise it may cause the system's crash. If the user wants to modify the registry, it is recommended to modify the best. Back up the registry.

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

New Post(0)