home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / Chapter4 / 4-6 / RGBex.c
Encoding:
C/C++ Source or Header  |  2000-07-17  |  1.8 KB  |  79 lines

  1.  
  2. #include <windows.h>
  3.  
  4. #define SCRSIZE 80*25
  5.  
  6. void ClearConsole(void);
  7. int ConsCoordPuts(char *pszString, COORD dwWriteCoord);
  8.  
  9. //
  10. // ClearConsole
  11. //    Clears the console wind (SCRSIZE only)
  12. //
  13. void ClearConsole(void)
  14. {
  15.     HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  16.     DWORD dwWritten;
  17.     COORD cCoordinate;
  18.  
  19.     cCoordinate.X = 0;
  20.     cCoordinate.Y = 0;
  21.     FillConsoleOutputCharacter(hOutput, ' ', SCRSIZE, cCoordinate, &dwWritten);
  22.     FillConsoleOutputAttribute(hOutput,
  23.        FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
  24.        SCRSIZE, cCoordinate, &dwWritten);
  25. }
  26.  
  27.  
  28. //
  29. // ConsCoordPuts:
  30. //    Print a string to StdOut at a given coordinate on the console
  31. //
  32. int ConsCoordPuts(char *pszString, COORD dwWriteCoord)
  33. {
  34.     DWORD nLen = strlen(pszString);
  35.     DWORD nWritten;
  36.     HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  37.     BOOL bRet;
  38.  
  39.     bRet = WriteConsoleOutputCharacter(hOutput,
  40.            pszString, nLen, dwWriteCoord, &nWritten);
  41.      return (!bRet || (nWritten != nLen)) ? 0 : nLen;
  42. }
  43.  
  44.  
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.     WORD nAttribute = FOREGROUND_GREEN | BACKGROUND_RED
  49.                     | BACKGROUND_GREEN | BACKGROUND_BLUE,
  50.          nAttrArray[SCRSIZE],
  51.          nIdx;
  52.     HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  53.     char *pszString = "Welcome to the attribute console program.";
  54.     DWORD dwWritten;
  55.     DWORD nLen = strlen(pszString);
  56.     COORD cCoordinate;
  57.  
  58.     // Clear the screen
  59.     ClearConsole();
  60.  
  61.     // Print welcome message
  62.     cCoordinate.X = 0;
  63.     cCoordinate.Y = 10;
  64.     ConsCoordPuts(pszString, cCoordinate);
  65.  
  66.     // Create an attribute array to write from then do it
  67.     for(nIdx = 0; nIdx < SCRSIZE; nIdx++)
  68.     {
  69.         nAttrArray[nIdx] = nAttribute;
  70.     }
  71.     WriteConsoleOutputAttribute(hOutput,
  72.       nAttrArray, nLen, cCoordinate, &dwWritten);
  73.  
  74.      return 0;
  75. }
  76.  
  77.  
  78.  
  79.