Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0db1c556d4 |
@@ -0,0 +1,221 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <locale.h>
|
||||
|
||||
TCHAR szDrive[] = _T(" A:");
|
||||
|
||||
int main()
|
||||
{
|
||||
setlocale(LC_ALL, "ru_RU.UTF8");
|
||||
SetConsoleOutputCP(65001);
|
||||
SetConsoleCP(65001);
|
||||
//getLogicalDrives();
|
||||
//getDiskFreeSpaceExA();
|
||||
//get_file_list();
|
||||
//getfiletime();
|
||||
//createDir();
|
||||
//removeDir();
|
||||
//compareFileTime();
|
||||
//setVolumeLabel();
|
||||
//moveFile();
|
||||
//deleteFile();
|
||||
|
||||
return 0;
|
||||
}
|
||||
int getLogicalDrives() {
|
||||
DWORD uDriveMask = GetLogicalDrives();
|
||||
// printf("The bitmask of the logical drives in hex: %0X\n", uDriveMask);
|
||||
// printf("The bitmask of the logical drives in decimal: %d\n", uDriveMask);
|
||||
if (uDriveMask == 0)
|
||||
printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError());
|
||||
else
|
||||
{
|
||||
printf("This machine has the following logical drives:\n");
|
||||
while (uDriveMask)
|
||||
{
|
||||
// Use the bitwise AND, 1â€"available, 0-not available
|
||||
if (uDriveMask & 1)
|
||||
printf("%S ", (const char*)szDrive);
|
||||
// increment, check next drive
|
||||
++szDrive[1];
|
||||
// shift the bitmask binary right
|
||||
uDriveMask >>= 1;
|
||||
}
|
||||
printf("\n ");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getDiskFreeSpaceExA() {
|
||||
char n[10] = "";
|
||||
printf("Enter disc name\n");
|
||||
scanf(" %s", n);
|
||||
LPCWSTR pszDrive = n;
|
||||
BOOL test, fResult;
|
||||
// 64 bits integer, low and high bytes
|
||||
__int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
|
||||
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
|
||||
// If the function succeeds, the return value is nonzero. If the function fails, the return value is 0 (zero).
|
||||
test = GetDiskFreeSpaceExA(
|
||||
pszDrive,
|
||||
(PULARGE_INTEGER)&lpFreeBytesAvailable,
|
||||
(PULARGE_INTEGER)&lpTotalNumberOfBytes,
|
||||
(PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
|
||||
);
|
||||
printf("\nUsing GetDiskFreeSpaceEx()...\n");
|
||||
// Check the return value
|
||||
printf("The return value: %d, error code: %d\n", test, GetLastError());
|
||||
printf("Total number of free bytes available for user-caller: %ul\n", lpFreeBytesAvailable);
|
||||
printf("Total number of bytes available for user: %ul\n", lpTotalNumberOfBytes);
|
||||
printf("Total number of free bytes on disk: %ul\n", lpTotalNumberOfFreeBytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_file_list()
|
||||
{
|
||||
char n[8] = "";
|
||||
printf("Enter disc name\n");
|
||||
scanf("%s:", n);
|
||||
HANDLE hFind, hFile;
|
||||
WIN32_FIND_DATA data;
|
||||
FILETIME ftCreate;
|
||||
SYSTEMTIME systime, sysLocal;
|
||||
|
||||
|
||||
hFind = FindFirstFileA(n, &data);
|
||||
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
printf("%s\n ", data.cFileName);
|
||||
//GetFileTime(&hFind, &ftCreate, NULL, NULL);
|
||||
//FileTimeToSystemTime(&ftCreate, &systime);
|
||||
//SystemTimeToTzSpecificLocalTime(NULL, &systime, &sysLocal);
|
||||
//wprintf(L"CreationTime: %lu:%lu:%lu\n", sysLocal.wHour, sysLocal.wMinute, sysLocal.wSecond);
|
||||
//printf("Created on: %02d/%02d/%d %02d:%02d\n", ssystimeystime.wDay, systime.wMonth, systime.wYear, systime.wHour, systime.wMinute);
|
||||
} while (FindNextFileA(hFind, &data));
|
||||
FindClose(hFind);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int getfiletime()
|
||||
{
|
||||
HANDLE hFile1;
|
||||
FILETIME ftCreate;
|
||||
SYSTEMTIME stUTC, stLocal;
|
||||
hFile1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (hFile1 == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
printf("Could not open file, error %ul\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
if (!GetFileTime(hFile1, &ftCreate, NULL, NULL))
|
||||
{
|
||||
printf("Something wrong!\n");
|
||||
return FALSE;
|
||||
}
|
||||
FileTimeToSystemTime(&ftCreate, &stUTC);
|
||||
printf("UTC System Time format:\n");
|
||||
printf("text.txt Created on: %02d/%02d/%d %02d:%02d\n",stUTC.wDay, stUTC.wMonth, stUTC.wYear, stUTC.wHour, stUTC.wMinute);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int createDir()
|
||||
{
|
||||
BOOL createD = CreateDirectory(L"NewFolder", NULL);
|
||||
if (createD)
|
||||
{
|
||||
printf("Directory Created\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int removeDir()
|
||||
{
|
||||
BOOL removeD = RemoveDirectory(L"NewFolder", NULL);
|
||||
if (removeD)
|
||||
{
|
||||
printf("Directory Deleted\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int compareFileTime() {
|
||||
FILETIME fileTime1, fileTime2;
|
||||
// первый файл
|
||||
HANDLE file1 = CreateFile(TEXT("text.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
// время изменения первого файла
|
||||
GetFileTime(file1, NULL, NULL, &fileTime1);
|
||||
// закрываем первый файл
|
||||
CloseHandle(file1);
|
||||
// Открываем второй файл
|
||||
HANDLE file2 = CreateFile(TEXT("text2.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
// Получаем время изменения второго файла
|
||||
GetFileTime(file2, NULL, NULL, &fileTime2);
|
||||
// Закрываем второй файл
|
||||
CloseHandle(file2);
|
||||
// Сравниваем время изменения файлов
|
||||
int comparisonResult = CompareFileTime(&fileTime1, &fileTime2);
|
||||
|
||||
if (comparisonResult == -1) {
|
||||
wprintf(L"Файл 1 был изменен раньше файла 2\n");
|
||||
}
|
||||
else if (comparisonResult == 1) {
|
||||
wprintf(L"Файл 2 был изменен раньше файла 1\n");
|
||||
}
|
||||
else {
|
||||
wprintf(L"Время изменения файлов одинаково\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int setVolumeLabel(){
|
||||
LPSTR dirch = "S:\\";
|
||||
LPSTR dirn = "Storage";
|
||||
//LPSTR dirn = "Test";
|
||||
BOOL bbb = SetVolumeLabelA(dirch, dirn);
|
||||
//if(bbb){wprintf("%b",bbb);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int moveFile(){
|
||||
if (MoveFile(L"Old.txt",L"New.txt")){
|
||||
wprintf(L"Файл перемещён\n");
|
||||
}
|
||||
else {
|
||||
wprintf(L"Ошибка\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int deleteFile() {
|
||||
if (DeleteFile(L"New.txt")) {
|
||||
wprintf(L"Файл удалён\n");
|
||||
}
|
||||
else {
|
||||
wprintf(L"Ошибка\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
GetLogicalDrivesFindFistFile +
|
||||
GetDiskFreeSpaceExA+
|
||||
|
||||
FindFirstFile +
|
||||
FindNextFile +
|
||||
|
||||
GetFileTime+
|
||||
|
||||
CompareFileTime+
|
||||
|
||||
SetVolumeLabel+
|
||||
|
||||
CreatDirectory+
|
||||
RemoveDirectory+
|
||||
|
||||
MoveFile +
|
||||
DeleteFile +
|
||||
*/
|
||||
@@ -1,116 +0,0 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <locale.h>
|
||||
#include <conio.h>
|
||||
|
||||
|
||||
TCHAR szDrive[] = _T(" A:");
|
||||
|
||||
int main()
|
||||
{
|
||||
setlocale(LC_ALL, "ru_RU.UTF8");
|
||||
SetConsoleOutputCP(65001);
|
||||
SetConsoleCP(65001);
|
||||
|
||||
|
||||
//getKeyboardState();
|
||||
//getKeyState();
|
||||
//getAsyncKeyState();
|
||||
setclipCursor();
|
||||
//swapMouseButton();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getKeyboardState() {
|
||||
BYTE keystate[256]; static prevKeys[256];
|
||||
if (GetKeyboardState(keystate))
|
||||
wprintf(L"Успешно получен статус клавиш\n");
|
||||
else
|
||||
wprintf(L"Не получен статус клавиш\n");
|
||||
|
||||
wprintf(L"Статус левой кнопки мыши: ");
|
||||
if ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0)
|
||||
wprintf(L"Активна \n");
|
||||
else
|
||||
wprintf(L"Неактивна\n");
|
||||
|
||||
wprintf(L"Статус левго CONTROL: ");
|
||||
if ((GetAsyncKeyState(VK_LCONTROL) & 0x8000) != 0)
|
||||
wprintf(L"Активен\n");
|
||||
else
|
||||
wprintf(L"Неактивен\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getKeyState() {
|
||||
while (TRUE)
|
||||
{
|
||||
SHORT keyState = GetKeyState(VK_SPACE);
|
||||
//if (keyState & 0x8000)
|
||||
if (keyState)
|
||||
{
|
||||
system("cls");
|
||||
wprintf(L"Нажат Пробел");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getAsyncKeyState() {
|
||||
POINT pt;
|
||||
while (TRUE) {
|
||||
if (GetAsyncKeyState(VK_LBUTTON) & 1)
|
||||
{
|
||||
system("cls");
|
||||
wprintf(L"Нажата левая кнопка мыши\n");
|
||||
GetCursorPos(&pt);
|
||||
wprintf(L"Коорднаты курсора: %d,%d\n", pt.x, pt.y);
|
||||
}
|
||||
if (GetAsyncKeyState(VK_RBUTTON) & 1)
|
||||
{
|
||||
system("cls");
|
||||
wprintf(L"Нажата правая кнопка мыши\n");
|
||||
GetCursorPos(&pt);
|
||||
wprintf(L"Коорднаты курсора: %d,%d\n", pt.x, pt.y);
|
||||
}
|
||||
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) {
|
||||
system("cls");
|
||||
wprintf(L"Нажат Выход");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setclipCursor() {
|
||||
wprintf(L"Ограничение курсора: включено\n");
|
||||
SetCaretBlinkTime(1000);
|
||||
SetCursorPos(0, 0);
|
||||
RECT r;
|
||||
char string[10] = "";
|
||||
r.left = 100;
|
||||
r.top = 100;
|
||||
r.right = 200;
|
||||
r.bottom = 200;
|
||||
ClipCursor(&r);
|
||||
wprintf(L"Для снятия ведите любой символ с клавиатуры\n");
|
||||
scanf(" %s", string);
|
||||
ClipCursor(NULL);
|
||||
//SetCaretBlinkTime(1000);
|
||||
wprintf(L"Ограничение курсора: выключено\n");
|
||||
return 0;
|
||||
}
|
||||
int swapMouseButton() {
|
||||
wprintf(L"Метрика перестановки кнопок мыши: %d\n",GetSystemMetrics(SM_SWAPBUTTON));
|
||||
SwapMouseButton(TRUE);
|
||||
wprintf(L"Метрика перестановки кнопок мыши: %d\n", GetSystemMetrics(SM_SWAPBUTTON));
|
||||
char string[10] = "";
|
||||
wprintf(L"Для отмены ведите любой символ с клавиатуры\n");
|
||||
scanf(" %s", string);
|
||||
SwapMouseButton(FALSE);
|
||||
wprintf(L"Метрика перестановки кнопок мыши: %d\n", GetSystemMetrics(SM_SWAPBUTTON));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user