Click here to Skip to main content
15,888,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am developing an Visual C++ application in windows console mode, I want to set my console text in to Bold and Italic form. I changed console text color and background color using SetConsoleTextAttribute function and system("COLOR XX") functions. But there is no Win32 API function to changed text mode in to BOLD, Italic or Stroke. Please mention any function or mechanism to achieve it within C/C++ programming boundary in Windows enviornment? Thank you.

What I have tried:

I was struggling with SetConsoleTextAttribute WinAPI function
Posted
Updated 15-Jan-18 11:44am

For bold you might set FOREGROUND_INTENSITY with SetConsoleTextAttribute.
But there is no support for italic and strike (besides changing the console font which affects all characters).

In the old MS-DOS days such was realised using ANSI escape sequences. These are now back with Windows 10.

If you use an actual Windows 10, see Console Virtual Terminal Sequences (Windows)[^].

But unfortunately italic (ESC[3m) and strike through (ESC[9m) are not supported.

If you really need these modes you must probably use additional software like GitHub - adoxa/ansicon: Process ANSI escape sequences for Windows console programs.[^] after checking if it supports italic and strike through (I have not checked it for the above).
 
Share this answer
 
Comments
Buddhi Chaturanga 31-Jan-17 9:49am    
Thank you for the fine answer :D
You can't. The console doesn't support "bold" or "italic" text.
 
Share this answer
 
Comments
Buddhi Chaturanga 31-Jan-17 9:49am    
Thank you for the reply :D
For bold you can use this function
#include <iostream>

std::ostream& bold_on(std::ostream& os)
{
return os << "\e[1m";
}

std::ostream& bold_off(std::ostream& os)
{
return os << "\e[0m";
}


int main()
{
std::cout << bold_on << "bold" << bold_off << " non-bold" << std::endl;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900