Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09ba73446a | ||
|
|
4425899e31 | ||
|
|
3491a43380 |
@@ -1,263 +1,169 @@
|
|||||||
#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 вариант
|
||||||
//GetLogicalDriverStrings V
|
//GetKeyboardType V
|
||||||
//GetDriveType V
|
//GetKeyboardStateV
|
||||||
//GetCurrentDirectoryV
|
//GetAsyncKeyStateV
|
||||||
//GetFileAttributesV
|
//GetCursorPosV
|
||||||
//GetSystemDirectoryV
|
//SetKeyboardStateV
|
||||||
//GetTempPathV
|
//GetSystemParametersInfoV
|
||||||
//SetCurrentDirectoryV
|
//SetKeyboardStateV
|
||||||
//SetFileAttributesV
|
//SetCaretBlinkTimeV
|
||||||
//CreateFileV
|
//ClipCursor
|
||||||
//ReadFileV
|
//SetSystemParametersInfoV
|
||||||
//WriteFileV
|
|
||||||
|
|
||||||
// for path use this: D:\c\lab1
|
int getKeyboardType(){
|
||||||
// for attributeChekc use: D:\c\lab1\text.txt
|
setlocale(LC_ALL, "Rus");
|
||||||
int getAllDisk(){
|
printf("Keyboard type: ");
|
||||||
DWORD dwSize = MAX_PATH;
|
switch(GetKeyboardType(0)){
|
||||||
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("Drive does not exist.\n");
|
printf(" 83-key keyboard for IBM PC/XT-compatible computers\n");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("Removable media.\n");
|
printf("102-key Olivetti keyboard\n");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf("Fixed disk.\n");
|
printf("IBM PC/AT-compatible keyboard (84 keys)\n");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
printf("Network drive.\n");
|
printf("Extended IBM keyboard (101- or 102 keys)\n");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
printf("CD-ROM drive.\n");
|
printf(" Nokia 1050 Keyboard\n");
|
||||||
break;
|
break;
|
||||||
}
|
case 6:
|
||||||
// get the next drive
|
printf("Nokia 9140 Keyboard\n");
|
||||||
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;
|
break;
|
||||||
case FILE_ATTRIBUTE_COMPRESSED:
|
case 7:
|
||||||
printf("Compressed\n");
|
printf("Japanese keyboard\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;
|
|
||||||
case 6 :
|
|
||||||
SetFileAttributes(path,FILE_ATTRIBUTE_READONLY);
|
|
||||||
break;
|
|
||||||
case 7 :
|
|
||||||
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 writeFile(char path[],char message[]){
|
int getKeyboardState(BYTE massive[256]){
|
||||||
DWORD bytesWritten;
|
|
||||||
HANDLE hFile = CreateFile(path, FILE_WRITE_ACCESS, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_ALWAYS, 0, NULL);
|
|
||||||
WriteFile(hFile, message, strlen(message), &bytesWritten, NULL);
|
if (GetKeyboardState(massive) == 0)
|
||||||
|
{
|
||||||
|
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 readFile(char path[]){
|
int getAsyncKeyState(){
|
||||||
char readBuffer[256];
|
int i = 0;
|
||||||
DWORD bytesRead;
|
printf("Please, press CONTROL\n");
|
||||||
|
while (i != 1){
|
||||||
HANDLE fh = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
if (GetAsyncKeyState(VK_CONTROL) != 0){
|
||||||
|
i = 1;
|
||||||
if(fh!=INVALID_HANDLE_VALUE){
|
printf("Control pressed\n");
|
||||||
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