简体   繁体   English

如何设置c控制台窗口标题

[英]How to set c console window title

How to set the console window title in C?如何在 C 中设置控制台窗口标题?

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

This works only under linux, not in windows.这仅适用于 linux,不适用于 windows。

Does anybody know a "cross-platform" solution?有人知道“跨平台”解决方案吗? (of course not system ( title=blah ) ) (当然不是system ( title=blah )

windows.h defines SetConsoleTitle() . windows.h定义了SetConsoleTitle()

You could use that everywhere, and declare your own function for linux platforms that does the same thing.你可以在任何地方使用它,并为做同样事情的 linux 平台声明你自己的函数。

Sounds similar to this posting: (Which is for Java, but the accepted answer uses JNI [ie a C Native call].听起来类似于这篇文章:(这是针对 Java 的,但接受的答案使用 JNI [即 C 本机调用]。

How to change command prompt (console) window title from command line Java app? 如何从命令行 Java 应用程序更改命令提示符(控制台)窗口标题?

您可以通过调用SetConsoleTitle来做到这一点

Maybe you have to implement a "cross-playform" solution yourself.也许您必须自己实施“跨游戏形式”解决方案。

For windows 2000+, you can use SetConsoleTitle(), more imformation can be found on MSDN .对于 windows 2000+,您可以使用 SetConsoleTitle(),更多信息可以在MSDN上找到。

The most easy way to achieve this in C is to use windows.h header and use the SetConsoleTitle function在 C 中实现此目的的最简单方法是使用windows.h标头并使用SetConsoleTitle 函数

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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM