LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI RT printf Color

Hey,

 

I was curious if there was a way with CVI RT to change the output color for printf in a similar way that this VI works:

 

https://decibel.ni.com/content/docs/DOC-14012

 

Thanks,

Kevin Key

0 Kudos
Message 1 of 6
(3,692 Views)

Hey Kevin -

 

This should do the trick for you:

 

#include <windows.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <rtutil.h>

int foregroundColors[] = {
  FOREGROUND_GREEN,
  FOREGROUND_BLUE,
  FOREGROUND_RED,
  FOREGROUND_GREEN|FOREGROUND_BLUE,
  FOREGROUND_GREEN|FOREGROUND_RED,
  FOREGROUND_BLUE|FOREGROUND_RED,
  FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED,
  FOREGROUND_GREEN|FOREGROUND_INTENSITY,
  FOREGROUND_BLUE|FOREGROUND_INTENSITY,
  FOREGROUND_RED|FOREGROUND_INTENSITY,
  FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY,
  FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY,
  FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY,
  FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY,
  0};

void CVIFUNC_C RTmain (void)
{
  HANDLE hStdOut;
  int i;

  if (InitCVIRTE (0, 0, 0) == 0)
    return; /* out of memory */

  hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);

  for (i = 0; foregroundColors[i]; i++) {
    SetConsoleTextAttribute (hStdOut, foregroundColors[i]);
    printf ("sample string\n");
  }

  CloseCVIRTE ();
}

 

For more information, check out this MSDN page.

 

NickB

National Instruments

0 Kudos
Message 2 of 6
(3,680 Views)

Is there a way to add the windows library to in CVI?

0 Kudos
Message 3 of 6
(3,677 Views)

These particular functions are actually added and linked automatically.  Take a look at this help topic for more information.

 

NickB

National Instruments

0 Kudos
Message 4 of 6
(3,675 Views)

I meant the like function tree and help menu to the IDE?

0 Kudos
Message 5 of 6
(3,673 Views)

Unfortunately, there is no function tree for the Win32 API in CVI, and you must consult MSDN for documentation.

 

NickB

National Instruments

0 Kudos
Message 6 of 6
(3,668 Views)