slickdeveloper
slickdeveloper

Reputation: 121

What is the appropriate way to access common ("stock") icons in Windows?

Most operating systems tend to use a common set of "stock" icons for indicating "warning", "error", and other states. And most of us know that we should not grovel into undocumented resources and use them in our application.

However, in GTK, it is possible to retrieve these icons because the toolkit provides documented APIs to do so. In Windows, while it is possible to extract a limited set of icons from the appropriate DLLs, this is undocumented and not guaranteed to work in future versions of Windows. Icons provided by an API are a contract; icons stored in a DLL are an implementation detail.

Is there any Windows (or .NET 4) API function to retrieve a "stock icon"? I know that for file associations, one could grovel the registry to locate the DefaultIcon entry, but this wouldn't take into account custom icon handlers, and it is not a solution for other stock icons such as the ones used in warning or error message boxes.

If there is no such functionality, what would be the most future-proof way to use these icons in my application? Or do I just have to do all the work myself and worry about Microsoft changing the implementation details in a future version of Windows?

Upvotes: 1

Views: 267

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308530

You can use LoadIcon or LoadImage to load stock icons. Microsoft recommends LoadImage but doesn't document the icons you can load, only pointing you to a .h file that contains the list.

Upvotes: 2

Related Questions