Добавил:
Yanus
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:lab5
.cpp#include <stdio.h>
#include <windows.h>
int main()
{
HANDLE hstdout, hInputFile, hstdin;
COORD pos;
WORD attr=0x2e;
DWORD actlen;
int posInText;
bool bResult;
char buffer[2000];
WORD wOldColorAttrs;
_CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
INPUT_RECORD charinfo;
hstdout=GetStdHandle(STD_OUTPUT_HANDLE);
hstdin=GetStdHandle(STD_INPUT_HANDLE);
if ((hstdout==INVALID_HANDLE_VALUE)|(hstdin==INVALID_HANDLE_VALUE))
{printf("Error GetStdHandle \n"); return(1);}
SetConsoleMode(hstdin, ENABLE_MOUSE_INPUT);
GetConsoleScreenBufferInfo(hstdout, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
hInputFile = CreateFile("test.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
bResult = ReadFile(hInputFile, buffer, 2000, &actlen, NULL);
if (bResult == false)
{
printf("Error when read from file occured");
return(1);
}
CloseHandle(hInputFile);
WriteConsole(hstdout, buffer, actlen, &actlen, NULL);
do
{
ReadConsoleInput(hstdin, &charinfo, 1, &actlen);
if ((charinfo.EventType==MOUSE_EVENT)&(charinfo.Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED))
{
posInText = charinfo.Event.MouseEvent.dwMousePosition.X;
pos.X = 0;
pos.Y = charinfo.Event.MouseEvent.dwMousePosition.Y;
ReadConsoleOutputCharacter(hstdout, buffer, csbiInfo.dwSize.X, pos, &actlen);
int i, j;
for (i = posInText - 1; (i > 0)&(buffer[i - 1] != ' '); i--);
for (j = i + 1; (j < actlen)&(buffer[j] != ' '); j++);
pos.Y = 30;
pos.X = 24;
SetConsoleTextAttribute(hstdout, attr);
SetConsoleCursorPosition(hstdout, pos);
WriteConsole(hstdout, " ", 15, &actlen, NULL);
SetConsoleCursorPosition(hstdout, pos);
WriteConsole(hstdout, &buffer[i], j-i, &actlen, NULL);
SetConsoleTextAttribute(hstdout, wOldColorAttrs);
}
}
while (!((charinfo.EventType==MOUSE_EVENT)&&(charinfo.Event.MouseEvent.dwButtonState==RIGHTMOST_BUTTON_PRESSED)));
SetConsoleTextAttribute(hstdout, wOldColorAttrs);
return 0;
}
Соседние файлы в предмете Операционные системы