Thread: This snippet of code, help me to finish it well.

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    112

    This snippet of code, help me to finish it well.

    This snippet of code, help me to finish it well.

    This code is taken completely from the site. I do not understand him at all. Functions are declared, but not registered. What is this? Are these functions not system, not library? Why are they not described?
    It looks like a pathetic snippet of code.

    If possible, can you finish it?


    Code:
    #include <windows.h>
    
    VOID MouseEventProc(MOUSE_EVENT_RECORD);
    VOID ResizeEventProc(WINDOW_BUFFER_SIZE_RECORD);
    VOID KeyEventProc(KEY_EVENT_RECORD);
    VOID GetInputEvents(VOID);
    
    int main()
    {
        HANDLE hStdin;
        DWORD cNumRead, fdwMode, fdwSaveOldMode, i;
        INPUT_RECORD irInBuf[128];
    
        // Получим стандартный дескриптор ввода.
    
        hStdin = GetStdHandle(STD_INPUT_HANDLE);
        if (hStdin == INVALID_HANDLE_VALUE)
            MyErrorExit("GetStdHandle");
    
        // Сохраним текущий режим ввода для будущего восстановления при
        // выходе из программы.
    
        if (! GetConsoleMode(hStdin, &fdwSaveOldMode) )
            MyErrorExit("GetConsoleMode");
    
        // Включим события ввода от мыши и окна.
    
        fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
        if (! SetConsoleMode(hStdin, fdwMode) )
            MyErrorExit("SetConsoleMode");
    
        // Цикл чтения и обработки событий ввода.
    
        while (1)
        {
    
        // Ожидание событий.
    
            if (! ReadConsoleInput(
                    hStdin,      // дескриптор буфера ввода
                    irInBuf,     // буфер, в котором читаем
                    128,         // размер буфера чтения
                    &cNumRead) ) // число прочитанных записей
                MyErrorExit("ReadConsoleInput");
    
       // Направляем события соответствующим обработчикам.
    
            for (i = 0; i < cNumRead; i++)
            {
                switch(irInBuf[i].EventType)
                {
                    case KEY_EVENT: // ввод с клавиатуры
                        KeyEventProc(irInBuf[i].Event.KeyEvent);
                        break;
    
                    case MOUSE_EVENT: // ввод от мыши
                        MouseEventProc(irInBuf[i].Event.MouseEvent);
                        break;
    
                    case WINDOW_BUFFER_SIZE_EVENT: // изменение размера
                                                   // экранного буфера
                        ResizeEventProc(
                            irInBuf[i].Event.WindowBufferSizeEvent);
                        break;
    
                    case FOCUS_EVENT:  // игнорирование событий фокуса
    
                    case MENU_EVENT:   // игнорирование событий меню
                        break;
    
                    default:
                        MyErrorExit("unknown event type");
                        break;
                }
            }
        }
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Yes, those function definitions are missing and need to be provided. It's not really possible for someone to complete them for you since it's up to you (or the original author) to decide what you want them to do.

    However, the code seems to have been (badly) copied from here, so perhaps those definitions will do. In fact, you're probably best to toss out the code you have and just use the code from the MS site.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is this code snippet wrong
    By jeff loomis in forum C Programming
    Replies: 4
    Last Post: 01-15-2014, 09:06 PM
  2. what will be the output of this code snippet
    By devilofwar in forum C Programming
    Replies: 12
    Last Post: 12-13-2010, 05:41 PM
  3. Explanation of code snippet
    By Jelte in forum C++ Programming
    Replies: 1
    Last Post: 01-20-2010, 06:59 AM
  4. C code snippet which I need help understanding
    By c_me in forum C Programming
    Replies: 3
    Last Post: 07-28-2006, 06:06 AM
  5. a great little code snippet...
    By skeptik in forum Windows Programming
    Replies: 1
    Last Post: 09-24-2002, 11:45 PM

Tags for this Thread