0

Say I have some third-party Windows application running and displaying multiple windows. And all these windows have different icons. In my application I want to get a bitmap image of the icon used in any window of that application, given I have a window handle (HWND). This should be done dynamically, at runtime. How can this be done?

IInspectable
  • 46,945
  • 8
  • 85
  • 181
ivan.ukr
  • 2,853
  • 1
  • 23
  • 41
  • Note that WinAPI is plain c, please. – πάντα ῥεῖ Aug 28 '23 at 16:19
  • 2
    @πάνταῥεῖ The [WIL](https://github.com/microsoft/wil) is C++, though, and it is a very popular library for consuming the Win32 API. Plus, some parts of the API surface cannot reasonably be accessed from C (such as Direct2D). Nothing wrong with having the [tag:c++] tag here. – IInspectable Aug 28 '23 at 16:53
  • 1
    @ivan.ukr have you looked at [`WM_GETICON`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-geticon) yet? – Remy Lebeau Aug 28 '23 at 18:17
  • How about [EnumResource*(Ex)\[A/W\]](https://learn.microsoft.com/en-us/windows/win32/menurc/enumerating-resources) functions? – YangXiaoPo-MSFT Aug 29 '23 at 08:11
  • @RemyLebeau Yes, I've seen WM_GETICON, but the whole question - does it work for the case when window that I will send it to is from another process? – ivan.ukr Aug 29 '23 at 10:03
  • @YangXiaoPo-MSFT How does EnumResourceXXX will help? Please elaborate a bit more. You can even write answer if you think you have it. – ivan.ukr Aug 29 '23 at 14:17
  • 2
    @ivan.ukr supposedly yes (I haven't tried it). See this code: https://groups.google.com/g/microsoft.public.win32.programmer.ui/c/m9J7O_sIA1E/m/0EG-UUe8tFEJ – Remy Lebeau Aug 29 '23 at 14:44
  • @RemyLebeau yup, it works. – ivan.ukr Aug 29 '23 at 16:47
  • @ivan.ukr what led me to that code is [this discussion](https://microsoft.public.vc.mfc.narkive.com/6l3OUc6A/get-icon-of-another-application). [This answer](https://stackoverflow.com/a/24052117/65863) also helped, too. – Remy Lebeau Aug 30 '23 at 00:32
  • @ivan.ukr, Would you answer yourself? – YangXiaoPo-MSFT Aug 30 '23 at 01:14

0 Answers0