Getting the icon associated with a running application using WinAPI

How can I get the icon of the running application if I know Hwnd?

+2


source to share


2 answers


Once you have a handle to the window, you can use GetClassLong :



HICON icon = (HICON)GetClassLong(window, GCL_HICON);

      

+2


source


You have a hwnd, you can get the process id using WINAPI GetWindowThreadProcessId. With this, you can create a C # Process object. Then you can iterate through the ProcessModule Collection process to get the name of the executable. Finally, you can use the WINAPI function ExtractIconEx to get the icon from the path

Pinvoke has information on two WINAPI methods



http://www.pinvoke.net/default.aspx/user32/GetWindowThreadProcessId.html

http://www.pinvoke.net/default.aspx/shell32/ExtractIconEx.html

0


source







All Articles