user197967
user197967

Reputation:

How to set c console window title

How to set the console window title in C?

printf("%c]0;%s%c", '\033', "My Console Title", '\007');

This works only under linux, not in windows.

Does anybody know a "cross-platform" solution? (of course not system ( title=blah ))

Upvotes: 8

Views: 13877

Answers (5)

Federico Baù
Federico Baù

Reputation: 7695

The most easy way to achieve this in C is to use windows.h header and use the SetConsoleTitle function

Simple Script

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

int main() 
{
    HANDLE handleConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTitle("Mini Desktop App"); // Here add the title of the window
    while(1){
        printf("Works as expected\n");
        printf("Press any Key to exit :)\n");
        getch();
        break;
    }

    return 0;

}

Upvotes: 0

XUE Can
XUE Can

Reputation: 701

Maybe you have to implement a "cross-playform" solution yourself.

For windows 2000+, you can use SetConsoleTitle(), more imformation can be found on MSDN.

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564611

You can do this by calling SetConsoleTitle.

Upvotes: 0

Anon.
Anon.

Reputation: 59993

windows.h defines SetConsoleTitle().

You could use that everywhere, and declare your own function for linux platforms that does the same thing.

Upvotes: 6

monojohnny
monojohnny

Reputation: 6181

Sounds similar to this posting: (Which is for Java, but the accepted answer uses JNI [ie a C Native call].

How to change command prompt (console) window title from command line Java app?

Upvotes: 0

Related Questions