  PROGRAM dcct
  USE ISO_C_BINDING, ONLY : C_INTPTR_T, C_INT16_T
  USE IFWIN,         ONLY : T_CONSOLE_SCREEN_BUFFER_INFO, GetConsoleWindow, GetStdHandle, STD_OUTPUT_HANDLE, &
                            GetConsoleScreenBufferInfo, FOREGROUND_RED, FOREGROUND_INTENSITY, SetConsoleTextAttribute
  IMPLICIT none
!
  INTEGER                            :: iResult
  INTEGER(KIND=C_INTPTR_T)           :: hConsole
  INTEGER(KIND=C_INTPTR_T)           :: hOutput
  INTEGER(KIND=C_INT16_T)            :: wAttributes_original
  INTEGER(KIND=C_INT16_T)            :: wAttributes_red_bold
  TYPE(T_CONSOLE_SCREEN_BUFFER_INFO) :: csbi
!
! get the console handle, the output handle, and the initial console attributes
!
  hConsole              = GetConsoleWindow()
  hOutput               = GetStdHandle(STD_OUTPUT_HANDLE)
  iResult               = GetConsoleScreenBufferInfo(hOutput, csbi)
  wAttributes_original  = csbi%wAttributes
!
!  write a line in the original col,.or
!
  WRITE(*,*) 'line with the original attributes'
!
! set the console attrbutes to bold red; write a red line 
!
  wAttributes_red_bold = IANY([FOREGROUND_RED, FOREGROUND_INTENSITY])
  iResult = SetConsoleTextAttribute(hOutput, wAttributes_red_bold)
  write(*,*) 'red line'
!
!  restore the console attributes to the original one
!
  iResult = SetConsoleTextAttribute(hOutput, wAttributes_original)
  write(*,*) 'line with the original attributes'
!
  STOP
  END PROGRAM