如何改变C ++中的freeglut主窗口图标? [英] How to change freeglut main window icon in C++?
问题描述
我有一个用C ++编写的DLL,它使用FreeGlut可视化一些数据。我想改变主(自由)过剩窗口的图标。
我看过这是不可能的,但在我看到的文档中:
GLUT_ICON - 指定进入freeglut窗口左上角的图标。
如何更改图标
确定,我这样做:
- 为项目创建资源并添加一个32x32图标(编辑或导入)。此图标的ID等于
IDI_ICON1
。 - 包含resource.h文件。 );
HWND hwnd = FindWindow(NULL,_T(VIZ)); //可能你可以用不同的方式获得窗口处理程序。
现在得到图标 - 它在你的DLL文件中,IDI_ICON1 id,所以我们使用:
HANDLE icon = LoadImage(GetModuleHandle(_T(NAME_OF_YOUR_DLL)),MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,32,32,LR_COLOR);
//你也可以准备第二个,较小的(16x16)图标 - 它在标题栏看起来更好。
// ...
现在将此消息发送到窗口。
SendMessage(hwnd,(UINT)WM_SETICON,ICON_BIG,(LPARAM)icon);
就是这样!也许一些清洁将是很好。
此解决方案不需要部署.ico文件。如果您愿意,可以通过以下方式忽略资源文件和加载图标:
icon = LoadImage(GetModuleHandle(),_T ico),IMAGE_ICON,32,32,LR_LOADFROMFILE | LR_COLOR);
您还可以使用 LoadIcon 函数,但是不能选择图标大小。
手册:
LoadImage
SendMessage
LoadIcon
编辑:
我认为这不是最好的解决方案,所以欢迎你写你的。也许使用 GLUT_ICON
?
I have a DLL written in C++ that uses FreeGlut to visualize some data. I want to change the icon of the main (free)glut window.
I've read that it is impossible, but in the docs I see:
GLUT_ICON - specifies the icon that goes in the upper left-hand corner of the freeglut windows.
How can I change icon for (free)glut window, if possible?
OK, I did it:
- Create a Resource for the project and add an 32x32 icon (edit it or import). This icon will get the ID equal to
IDI_ICON1
. - Include the "resource.h" file.
Create the glut window like this:
glutCreateWindow("VIZ"); HWND hwnd = FindWindow(NULL, _T("VIZ") ); //probably you can get the window handler in different way..
Now get the icon - it is in your DLL file, with IDI_ICON1 id, so we use:
HANDLE icon = LoadImage(GetModuleHandle(_T("NAME_OF_YOUR_DLL")), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_COLOR );
//You can also prepare second, smaller (16x16) icon - it looks better in title bar.
//...
Now send this message to the Window.
SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)icon);
That's it! Probably some cleaning would be nice.
This solution does not require to deploy .ico file. If you prefer you can ommit resource file and load icon with:
icon = LoadImage(GetModuleHandle(), _T("icon.ico"), IMAGE_ICON, 32, 32, LR_LOADFROMFILE | LR_COLOR);
You can also use LoadIcon function, but then you can't select icon size.
Manuals: LoadImage SendMessage LoadIcon
Edit:
I think it's not the best solution, so you're welcome to write yours. Maybe using GLUT_ICON
?
这篇关于如何改变C ++中的freeglut主窗口图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!