How to set title for your console application window.
![]()
In huge frameworks, there might be a number of back-end servers running. Since they are servers most of them might be implemented as windows console applications to avoid gui overheads. But when you run the console, the title of the console window will be the path of console.exe.
Since there can be multiple console applications, One of the headache is to identify which console window is the server you are searching for? Usually we print logs in console such as “Image Server Started…” to identify which server it is. It will be nice, if we can set the console window title our own. So that we can easly identify the server application.
![]()
You can use the function – SetConsoleTitle(). Its straight forward. Just call the function by passing the preferred console title. See the code snippet below.
int main(int argc, char* argv[])
{
// Set the console title of my Image Server.
SetConsoleTitle( "Image Server." );
// Let me see the result.
getchar();
return 0;
}
![]()
The SetConsoleTitle() is declared in wincon.h. But you just include windows.h which includes everything.
![]()
Targeted Audience – Beginners.
Thank you very much! I wanted to know how to do this with Dev-C++, turns out all you have to do is use this code and include the Windows header file
Thanks! I was looking all over the web for this info.
Always welcome buddy. Keep watching.
Regards,
Jijo.
Sry dude the sample does not work on my XP laptop (not even with the proper includes). Please advice, my code below:
#include
#include
#include
using namespace std;
int main(int argc, char* argv[])
{
// Set the console title of my Image Server.
SetConsoleTitle( “Image Server.” );
// Let me see the result.
getchar();
return 0;
Sry the last } in the code was missing in my previous comment ( copy paste mistake) above, but it is not the issue I get the error : cannot convert parameter 1 from ‘const char [14]‘ to ‘LPCWSTR’
Hi Kurt,
I think you’re using visual studio 2005 or latest. In that by default, UNICODE will be enabled. So modify your code snippet like this,
SetConsoleTitle( _T(
Thanks, man! It was exactly what I was looking for! Helped me a lot.
Thanks, its so convenient, I wish all C++ was this easy…
Okay,I wonder how to set Window title from Filename?