Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09b4fd67b9 |
@@ -1,169 +1,263 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <locale.h>
|
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
//4 вариант
|
//сделать применение функций
|
||||||
//GetKeyboardType V
|
//GetLogicalDriverStrings V
|
||||||
//GetKeyboardStateV
|
//GetDriveType V
|
||||||
//GetAsyncKeyStateV
|
//GetCurrentDirectoryV
|
||||||
//GetCursorPosV
|
//GetFileAttributesV
|
||||||
//SetKeyboardStateV
|
//GetSystemDirectoryV
|
||||||
//GetSystemParametersInfoV
|
//GetTempPathV
|
||||||
//SetKeyboardStateV
|
//SetCurrentDirectoryV
|
||||||
//SetCaretBlinkTimeV
|
//SetFileAttributesV
|
||||||
//ClipCursor
|
//CreateFileV
|
||||||
//SetSystemParametersInfoV
|
//ReadFileV
|
||||||
|
//WriteFileV
|
||||||
|
|
||||||
int getKeyboardType(){
|
// for path use this: D:\c\lab1
|
||||||
setlocale(LC_ALL, "Rus");
|
// for attributeChekc use: D:\c\lab1\text.txt
|
||||||
printf("Keyboard type: ");
|
int getAllDisk(){
|
||||||
switch(GetKeyboardType(0)){
|
DWORD dwSize = MAX_PATH;
|
||||||
|
char szLogicalDrives[MAX_PATH] = {0};
|
||||||
|
WORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);
|
||||||
|
if (dwResult > 0 && dwResult <= MAX_PATH)
|
||||||
|
{
|
||||||
|
char* szSingleDrive = szLogicalDrives;
|
||||||
|
while(*szSingleDrive)
|
||||||
|
{
|
||||||
|
printf("Drive: %s\n", szSingleDrive);
|
||||||
|
|
||||||
|
// get the next drive
|
||||||
|
szSingleDrive += strlen(szSingleDrive) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int getDriveType(){
|
||||||
|
DWORD dwSize = MAX_PATH;
|
||||||
|
char szLogicalDrives[MAX_PATH] = {0};
|
||||||
|
WORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);
|
||||||
|
if (dwResult > 0 && dwResult <= MAX_PATH)
|
||||||
|
{
|
||||||
|
char* szSingleDrive = szLogicalDrives;
|
||||||
|
while(*szSingleDrive)
|
||||||
|
{
|
||||||
|
printf("Drive: %s", szSingleDrive);
|
||||||
|
switch(GetDriveType(szSingleDrive)){
|
||||||
|
case 0:
|
||||||
|
printf("Error.\n");
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf(" 83-key keyboard for IBM PC/XT-compatible computers\n");
|
printf("Drive does not exist.\n");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("102-key Olivetti keyboard\n");
|
printf("Removable media.\n");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf("IBM PC/AT-compatible keyboard (84 keys)\n");
|
printf("Fixed disk.\n");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
printf("Extended IBM keyboard (101- or 102 keys)\n");
|
printf("Network drive.\n");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
printf(" Nokia 1050 Keyboard\n");
|
printf("CD-ROM drive.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// get the next drive
|
||||||
|
szSingleDrive += strlen(szSingleDrive) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int getCurrentDirectory(){
|
||||||
|
DWORD dwSize = MAX_PATH;
|
||||||
|
char szLogicalDrives[MAX_PATH] = {0};
|
||||||
|
WORD dwResult = GetCurrentDirectory(dwSize,szLogicalDrives);
|
||||||
|
if (dwResult > 0 && dwResult <= MAX_PATH)
|
||||||
|
{
|
||||||
|
char* szSingleDrive = szLogicalDrives;
|
||||||
|
|
||||||
|
printf("CurrentDirectory: %s\n", szSingleDrive);
|
||||||
|
|
||||||
|
// get the next drive
|
||||||
|
//szSingleDrive += strlen(szSingleDrive) + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
int getFileAttribute(char path[]){
|
||||||
|
|
||||||
|
switch(GetFileAttributes(path)){
|
||||||
|
case FILE_ATTRIBUTE_ARCHIVE:
|
||||||
|
printf("Archived.\n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_COMPRESSED:
|
||||||
|
printf("Compressed\n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_DIRECTORY:
|
||||||
|
printf("FolderName\n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_HIDDEN :
|
||||||
|
printf("hidden\n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_NORMAL:
|
||||||
|
printf("Normal \n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_READONLY :
|
||||||
|
printf("readOnly\n");
|
||||||
|
break;
|
||||||
|
case FILE_ATTRIBUTE_SYSTEM :
|
||||||
|
printf("systemFile\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int getSystemDirectory(){
|
||||||
|
DWORD dwSize = MAX_PATH;
|
||||||
|
char szLogicalDrives[MAX_PATH] = {0};
|
||||||
|
WORD dwResult = GetSystemDirectory(szLogicalDrives,dwSize);
|
||||||
|
if (dwResult > 0 && dwResult <= MAX_PATH)
|
||||||
|
{
|
||||||
|
char* szSingleDrive = szLogicalDrives;
|
||||||
|
|
||||||
|
printf("SystemDirectory: %s\n", szSingleDrive);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
int getTempPath(){
|
||||||
|
DWORD dwSize = MAX_PATH;
|
||||||
|
char szLogicalDrives[MAX_PATH] = {0};
|
||||||
|
WORD dwResult = GetTempPath(dwSize,szLogicalDrives);
|
||||||
|
if (dwResult > 0 && dwResult <= MAX_PATH)
|
||||||
|
{
|
||||||
|
char* szSingleDrive = szLogicalDrives;
|
||||||
|
|
||||||
|
printf("TempPath: %s\n", szSingleDrive);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int setCurrentDirectory(char path[]){
|
||||||
|
SetCurrentDirectory(path);
|
||||||
|
getCurrentDirectory();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int setFileAttribute(char path[],int attribute){
|
||||||
|
switch(attribute){
|
||||||
|
case 1:
|
||||||
|
SetFileAttributes(path,FILE_ATTRIBUTE_ARCHIVE);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SetFileAttributes(path,FILE_ATTRIBUTE_COMPRESSED);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
SetFileAttributes(path,FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
break;
|
||||||
|
case 4 :
|
||||||
|
SetFileAttributes(path,FILE_ATTRIBUTE_HIDDEN);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
SetFileAttributes(path,FILE_ATTRIBUTE_NORMAL);
|
||||||
break;
|
break;
|
||||||
case 6 :
|
case 6 :
|
||||||
printf("Nokia 9140 Keyboard\n");
|
SetFileAttributes(path,FILE_ATTRIBUTE_READONLY);
|
||||||
break;
|
break;
|
||||||
case 7 :
|
case 7 :
|
||||||
printf("Japanese keyboard\n");
|
SetFileAttributes(path,FILE_ATTRIBUTE_SYSTEM);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Error or unknown keyboard type\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
getFileAttribute(path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int getKeyboardState(BYTE massive[256]){
|
int writeFile(char path[],char message[]){
|
||||||
|
DWORD bytesWritten;
|
||||||
|
HANDLE hFile = CreateFile(path, FILE_WRITE_ACCESS, FILE_SHARE_READ,
|
||||||
|
NULL, OPEN_ALWAYS, 0, NULL);
|
||||||
if (GetKeyboardState(massive) == 0)
|
WriteFile(hFile, message, strlen(message), &bytesWritten, NULL);
|
||||||
{
|
|
||||||
printf("KS - Error\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("KS - notError\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (massive[VK_CONTROL] & 0x80)
|
|
||||||
{
|
|
||||||
printf("CONTROL has been pressed\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("CONTROL not been pressed\n");
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int getAsyncKeyState(){
|
int readFile(char path[]){
|
||||||
int i = 0;
|
char readBuffer[256];
|
||||||
printf("Please, press CONTROL\n");
|
DWORD bytesRead;
|
||||||
while (i != 1){
|
|
||||||
if (GetAsyncKeyState(VK_CONTROL) != 0){
|
HANDLE fh = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
i = 1;
|
|
||||||
printf("Control pressed\n");
|
if(fh!=INVALID_HANDLE_VALUE){
|
||||||
|
printf("File opened for reading!\n");
|
||||||
|
} else {
|
||||||
|
printf("File not opened for reading!\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ReadFile(fh, readBuffer, sizeof(readBuffer), &bytesRead, NULL)){
|
||||||
|
printf("File successfully read!\n");
|
||||||
|
printf("%lu bytes read.\n", bytesRead);
|
||||||
|
printf("%s\n", readBuffer);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int getCursorPos(){
|
|
||||||
POINT pt;
|
|
||||||
|
|
||||||
if (GetCursorPos(&pt) == 0){
|
|
||||||
printf("CP - Error\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("CP - notError\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int setKeyboardState(){//переделать
|
|
||||||
BYTE state[256];
|
|
||||||
state[VK_CONTROL] = 0x80;
|
|
||||||
SetKeyboardState(state);
|
|
||||||
getKeyboardState(state);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int systemParametersInfo(){//передалтьV
|
|
||||||
PVOID parametr;
|
|
||||||
UINT uint;
|
|
||||||
if (SystemParametersInfo(SPI_GETBEEP, uint, parametr, uint) ==0)
|
|
||||||
{
|
|
||||||
printf("SPI - Error\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("SPI - notError\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int setSystemParametrsInfo(){
|
|
||||||
PVOID parametr;
|
|
||||||
UINT uint;
|
|
||||||
if (SystemParametersInfo(SPI_SETMOUSEBUTTONSWAP, 1, parametr, uint) == 0){
|
|
||||||
printf("SPI - SetError\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("SPI - SetNotError\n");
|
|
||||||
}
|
|
||||||
getAsyncKeyState();
|
|
||||||
SystemParametersInfo(SPI_SETMOUSEBUTTONSWAP, 0, parametr, uint);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
int setCarietBlinkTime(){
|
|
||||||
if (SetCaretBlinkTime(1000) == 0){
|
|
||||||
printf("CBT - Error\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("CBT - notError\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int clipCursour(){//переделатьV
|
|
||||||
RECT rcOldClip;
|
|
||||||
RECT rcNewClip;
|
|
||||||
GetClipCursor(&rcOldClip);
|
|
||||||
|
|
||||||
rcNewClip.bottom = 100;
|
|
||||||
rcNewClip.left = 100;
|
|
||||||
rcNewClip.top = 100;
|
|
||||||
rcNewClip.right = 200;
|
|
||||||
|
|
||||||
ClipCursor(&rcNewClip);
|
|
||||||
getAsyncKeyState();
|
|
||||||
ClipCursor(&rcOldClip);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
int main() {
|
int main() {
|
||||||
|
printf("GetAllDisk:\n");
|
||||||
|
getAllDisk();
|
||||||
|
|
||||||
|
printf("GetDriveType:\n");
|
||||||
|
getDriveType();
|
||||||
|
|
||||||
|
printf("GetCurrentDirectory:\n");
|
||||||
|
getCurrentDirectory();
|
||||||
|
|
||||||
|
printf("GetFileAttribute:\n");
|
||||||
|
char userInput[MAX_PATH];
|
||||||
|
printf("Input path\n");
|
||||||
|
// scanf("%260s",userInput);
|
||||||
|
//getFileAttribute( userInput);
|
||||||
|
|
||||||
|
printf("GetSystemDirectory:\n");
|
||||||
|
getSystemDirectory();
|
||||||
|
|
||||||
|
printf("GetTempPath:\n");
|
||||||
|
getTempPath();
|
||||||
|
|
||||||
|
printf("SetCurrentDirectory:\n");
|
||||||
|
|
||||||
|
printf("Input path\n");
|
||||||
|
//scanf("%260s",userInput);
|
||||||
|
//setCurrentDirectory(userInput);
|
||||||
|
printf("SetFileAttribute\n");
|
||||||
|
printf("Input path\n");
|
||||||
|
//scanf("%260s",userInput);
|
||||||
|
int userChoice;
|
||||||
|
printf("choise attribute:\n 1-archive\n2-compressed\n3-directory\n4-hidden\n5-normal\n6-readonly\n7-system\n");
|
||||||
|
//scanf("%d",&userChoice);
|
||||||
|
//setFileAttribute(userInput,userChoice);
|
||||||
|
|
||||||
|
printf("CreateFile:\n");
|
||||||
|
printf("Input path\n");
|
||||||
|
//scanf("%260s",userInput);
|
||||||
|
// createFile(userInput);
|
||||||
|
|
||||||
|
printf("WriteFile:\n");
|
||||||
|
printf("Input path\n");
|
||||||
|
//scanf("%260s",userInput);
|
||||||
|
char userMessage[1024];
|
||||||
|
printf("Input text that you want write to file\n");
|
||||||
|
//scanf("%1024s",userMessage);
|
||||||
|
//writeFile(userInput,userMessage);
|
||||||
|
|
||||||
|
printf("ReadFile:\n");
|
||||||
|
scanf("%260s",userInput);
|
||||||
|
readFile(userInput);
|
||||||
|
|
||||||
BYTE massive[256];
|
|
||||||
setlocale(LC_ALL, "Rus");
|
|
||||||
getKeyboardType();
|
|
||||||
getKeyboardState(massive);
|
|
||||||
getCursorPos();
|
|
||||||
setKeyboardState();
|
|
||||||
systemParametersInfo();
|
|
||||||
setCarietBlinkTime();
|
|
||||||
setSystemParametrsInfo();
|
|
||||||
//clipCursour();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user