• Welcome to Valhalla Legends Archive.
 

Win32 Console - FillConsoleOutputAttribute?

Started by Eli_1, April 25, 2004, 06:30 PM

Previous topic - Next topic

Eli_1

I saw a console app, Half-Life's HLTV, display a little green banner at the top of the window that displays data. The data constantly changes and doesn't move from the top.

I researched this some and I think the way to do it is with FillConsoleOutputAttribute, but I can't get it working. Can anyone explain how to do this to me?

Eli_1

#1
I got it working.
Code:

#include <windows.h>
#include <wincon.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>

void writeLine(LPCTSTR lpString, WORD wColor, int X, int Y, DWORD dwSize) {
   HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
   COORD coord;
   DWORD cWritten;
   coord.X = X;
   coord.Y = Y;
   char ctmp = ' ';
   FillConsoleOutputCharacter(hStdout, ctmp, dwSize, coord, &cWritten);
   FillConsoleOutputAttribute(hStdout, wColor, dwSize, coord, &cWritten);
   WriteConsoleOutputCharacter(hStdout, lpString, strlen(lpString), coord, &cWritten);
}
int main() {
   clrscr();
   for (int i=0; i<50; i++) {
      printf("test3\n");
      writeLine("test", BACKGROUND_GREEN, 0, 0, 50);
      writeLine("test2", BACKGROUND_RED, 0, 1, 50);
      Sleep(100);
   }

   return 0;
}


Output:
   Legend:
   !!! = Green Background
   III = Red Background
Quote
Test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Test2IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
test3
test3
test3
test3
...

Anyone know of a better way of doing this?