Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
4 Views

Change icon for console applications 2

Jump to solution

This is a continuation of this topic: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/276032

I had been using the code in that topic to change icons for a couple years but recently got a new computer/OS/VS/IVF and the code no longer works.  Initially when i opened the resource file (ci.rc) in visual studio i received an error that rcdll.dll could not be found in "C:\Program Files (x86)\Windows Kits\10\bin\x86", so i copied it from "C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86" to that location and the error went away.

I now have:

Windows 10 Pro

Microsoft Visual Studio Community 2017
Version 15.2 (26430.13) Release
VisualStudio.15.Release/15.2.0+26430.13
Microsoft .NET Framework
Version 4.6.01586

Visual C++ 2017   00369-60000-00001-AA511

Microsoft Visual C++ 2017

Intel® Advisor 2017 Update 3   

Intel® Advisor 2017 Update 3, (build 510716), Copyright © 2009-2017 Intel Corporation. All rights reserved.

Intel® Inspector 2017 Update 3   
Intel® Inspector 2017 Update 3, (build 510645), Copyright © 2009-2017 Intel Corporation. All rights reserved.

Intel® Parallel Studio XE 2017 Update 4 Composer Edition for C++ Windows*   Package ID: w_comp_lib_2017.4.210
Intel® Parallel Studio XE 2017 Update 4 Composer Edition for C++ Windows* Integration for Microsoft* Visual Studio* 2017, Version 17.0.76.15, Copyright © 2002-2017 Intel Corporation. All rights reserved.
* Other names and brands may be claimed as the property of others.

Intel® Parallel Studio XE 2017 Update 4 Composer Edition for Fortran Windows*   Package ID: w_comp_lib_2017.4.210
Intel® Parallel Studio XE 2017 Update 4 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2017, Version 17.0.0047.15, Copyright © 2002-2017 Intel Corporation. All rights reserved.
* Other names and brands may be claimed as the property of others.

Here is the code:

SUBROUTINE ci(i)
! Interface to the SetConsoleIcon function
USE ISO_C_BINDING
USE IFWIN
IMPLICIT NONE

INTEGER(WORD), INTENT(IN) :: i										! index of ico to load
POINTER SetConsoleIcon

INTERFACE
INTEGER FUNCTION SetConsoleIcon(hIcon)
!DEC$ ATTRIBUTES DEFAULT, STDCALL :: SetConsoleIcon
USE ISO_C_BINDING
INTEGER(KIND=C_INTPTR_T) :: hIcon
ENDFUNCTION SetConsoleIcon
END INTERFACE

!----------------------------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------- begin define local variables ------------------------------------------------------------
INTEGER(KIND=HANDLE) :: hMainMod									! the handle of the executable
INTEGER(KIND=HANDLE) :: hIcon										! the handle of the icon
INTEGER(KIND=HANDLE) :: hLib										! the handle of the library that contains the function
INTEGER(KIND=HANDLE) :: SetConsoleIcon_Address						! the address of the function
INTEGER(KIND=HANDLE) ::	iResult
!------------------------------------------------------------ end define local variables ------------------------------------------------------------
!----------------------------------------------------------------------------------------------------------------------------------------------------

! Obtain the module handle; the icon handle, the library handle
hMainMod = GetModuleHandle(NULL)
!hIcon = LoadIcon(hMainMod, i)
hIcon = LoadIcon(hMainMod, MAKEINTRESOURCE(i))
hLib = LoadLibrary("Kernel32.dll"//C_NULL_CHAR)

! obtain the address to the function and obtain the function itself
SetConsoleIcon_Address = GetProcAddress(hLib, "SetConsoleIcon"//C_NULL_CHAR)
CALL C_F_PROCPOINTER(TRANSFER(SetConsoleIcon_Address, C_NULL_FUNPTR), SetConsoleIcon)

! display the console with the new icon
iResult = SetConsoleIcon(hIcon)

ENDSUBROUTINE ci

 

When i run it i don't get any errors, but the icon doesn't change anymore (like it did before the hardware/software changes).  Here are the LHS values at the end of this sub on my new machine:

        hMainMod    140699780251648    INTEGER(8)
        hIcon    40244361    INTEGER(8)
        hLib    140730640760832    INTEGER(8)
        SetConsoleIcon_Address    140730641171104    INTEGER(8)
        iResult    0    INTEGER(4)

And here they are on my old machine:

        hMainMod          5366677504         INTEGER(8)

        hIcon     -1977796927       INTEGER(8)

        hLib       2004287488         INTEGER(8)

        SetConsoleIcon_Address             2004552288         INTEGER(8)

        iResult  1              INTEGER(4)

 

It seems an iResult of 1 is success and 0 is failure.  The LHS values for some of the calls seem to be many orders of magnitude larger on the new machine than the old.  Maybe it's time to stop using 32bit stuff?  Any ideas?

thanks,

rob

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor II
4 Views

hIcon = LoadIcon(

Jump to solution
        hIcon    =  LoadIcon( ghInstance, MAKEINTRESOURCE(int(IDI_ICON2,word)))
        hConsole = GetConsoleWindow()
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_SMALL,KIND=fWPARAM), hIcon)
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_BIG,KIND=fWPARAM),   hIcon)

You don't need to load library for kernel32, I found SetConsoleIcon unreliable and use the sendmessage method.

View solution in original post

0 Kudos
5 Replies
Highlighted
Valued Contributor II
5 Views

hIcon = LoadIcon(

Jump to solution
        hIcon    =  LoadIcon( ghInstance, MAKEINTRESOURCE(int(IDI_ICON2,word)))
        hConsole = GetConsoleWindow()
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_SMALL,KIND=fWPARAM), hIcon)
        lres     = SendMessage(hConsole, WM_SETICON, INT(ICON_BIG,KIND=fWPARAM),   hIcon)

You don't need to load library for kernel32, I found SetConsoleIcon unreliable and use the sendmessage method.

View solution in original post

0 Kudos
Highlighted
Beginner
4 Views

Thank you andrew! it works

Jump to solution

Thank you andrew! it works now.

I did some searching with what you provided which turned up this: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/721841

0 Kudos
Highlighted
Beginner
4 Views

I have an intel fortran

Jump to solution

I have an intel fortran project for a console program, and it used to apply a custom icon to the exe.  Earlier this year I had to remake the Visual Studio (2010) project because it had become corrupted, and the remade project (vfproj) doesn't do the icon trick.  There is a folder in the project containing the following files:

icon1.ico
resource.fd
resource.h
Script1.aps
Script1.rc
Somehow, these files must have something to do with the icon trick.  Can someone tell me what to do with them?

Thanks,

Brian M.

0 Kudos
Highlighted
Beginner
4 Views

I got the icon to work.

Jump to solution

I got the icon to work. Yippee!  In VS2010 I did "Add new item" and added Script1.rc and icon1.ico to the list of source files.  Rebuilt and now I got the icon. Rebuilding created a new file Debug\Script1.res and this file was in the list of linked files. 

The first line of the file Script1.rc says //Microsoft Developer Studio generated resource script.

I'm lucky I had this file, because I don't how to create it.  This file contains the name of the icon file icon1.ico.

0 Kudos
Highlighted
Black Belt
4 Views

If you add a resource (such

Jump to solution

If you add a resource (such as an icon) using the menus, the .rc will be created automatically.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos