Home > OS >  How to get Icon of Current Active Window in C Sharp?
How to get Icon of Current Active Window in C Sharp?

Time:09-21

As we can get the title of active window in c sharp using method ActiveWindowTitle(). Now I need to get The icon of above same window. how can I do that?

CodePudding user response:

If you find a foreground window

GetForegroundWindow(

you can find out its process ID

GetWindowThreadProcessId(

and for that process, the file path

process.MainModule;

then just use the function

Icon ico = Icon.ExtractAssociatedIcon (executablPath);

See for example: enter image description here

  • Related