Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Change icon for console applications

madsplinter
Beginner
5,031 Views

Hi there, I have a simple question:
Assuming that I already have an .ICO file, how do I change the program icon for a console application?

0 Kudos
26 Replies
jirina
New Contributor I
862 Views

Jan, did you forget attaching the source files? Or don't I just see them?

0 Kudos
jirina
New Contributor I
862 Views

I started having problem with setting the icon for my console application. Everything worked well, but for some reason (could it be Update 2 of IVF Studio?) it does not work anymore, even though I did not change anything in the respective code that reads:

      use ifwin
      use iso_c_binding
      
      pointer SetConsoleIcon
      interface
        integer function SetConsoleIcon ( hIcon )
        !dec$ attributes default, stdcall :: SetConsoleIcon
        use iso_c_binding
        integer(kind=c_intptr_t) :: hIcon
        end function SetConsoleIcon
      end interface
      
      integer(kind=c_intptr_t) :: hMainMod, hLib, hIcon, SetConsoleIcon_Address
      integer,parameter :: IDI_ICON_REDOX=101
      integer :: iResult
      
      hMainMod = GetModuleHandle ( NULL )
      hIcon = LoadIcon ( hMainMod, IDI_ICON_REDOX )
      hLib = LoadLibrary ( "Kernel32.dll"//C_NULL_CHAR )
      
      SetConsoleIcon_Address = GetProcAddress ( hLib, "SetConsoleIcon"//C_NULL_CHAR )
      call C_F_PROCPOINTER(TRANSFER(SetConsoleIcon_Address, C_NULL_FUNPTR), SetConsoleIcon)
      
      iResult = SetConsoleIcon ( hIcon )

I verified that I have the icon IDI_ICON_REDOX in my resources and that no changes were done for this part of the code. Am I missing something?

0 Kudos
andrew_4619
Honored Contributor III
862 Views

Have you changed windows version? SetConsoleIcon is not a documented API in Kernel32 so it may disappear without warning at some future windows release.

 

0 Kudos
jirina
New Contributor I
862 Views

No, I have not changed Windows 7 Pro 64-bit since 4 years ago. Or do you mean also Service Packs?

If I am using an undocumented API, is there an official and documented way how to change the console window's icon?

0 Kudos
Robert_van_Amerongen
New Contributor III
862 Views

I have recompiled a program that is similar to the one that I send with #16 and that runs fine under Windows 8.1, 64 bits. So it is still in the SDK. I am not aware of an "official" method to change the console icon that is different from the "illegal" SetConsoleIcon.

Robert

 

0 Kudos
jirina
New Contributor I
862 Views

I used your approach from #16 and it worked well, but is does not work now and I could not figure out why. Checking Resources.rc showed that resource.h is included and I had a wrong name for the icon resource in the #define statement. Correcting this line in resource.h got everything work well again.

Thank you for your tests and kid support; I appreciate it.

0 Kudos
Reply