如何在任务栏中更改应用的缩略图? SFML 2.4

时间:2017-04-14 18:18:47

标签: visual-c++ sfml

有人知道如何在SFML 2.4中更改或制作缩略图

1 个答案:

答案 0 :(得分:2)

可以在SFML文档页面here.上快速找到解决方案 sf :: RenderWindow :: setIcon()方法可以为应用程序窗口提供一个图标,但实际图标必须由指向像素数组的指针表示。

这可以通过创建.rc头文件和包含像素数组的.c文件来实现。可以使用GIMP的“C-Source图像转储”功能创建阵列。

示例:

.rc文件:

//icon.rc
IDR_APP_ICON ICON "icon.ico"
GLUT_ICON ICON "icon.ico"

.c文件:

//icon.c

/* GIMP RGBA C-Source image dump (icon.c) */

static const struct {
  unsigned int   width;
  unsigned int   height;
  unsigned int   bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ 
  unsigned char  pixel_data[32 * 32 * 4 + 1];
} gimp_image = {
  32, 32, 4,
  "k\177h\377k\177h\377\377\377\377\0\377\377\377\0\377\377\377\0\204`\236\201"`

//The array pixel array would continue here until }; closing the struct.

然后,生成的struct对象可以作为参数传递给setIcon()方法。

sf::RenderWindow::setIcon(gimp_image.width, gimp_image.height, gimp_image.pixel_data);

icon.c文件应该包含在main.cpp文件中,或者将图标设置为RenderWindow。

相关问题