Thread: MDI Child Window Icons change to IDI_EXCLAMATION

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    5

    MDI Child Window Icons change to IDI_EXCLAMATION

    I'm writing a win32 application with Multiple Document Interface (MDI) child windows. The child windows have the same icon as the main application window (IDI_ICON1).

    Everything works fine when I run the application from the Visual Studio Projects folder. But if I move the executable anywhere else, instead of my application icon, the child windows have the Windows warning icon (IDI_EXCLAMATION).

    The icon for the child windows is set when defining the window class (wc) for the child windows.

    Code:
    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    Thanks.

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    Are you sure you have your icon defined in your resource file and header file, and all files are included when your program is compiled?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    Here's an example of what I mean by defining your icon in the appropriate files:

    Code:
    wc.hIcon = LoadIcon(hInstance, (LPSTR) MAKEINTRESOURCE(ID_ICON));
    Code:
    Resource File (.rc)
    ID_ICON ICON DISCARDABLE   myapp.ico
    Code:
    Header File (.h)
    #ifdef RC_INVOKED
    #define ID(id) id
    #else
    #define ID(id) MAKEINTRESOURCE(id)
    #endif
    
    // resource id's
    #define ID_ICON  1

  4. #4
    Registered User
    Join Date
    Apr 2015
    Posts
    5
    Yeah.

    resource.h
    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by WinDemo_01.rc
    //
    #define IDI_ICON1                       101

    resource file
    Code:
    IDI_ICON1               ICON                    "icon1.ico"
    If I run the .exe (by double-clicking on it) from the debug folder within the solution project folder the icon appears as it should. The same if I run it from within Visual Studio.

    If I move the .exe or the whole solution folder somewhere else and run the .exe by double clicking on it, all the MDI child windows have the Windows warning icon. The application frame window has the proper icon. All my other icons, such as list view icons appear as they should.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    What happens if you use two icons in in your program; one for the parent window and a different one for the child window? Do you end up with the same results?

  6. #6
    Registered User
    Join Date
    Apr 2015
    Posts
    5
    If I use my IDI_ICON2 instead for the child windows, while retaining my IDI_ICON1 for the frame window, the behavior is the same except that instead of the child window icon being replaced by IDI_EXCLAMATION, they're replaced by the Windows IDI_ERROR icon.

    Code:
    #define IDI_ICON2                       103
    I note that IDI_EXCLAMATION is MAKEINTRESOURCE(32515) and that IDI_ERROR is MAKEINTRESOURCE(32513) so that they are also 2 digits apart like my resource identifiers 101 and 103. But I don't know what significance this might have if any.

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    Wierd...Perhaps trying a somewhat different approach will yield better results. Try changing the LoadIcon calls for the parent and child windows to this.

    Code:
    wc.hIcon = LoadIcon(hInstance, IDPIC);
    Then in your header file (.h) add the following.

    Code:
    #ifdef RC_INVOKED
    #define ID(id) id
    #else
    #define ID(id) MAKEINTRESOURCE(id)
    #endif
    
    // resource id's
    #define IDPIC    ID(1)  // for your icon
    In your resource file (.rc) add this.

    Code:
    #include "resource.h"  // assuming your header file is called resource.h
    
    IDPIC      ICON        icon1.ico   // icon for parent and child windows

  8. #8
    Registered User
    Join Date
    Apr 2015
    Posts
    5
    Sorry about the delay. I don't get much time through the week.

    I tried the suggestion, but the result is the same. I.e. it works when I run it from Visual Studio or from the .exe in the Debug folder in the Visual Studio Projects folder, but if I run it from anywhere else I get the Windows warning icon instead.

    I changed my icon ID to IDPIC and made the following change to the LoadIcon calls for the main window and child window

    Code:
    wc.hIcon = LoadIcon(hInstance, IDPIC);
    


    I made the following change to resource.h

    Code:
    #ifdef RC_INVOKED
    #define ID(id) id
    #else
    #define ID(id) MAKEINTRESOURCE(id)
    #endif
    
    #define IDPIC ID(101)


    and the resource file has:

    Code:
    IDPIC ICON "icon1.ico"

  9. #9
    Registered User
    Join Date
    Apr 2015
    Posts
    5
    It's working, kind of.

    I just tried running it from some other locations and it works as it should. It was something about the particular location I was running it from that it didn't like.

    I did some more testing. It seems to be the length of the file path to the executable that it doesn't like. It won't work if the file path is too long. All my other executables in these folders work fine, but not for MDI child window icons. Weird.

    I tried removing characters from the name of the folder it was in until it worked. If the folder name has two characters in the title I get the Warning icon. If the folder name has one character in the title I get the correct icon.

    It's unsettling that the program will only work properly in certain locations.
    Last edited by Alej; 05-01-2015 at 11:18 PM.

  10. #10
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    Quote Originally Posted by Alej View Post
    It's working, kind of.

    I just tried running it from some other locations and it works as it should. It was something about the particular location I was running it from that it didn't like.

    I did some more testing. It seems to be the length of the file path to the executable that it doesn't like. It won't work if the file path is too long. All my other executables in these folders work fine, but not for MDI child window icons. Weird.

    I tried removing characters from the name of the folder it was in until it worked. If the folder name has two characters in the title I get the Warning icon. If the folder name has one character in the title I get the correct icon.

    It's unsettling that the program will only work properly in certain locations.
    That is extremely weird indeed. Unfortunately, I do not have an explanation for this behavior if it is indeed the root cause.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access Function in Child Window From Parent Window
    By Welder in forum Windows Programming
    Replies: 3
    Last Post: 05-20-2008, 03:06 AM
  2. parent window minimizing on child window destruction
    By Yarin in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2008, 09:34 AM
  3. how to add/change icons?
    By seal in forum C Programming
    Replies: 12
    Last Post: 08-30-2005, 02:22 PM
  4. Change icons in Windows 2K
    By ober in forum Tech Board
    Replies: 1
    Last Post: 05-14-2004, 01:19 PM
  5. Child window inside child window
    By Magos in forum Windows Programming
    Replies: 13
    Last Post: 04-20-2004, 06:51 AM

Tags for this Thread