locked
Wrong Icon On Title Bar RRS feed

  • Question

  • Working with Visual Studio 2005, with a wizard-generated MFC application and no doc/view support, I get a generic application icon on my title bar. However, the wizard generated icon, IDR_MAINFRAME, is the icon with the MFC logo. The frame window is created via LoadFrame and IDR_MAINFRAME is passed to it. The program has no other icons associated with it.
     
    So why is the generic icon on the app's title bar?

    What's weird is that it is ONLY in the title bar where I get the generic icon. In the taskbar and on the desktop (when I create a shortcut), the icon is the correct one with the MFC letters.

    Again, the program icon shows correctly everywhere EXCEPT on the app's title bar!
    Tuesday, February 21, 2006 7:54 AM

Answers

  • I'm running an out of the box unmodified single document, no doc/view support, no toolbar, no activeX, no database, wizard generated app. Fortunately, someone at the public mfc forum knew the answer. It has to do with a problem with the MFC app wizard and non doc/view applications that has persisted since VC 6.0. I usually use the doc/view architecture, so have never encountered this before. The fix is to put the following lines of code in InitInstance, after pFrame->UpdateWindow

    HICON hIcon = LoadIcon(IDR_MAINFRAME);

    HICON hPrevIcon = pFrame->SetIcon(hIcon,FALSE);

    if (hPrevIcon && hPrevIcon != hIcon) DestroyIcon(hPrevIcon);

     

    Tuesday, February 21, 2006 7:49 PM

All replies

  • It depends how the frame window registersits window class. Did you overwrote PreCreateWindow? Did you register your own class for the frame window?
    Tuesday, February 21, 2006 12:10 PM
  • I'm running an out of the box unmodified single document, no doc/view support, no toolbar, no activeX, no database, wizard generated app. Fortunately, someone at the public mfc forum knew the answer. It has to do with a problem with the MFC app wizard and non doc/view applications that has persisted since VC 6.0. I usually use the doc/view architecture, so have never encountered this before. The fix is to put the following lines of code in InitInstance, after pFrame->UpdateWindow

    HICON hIcon = LoadIcon(IDR_MAINFRAME);

    HICON hPrevIcon = pFrame->SetIcon(hIcon,FALSE);

    if (hPrevIcon && hPrevIcon != hIcon) DestroyIcon(hPrevIcon);

     

    Tuesday, February 21, 2006 7:49 PM
  • I have the same issue as spiritualfields': a generic icon on title bar but correct one on taskbar and desktop shortcut. My application differs from that of spiritualfields' in that I use Win32 API instead of MFC:

       WNDCLASS wndclass;

       hInst = hInstance;

       wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC;
       wndclass.lpfnWndProc   = WndProc;
       wndclass.cbClsExtra    = 0;
       wndclass.cbWndExtra    = 0;
       wndclass.hInstance     = hInstance;
       wndclass.hIcon         = LoadIcon(NULL, MAKEINTRESOURCE(IDI_MEXPLORER));
       wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
       wndclass.lpszMenuName  = szAppName;
       wndclass.lpszClassName = szAppName;

    I use Visual C++ 2008 express on Windows Vista.

     

    Friday, June 10, 2011 3:27 PM