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

标签 c winapi

这次还有一个简单的问题:我处理 UI 内容的 DLL 有一个 uninit() function that should be called before the program terminates that frees all resources (注销窗口类、删除私有(private)堆等)。卸载使用 LoadIcon/Cursor(NULL, IDI) 加载的 IDI_APPLICATIONIDC_ARROW 和其他系统图标和光标所需的调用是什么/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.

关于c - 如何释放标准图标和光标(使用 LoadIcon/Cursor(NULL, IDI/IDC_WHATEVER) 加载的图标和光标)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30603077/

相关文章:

c - 在 c 中具有字符元素的结构中复制字符串的方法

c - realloc() 后出现段错误。无法将分配的内存分配给指针

c - Valgrind 错误

c++ - 如何修复 CopyFile() 错误 5 - 访问被拒绝错误

winapi - 锁定文件但允许当前进程使用?

winapi - VB6 从 IP 查找主机名,指定 DNS 服务器

c - 在 C 中以较高索引开始数组

更改 char* 数组中元素的地址? C

c++ - 如何正确 Hook WM_COMMAND

c++ - UnhookWindowsHookEx() 期间崩溃