Software Archive
Read-only legacy content
17061 Discussions

Icon with a console app?

Intel_C_Intel
Employee
686 Views
Is it possible to associate an icon with a console app, to get rid of that awful default icon?
0 Kudos
3 Replies
gchien
Beginner
686 Views
1. Create an icon file (e.g. hello.ico) in which there should be a 32x32 pixel icon and a 16x16 one. You can use any icon editor to do it, but I normally use the one that came with Visual Studio.
2. Create a resource file (e.g. hello.rc) containing only one line:
0 ICON hello.ico

Now, if you are using the IDE, simply insert the hello.rc file into the project and rebuilt. If you are using the command line, you need to:
3. compile the resource file by: rc -r hello.rc to create hello.res
4. link your files with hello.res: DF hello.f90 hello.res

The icon will be shown in the Explorer and when the program is run outside the IDE. When the program is executed in the IDE, the "awful default" icon will still be used.

HTH,
Greg Chien
http://protodesign-inc.com
0 Kudos
Intel_C_Intel
Employee
686 Views
If you want to replace the 'awful default' icon in the console app's title bar also, you can use the method described in this past post with a few minor changes. Something like this would do:
 
    ! ... 
    integer :: hWnd, hIcon, hr  
 
    include 'resource.fd'     
 
    hWnd = 0 
    hWnd = GetForegroundWindow() 
 
    hIcon = 0;  hr = 0 
    hIcon = LoadImage(GetModuleHandle(%val(0)), %val(MAKEINTRESOURCE(IDI_ICON1)), IMAGE_ICON, & 
                      GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); 
    if(hIcon /= 0) then  
       hr = SendMessage(hWnd, WM_SETICON, ICON_SMALL, hIcon); 
    end if 


hth,
John
0 Kudos
Intel_C_Intel
Employee
686 Views
Wow, fun, it worked perfectly. Thank you!
0 Kudos
Reply