c - 如何在 C 中向我的控制台程序添加图标?

标签 c winapi icons

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

int main()
{
   SetConsoleTitle("MathTable Gen [beta]");
   system("color 17");
   system("mode 55,40");
   int num,x;
   printf("\n\t\tGenerate table of : ");
   scanf("%d",&num);
   if (num <=1000)
   {
        for (x=0;x<=10;x=x+1)
   {
    printf("\n\t%d\tx\t%d\t=\t%d\n\n",num,x,num*x);
   }
printf("\n           Created by : Naveen Niraula !");
}
else
{
    system("mode 70,15");
    SetConsoleTitle("MathTable Gen [beta] - Error!");
    system("cls");
    printf("\n\n\n\n\n  You either entered an invalid number or entered a value too big !\n\n\t \t  \tBetter try again. :)");
    printf("\n\n\n\t\t    Created by : Naveen Niraula !");
    getch();
    return;
}
getch();
return();
}

好的,这是我学习了一点之后的第一个 C 程序。
现在我唯一的问题是如何将 ICON 添加到我的程序中? 哦,我正在使用 Code::Blocks 作为我的 C IDE。我希望有人能帮我清关?

最佳答案

要添加图标,您需要使用以下条目编写资源脚本 (.rc)

IDI_ICON1               ICON                    "myIcon.ico"

这会将 myIcon 文件添加到您的应用程序中。 然后需要使用资源编译器 (rc.exe) 编译 rc 文件,您应该在默认编译器安装文件夹中找到它。这会生成一个 .res 文件,您可以将该文件与程序的其他目标文件一起传递给链接器。

更多信息请引用以下链接: about resource files

可以下载SDK包中的资源编译器here

关于c - 如何在 C 中向我的控制台程序添加图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25322462/

相关文章:

C 从文件中读取,它读取 "@"

c++ - win32 c++ 中的停靠窗口

file - 如何获得自己的文件格式的文件以具有自己的动态图标?

c# - 以编程方式更改 WPF 中的按钮图标

c++ - C 与 C++ 为什么这个宏不扩展为常量?

在 C 中将字符数组和 const char 指针组合成单个 const char*

C:评估字符串的一部分

winapi - 多次调用 CryptHashData

c++ - 将位填充(位移位?)添加到存储在字节数组中的 10 位值

tree - 更改 PrimeNG 树中的展开和折叠图标