M
Milana
Вот код программ. Не могли бы вы, пожалуйста, написать, что делает каждая строка кода?
[codebox]#include <iostream>
#include <windows.h>
using namespace std;
void DiskInfo(int, LPTSTR);
void main()
{
char buffer[MAX_PATH];
char bufferDrive[256];
char *pch = bufferDrive;
int i;
int a;
GetCurrentDirectory(sizeof(buffer),(LPTSTR)buffer);
cout << "Current directory: " <<endl <<buffer << endl << endl;
GetSystemDirectory((LPTSTR)buffer,sizeof (buffer));
cout << "System directory: " << endl << buffer<<endl << endl;
GetWindowsDirectory((LPTSTR)buffer,sizeof(buffer));
cout << "Windows directory: " << endl << buffer << endl << endl;
cout << "------------------------------------------------------------------------------" << endl << endl;
GetLogicalDriveStrings(sizeof(bufferDrive),(LPTSTR) bufferDrive);
cout << " Available logical drives: " << endl << endl;
i=1;
while (*pch)
{
cout << i << " :" << pch << endl;
pch = &pch[strlen(pch) + 1];
i++;
}
cout << endl << "Enter the number of logical drive to see the info about it : ";
cin >> a;
DiskInfo(a,bufferDrive);
getchar();
getchar();
}
void DiskInfo(int a, LPTSTR bufferDriveF)
{
char *pchF = bufferDriveF;
int gDriveType;
char lpSectorsPerCluster[256];
char lpBytesPerSector[256];
char lpNumberOfFreeClusters[256];
char lpTotalNumberOfClusters[256];
int j=2;
while (j<=a && *pchF)
{
pchF=&pchF[strlen(pchF)+1];
j++;
}
cout << endl << "Information about " << pchF << " :" << endl << endl;
cout << "Drive type: ";
gDriveType=GetDriveType(pchF);
switch (gDriveType)
{
case 0: cout << "Unknown type of device" << endl;break;
case 1: cout << "This root directory doesn't exist" << endl;break;
case 2: cout << "Drive is removable" << endl;break;
case 3: cout << "Drive is fixed" << endl;break;
case 4: cout << "Drive is remote" << endl;break;
case 5: cout << "Drive is CD-ROM" << endl;break;
case 6: cout << "Drive is RAM Disk" << endl;break;
default: break;
}
GetDiskFreeSpace(pchF,
(LPDWORD)lpSectorsPerCluster,
(LPDWORD)lpBytesPerSector,
(LPDWORD)lpNumberOfFreeClusters,
(LPDWORD)lpTotalNumberOfClusters);
cout << "SectorsPerCluster: " << lpSectorsPerCluster << endl;
cout << "BytesPerSector: " << lpBytesPerSector << endl;
cout << "NumberOfFreeClusters: " << lpNumberOfFreeClusters << endl;
cout << "TotalNumberofClusters: " << lpTotalNumberOfClusters << endl;
}[/quote]
[codebox]#include <iostream>
#include <windows.h>
using namespace std;
void DiskInfo(int, LPTSTR);
void main()
{
char buffer[MAX_PATH];
char bufferDrive[256];
char *pch = bufferDrive;
int i;
int a;
GetCurrentDirectory(sizeof(buffer),(LPTSTR)buffer);
cout << "Current directory: " <<endl <<buffer << endl << endl;
GetSystemDirectory((LPTSTR)buffer,sizeof (buffer));
cout << "System directory: " << endl << buffer<<endl << endl;
GetWindowsDirectory((LPTSTR)buffer,sizeof(buffer));
cout << "Windows directory: " << endl << buffer << endl << endl;
cout << "------------------------------------------------------------------------------" << endl << endl;
GetLogicalDriveStrings(sizeof(bufferDrive),(LPTSTR) bufferDrive);
cout << " Available logical drives: " << endl << endl;
i=1;
while (*pch)
{
cout << i << " :" << pch << endl;
pch = &pch[strlen(pch) + 1];
i++;
}
cout << endl << "Enter the number of logical drive to see the info about it : ";
cin >> a;
DiskInfo(a,bufferDrive);
getchar();
getchar();
}
void DiskInfo(int a, LPTSTR bufferDriveF)
{
char *pchF = bufferDriveF;
int gDriveType;
char lpSectorsPerCluster[256];
char lpBytesPerSector[256];
char lpNumberOfFreeClusters[256];
char lpTotalNumberOfClusters[256];
int j=2;
while (j<=a && *pchF)
{
pchF=&pchF[strlen(pchF)+1];
j++;
}
cout << endl << "Information about " << pchF << " :" << endl << endl;
cout << "Drive type: ";
gDriveType=GetDriveType(pchF);
switch (gDriveType)
{
case 0: cout << "Unknown type of device" << endl;break;
case 1: cout << "This root directory doesn't exist" << endl;break;
case 2: cout << "Drive is removable" << endl;break;
case 3: cout << "Drive is fixed" << endl;break;
case 4: cout << "Drive is remote" << endl;break;
case 5: cout << "Drive is CD-ROM" << endl;break;
case 6: cout << "Drive is RAM Disk" << endl;break;
default: break;
}
GetDiskFreeSpace(pchF,
(LPDWORD)lpSectorsPerCluster,
(LPDWORD)lpBytesPerSector,
(LPDWORD)lpNumberOfFreeClusters,
(LPDWORD)lpTotalNumberOfClusters);
cout << "SectorsPerCluster: " << lpSectorsPerCluster << endl;
cout << "BytesPerSector: " << lpBytesPerSector << endl;
cout << "NumberOfFreeClusters: " << lpNumberOfFreeClusters << endl;
cout << "TotalNumberofClusters: " << lpTotalNumberOfClusters << endl;
}[/quote]
#include <windows.h>
#include <iostream>
#include <string>
#define MAX_KEY_LENGTH 255
using namespace std;
void GetSubKeys(HKEY hKey)
{
TCHAR subKeyName[MAX_KEY_LENGTH];
DWORD keyLen;
DWORD lpcSubKeys=0;
DWORD i, lResult;
lResult = RegQueryInfoKey(
hKey,
NULL,//lpClass,
NULL,//&lpcClass,
NULL,
&lpcSubKeys,
NULL,//&lpcMaxSubKeyLen,
NULL,//&lpcMaxClassLen,
NULL,//&lpcValues,
NULL,//&lpcMaxValueNameLen,
NULL,//&lpcMaxValueLen,
NULL,//&lpcbSecurityDescriptor ,
NULL);//&lpftLastWriteTime);
if (lpcSubKeys)
{
cout << endl << "Number of subkeys: " << lpcSubKeys << endl;
for (i=0; i<lpcSubKeys; i++)
{
keyLen = MAX_KEY_LENGTH;
lResult = RegEnumKeyEx(hKey,
i,
subKeyName,
&keyLen,
NULL,
NULL,
NULL,
NULL);
if (lResult == ERROR_SUCCESS)
{
cout << i+1 <<": " << subKeyName << endl;
}
}
}
}
void main()
{
HKEY hRootKey,hOpenedKey;
char sk[255];
string rootKey;
cout << "Enter rootKey: ";
cin >> rootKey;
if (rootKey == "HKEY_CLASSES_ROOT")
{
hRootKey = HKEY_CLASSES_ROOT;
}
else
{
if (rootKey == "HKEY_CURRENT_USER")
{
hRootKey = HKEY_CURRENT_USER;
}
else
{
if (rootKey == "HKEY_LOCAL_MACHINE")
{
hRootKey = HKEY_LOCAL_MACHINE;
}
else
{
if (rootKey == "HKEY_USERS")
{
hRootKey = HKEY_USERS;
}
else
{
if (rootKey == "HKEY_CURRENT_CONFIG")
{
hRootKey = HKEY_CURRENT_CONFIG;
}
else
{
cout << "No such rootKey!" << endl;
getchar();
getchar();
exit(1);
}
}
}
}
}
cout << endl << "Enter the subKey: ";
cin >> sk;
if( RegOpenKeyEx(hRootKey,
sk,
0,
KEY_READ,
&hOpenedKey) == ERROR_SUCCESS
)
{
GetSubKeys(hOpenedKey);
RegCloseKey(hOpenedKey);
}
else cout << "No such subKey!";
cout << endl;
getchar();
getchar();
}[/codebox]