如何释放标准图标和光标(加载 LoadIcon/Cursor(NULL, IDI/IDC_WHATEVER) 的图标和光标)?

How do I free the standard icons and cursors (those loaded with LoadIcon/Cursor(NULL, IDI/IDC_WHATEVER))?

这次是另一个快速问题:我处理 UI 内容的 DLL 有一个 uninit() function that should be called before the program terminates that frees all resources(注销 window 类、删除私有堆等)。卸载IDI_APPLICATIONIDC_ARROW和其他加载LoadIcon/Cursor(NULL, IDI/IDC_WHATEVER)的系统图标和光标需要调用什么?我可以从 MSDN 收集到的最接近的信息是 DeleteObject() 不应在这些图标上调用;在那种情况下没有这样的功能吗?谢谢。

您没有卸载系统定义的图标或光标。例如,documentation for DestroyIcon 明确表示(强调):

It is only necessary to call DestroyIcon for icons and cursors created with the following functions: CreateIconFromResourceEx (if called without the LR_SHARED flag), CreateIconIndirect, and CopyIcon. Do not use this function to destroy a shared icon. A shared icon is valid as long as the module from which it was loaded remains in memory. The following functions obtain a shared icon.

  • LoadIcon
  • LoadImage (if you use the LR_SHARED flag)
  • CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter is a shared icon)
  • CreateIconFromResource
  • CreateIconFromResourceEx (if you use the LR_SHARED flag)

以上明确指出,不应破坏使用 LoadIcon() 获取的图标。 documentation for DestroyCursor:

中也有同样的说法

Destroys a cursor and frees any memory the cursor occupied. Do not use this function to destroy a shared cursor.