且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为我的应用和按钮分配图标?

更新时间:2023-02-09 14:41:08

1。假设.rc被编译并且.res链接,它可能是Windows缓存图标的旧问题,并且在更新/链接目标时不显示正确的图标。两个想法来检验这个假设; 1.在资源管理器中选择exe上的属性。这可以从中提取正确的图标。 2.将exe复制到一个新名称,看看是否也无法显示图标。



2.查看LoadIcon的文档(也许还有LoadImage) )。你确实可以获得系统提供的图标至少前者的HICON。


1。检查图标文件是否在当前目录中,并且也是资源脚本中的第一个 ICON 条目。



2.只要在主代码中使用相同的名称,就可以在脚本中使用任何预定义的资源值。您还应确保您自己的任何定义都不使用与预定义名称相同的值。


Hi at all,

I’ve two questions to icons in a Visual Studio 2012 Win-Forms C++/CLI project:

1.) I’ve created "MyIcon.ico" and added it to app’s resource files:

App.rc:
IDI_MAIN ICON " MyIcon.ico"

resource.h:
#define IDI_MAIN 1

But my application shows the VS standard icon instead of mine.

2.) I’ve a form with a ToolStrip and a ToolStripButton and I’ve assigned an icon (Save.bmp) to my button. But isn’t there a possibility to assign predefined Windows standard icons to my controls?
In the app’s resource file there are shown lots of predefined (but not used) read-only symbols, e.g. ID_FILE_SAVE. But how to assign this ID (icon) to my button?

Thanx
Volker

1. Assuming the .rc is compiled and the .res linked, it could be the old problem of Windows caching icons, and not displaying the right icon when updating/linking a target. Two ideas to test that hypothesis; 1. select Properties on the exe in Explorer. That could extract the correct icon from it. 2. Copy the exe to a new name and see if that also fails to display the icon.

2. Have a look at the documentation for LoadIcon (maybe also LoadImage). You can indeed get a HICON for the system-provided icons frmo at least the former.


1. Check that the icon file is in the current directory, and is also the first ICON entry in the resource script.

2. You may use any of the predefined resource values in your scripts, as long as you use the same names in your main code. You should also ensure that any of your own definitions do not use the same values as the predefined names.