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

发布于 2024-08-21 09:16:33 字数 200 浏览 5 评论 0原文

如何在C中设置控制台窗口标题?

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

这只适用于linux,不适用于windows。

有人知道“跨平台”解决方案吗? (当然不是 system ( title=blah )

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 ))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

偏爱自由 2024-08-28 09:16:33

windows.h 定义 SetConsoleTitle()

您可以在任何地方使用它,并为 Linux 平台声明您自己的函数来执行相同的操作。

windows.h defines SetConsoleTitle().

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

只是一片海 2024-08-28 09:16:33

听起来类似于这个帖子:(这是针对 Java 的,但接受的答案使用 JNI [即 C Native 调用]。

如何从命令行 Java 应用程序更改命令提示符(控制台)窗口标题?

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?

故人如初 2024-08-28 09:16:33

您可以通过调用 SetConsoleTitle 来执行此操作。

You can do this by calling SetConsoleTitle.

久夏青 2024-08-28 09:16:33

也许您必须自己实施“跨游戏形式”解决方案。

对于 Windows 2000+,您可以使用 SetConsoleTitle(),更多信息可以在 MSDN

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

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

老子叫无熙 2024-08-28 09:16:33

在 C 中实现此目的的最简单方法是使用 windows.h 标头并使用 SetConsoleTitle 函数

简单脚本

#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;

}

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;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文