explaination coding for my viva!!! urgent!!!

This is a discussion on explaination coding for my viva!!! urgent!!! within the C++ Programming forums, part of the General Programming Boards category; hello all!!! i need your help to explain these codes for me because i may need to viva soon....thanks!!! 1.) ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    15

    Question explaination coding for my viva!!! urgent!!!

    hello all!!! i need your help to explain these codes for me because i may need to viva soon....thanks!!!

    1.) here are codes, i am using arrow keys to control my menu...as i know the 72 is for arrow key up and 80 is for arrow key down. but y do need the function below that add 256 to my arrows code???

    Code:
    int get_code ( void )
    {
      int ch = getch();
     if ( ch == 0 || ch == 224 )
               ch = static_cast<int>(256 + getch());
      return ch;
    }
    while ( ( ch = get_code() ) != 27 )
    {
    switch ( ch ) {
    case 256 + 72://arrow key up}
    }

    2. )i also use the code below to change the particular line of my program to make it look more attractive. but i dun really understand wat does the handle h mean. wat is the h??

    Code:
    int main ( void )
    {
      HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );//line 1
      WORD wOldColorAttrs;//line2
      CONSOLE_SCREEN_BUFFER_INFO csbiInfo; //line3
      
        GetConsoleScreenBufferInfo(h, &csbiInfo);//line4
      wOldColorAttrs = csbiInfo.wAttributes; //line5
      
       SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
      
      printf ( "This is a test\n" );
    
      SetConsoleTextAttribute ( h, FOREGROUND_BLUE| FOREGROUND_INTENSITY );
      
      printf ( "This is a test\n" );
       SetConsoleTextAttribute ( h, wOldColorAttrs);
      return 0;
    }
    is anyone out there can explain line 1, 2, 3, 4 and 5 for me?? thanks!!

    thanks guys first.....ur guys will give me a big help on my viva....thanks!!!

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    1. getch() returns 0 the first time called when a special key is presses, such as arrow and function keys. When that happens the program must call getch() a second time to get the actual key code. If get_code() simply returned that key code, the calling function would have no way to distinguish arrow keys from any other key. There are a couple (maybe more) ways to handle that, and get_code() adds 256 to special key code. Now the calling function only needs to check if its return value > 256 to determine whether the key was a special key or not. If 72 is an up arrow, then get_code() will return 256+72.

    2. HANDLE is a data type defined in windows.h. Apparently you are completly new to MS-Windows win32 api programming, so I would suggest reading this tutorial before continuing. win32 api programming is just simply too difficult and complicated to spoonfood in these forums.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21