Software Archive
Read-only legacy content
17061 Discussions

Changing icon in simple dialog based application

Intel_C_Intel
Employee
556 Views
Hello,

Is there a way to change the icon in the title bar with a simple dialog based windows application?

Walter Kramer
0 Kudos
6 Replies
gchien
Beginner
556 Views
Most likely, you haven't changed the icon with 16x16 pixel resolution. You need both 32x32 and 16x16 icons in the same file so that it will be displayed properly in various situations.

If you are using the IDE, modify the icon in the resource section. If you are using the command line without the IDE (such as using a makefile), you can still incorporate your own icon by performing the following:

1. Create an icon file with any icon editor (perhaps the one that came with
your visual environment :-). In the icon file it should have a large icon
(32x32 pixels) and a small icon (16x16 pixels). Let's call the file
hello.ico.

2. Prepare a resource file with the following one line, let's call it hello.rc.
0 ICON hello.ico

3. Run the Win32 resource compiler:
rc -r hello.rc
This will generate a hello.res.

4. Link your console application with hello.res (using df, for example):
df hello.f90 hello.res

5. Verify it with the Windows Explorer. The executable file should be
displayed with the custom icon.

HTH,
Greg Chien
http://protodesign-inc.com
0 Kudos
Intel_C_Intel
Employee
556 Views
I probably was not clear in my posting. I don't mean the display of the icon in the explorer, but the display of the icon in the title bar when the application is running. I have got several applications that can be running simultaneously using optically the same interface. It would be nice for the users if they could see at a glance which interface they are looking at. An icon can help.
I do have my own icons available in all possible sizes.
In a windows SDI or MDI application I can use WNDCLASS, LoadIcon() or LoadImage() and REGISTERCLASS to display the application icon in the title bar, but I don't know how to achieve this in a simple dialog based application (not a console application) whose framework has been generated by the fortran windows application wizard.

Walter
0 Kudos
Intel_C_Intel
Employee
556 Views
Hi,

You may want to see MS KB article Q179582 - HOWTO: Set the Title Bar Icon in a Dialog Box; the meat of which, in a CVF dialog app, could look something like
 
hIcon = LoadImage(ghInstance, %val(MAKEINTRESOURCE(IDI_TITLEBAR_ICON)), IMAGE_ICON, & 
                  GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); 
if(hIcon /= 0) then  
   hr = SendMessage(dlg%hWnd, WM_SETICON, ICON_SMALL, hIcon); 
end if 


hth,
John
0 Kudos
Intel_C_Intel
Employee
556 Views
Thank you John, this works.

I added the lines as you suggested to the dialog call back routine under (callbacktype==dlg_init).
Note that LoadImage needs "aliasing" if you use dflib, because it has been declared there too.

Walter Kramer
0 Kudos
isn-removed200637
556 Views
Can you not just create icons and give them ID's "FRAMEICON" and "CHILDICON", save them in files called, for example, FRAMEICON.ICO and CHILDICON.ICO and include them in the project which generates the application? It works for me.
0 Kudos
Intel_C_Intel
Employee
556 Views
Anthony, I have tried you method but without any succes. Your method probably only works for SDI and MDI windows applications.
The method suggested by John Termine works OK also in a simple dialog based application. You can also use :

  
hIcon = LoadImage(ghInstance, %val(MAKEINTRESOURCE(IDI_ALTTAB_ICON)), IMAGE_ICON, &   
                  GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0) 
if(hIcon /= 0) then    
   hr = SendMessage(dlg%hWnd, WM_SETICON, ICON_BIG, hIcon) 
end if  


This icon will be used when switching applications using Alt-TAB
0 Kudos
Reply