1 Commits
Author SHA1 Message Date
stud126211 09b4fd67b9 add README 2023-09-28 07:31:01 +00:00
2 changed files with 229 additions and 134 deletions
+1
View File
@@ -0,0 +1 @@
Ветка с 1 лабороторной работотй по C
+227 -133
View File
@@ -1,169 +1,263 @@
#include <stdio.h>
#include <windows.h>
#include <stdio.h>
#include <locale.h>
#include <conio.h>
//4 вариант
//GetKeyboardType V
//GetKeyboardStateV
//GetAsyncKeyStateV
//GetCursorPosV
//SetKeyboardStateV
//GetSystemParametersInfoV
//SetKeyboardStateV
//SetCaretBlinkTimeV
//ClipCursor
//SetSystemParametersInfoV
//сделать применение функций
//GetLogicalDriverStrings V
//GetDriveType V
//GetCurrentDirectoryV
//GetFileAttributesV
//GetSystemDirectoryV
//GetTempPathV
//SetCurrentDirectoryV
//SetFileAttributesV
//CreateFileV
//ReadFileV
//WriteFileV
int getKeyboardType(){
setlocale(LC_ALL, "Rus");
printf("Keyboard type: ");
switch(GetKeyboardType(0)){
// for path use this: D:\c\lab1
// for attributeChekc use: D:\c\lab1\text.txt
int getAllDisk(){
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:
printf(" 83-key keyboard for IBM PC/XT-compatible computers\n");
printf("Drive does not exist.\n");
break;
case 2:
printf("102-key Olivetti keyboard\n");
printf("Removable media.\n");
break;
case 3:
printf("IBM PC/AT-compatible keyboard (84 keys)\n");
printf("Fixed disk.\n");
break;
case 4:
printf("Extended IBM keyboard (101- or 102 keys)\n");
printf("Network drive.\n");
break;
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;
case 6 :
printf("Nokia 9140 Keyboard\n");
SetFileAttributes(path,FILE_ATTRIBUTE_READONLY);
break;
case 7 :
printf("Japanese keyboard\n");
SetFileAttributes(path,FILE_ATTRIBUTE_SYSTEM);
break;
default:
printf("Error or unknown keyboard type\n");
break;
}
getFileAttribute(path);
return 0;
}
int getKeyboardState(BYTE massive[256]){
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");
}
int writeFile(char path[],char message[]){
DWORD bytesWritten;
HANDLE hFile = CreateFile(path, FILE_WRITE_ACCESS, FILE_SHARE_READ,
NULL, OPEN_ALWAYS, 0, NULL);
WriteFile(hFile, message, strlen(message), &bytesWritten, NULL);
return 0;
}
int getAsyncKeyState(){
int i = 0;
printf("Please, press CONTROL\n");
while (i != 1){
if (GetAsyncKeyState(VK_CONTROL) != 0){
i = 1;
printf("Control pressed\n");
int readFile(char path[]){
char readBuffer[256];
DWORD bytesRead;
HANDLE fh = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
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;
}
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;
}