home *** CD-ROM | disk | FTP | other *** search
-
- #include <windows.h>
-
- #define SCRSIZE 80*25
-
- void ClearConsole(void);
- int ConsCoordPuts(char *pszString, COORD dwWriteCoord);
-
- //
- // ClearConsole
- // Clears the console wind (SCRSIZE only)
- //
- void ClearConsole(void)
- {
- HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- DWORD dwWritten;
- COORD cCoordinate;
-
- cCoordinate.X = 0;
- cCoordinate.Y = 0;
- FillConsoleOutputCharacter(hOutput, ' ', SCRSIZE, cCoordinate, &dwWritten);
- FillConsoleOutputAttribute(hOutput,
- FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
- SCRSIZE, cCoordinate, &dwWritten);
- }
-
-
- //
- // ConsCoordPuts:
- // Print a string to StdOut at a given coordinate on the console
- //
- int ConsCoordPuts(char *pszString, COORD dwWriteCoord)
- {
- DWORD nLen = strlen(pszString);
- DWORD nWritten;
- HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- BOOL bRet;
-
- bRet = WriteConsoleOutputCharacter(hOutput,
- pszString, nLen, dwWriteCoord, &nWritten);
- return (!bRet || (nWritten != nLen)) ? 0 : nLen;
- }
-
-
-
- int main(int argc, char *argv[])
- {
- WORD nAttribute = FOREGROUND_GREEN | BACKGROUND_RED
- | BACKGROUND_GREEN | BACKGROUND_BLUE,
- nAttrArray[SCRSIZE],
- nIdx;
- HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
- char *pszString = "Welcome to the attribute console program.";
- DWORD dwWritten;
- DWORD nLen = strlen(pszString);
- COORD cCoordinate;
-
- // Clear the screen
- ClearConsole();
-
- // Print welcome message
- cCoordinate.X = 0;
- cCoordinate.Y = 10;
- ConsCoordPuts(pszString, cCoordinate);
-
- // Create an attribute array to write from then do it
- for(nIdx = 0; nIdx < SCRSIZE; nIdx++)
- {
- nAttrArray[nIdx] = nAttribute;
- }
- WriteConsoleOutputAttribute(hOutput,
- nAttrArray, nLen, cCoordinate, &dwWritten);
-
- return 0;
- }
-
-
-
-