0
votes

I am having a bit of a problem displaying the taskbar icon for a dialog that my app creates. The main application is a system tray based windows application.

Here is the code I use to create the dialog:

        g_pMainWnd->m_DlgAuth= new CDlg_Auth();
        g_pMainWnd->m_DlgAuth->SetTitle(_T("Authentication"));          
        g_pMainWnd->m_DlgAuth->SetSize(420,420);
        g_pMainWnd->m_DlgAuth->Create(IDD_DLG_AUTH,AfxGetMainWnd());
        g_pMainWnd->m_DlgAuth->ShowWindow(SW_SHOW);
        g_pMainWnd->m_DlgAuth->SetForegroundWindow();

The g_pMainWnd is a global pointer to the main class, Since the creation of the dialog is made in a callback from a child thread.

The taskbar icon is created in MFC's OnInitDialog method as shown here:

    m_hIcon = (HICON)LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME),IMAGE_ICON, 0, 0, 0); 

    int cxIcon = GetSystemMetrics(SM_CXSMICON);
    int cyIcon = GetSystemMetrics(SM_CYSMICON);

    m_hIconSmall = (HICON)LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME),IMAGE_ICON
        ,cxIcon,cyIcon, 0); 

    SetIcon(m_hIconSmall, FALSE);       // Set small icon
    SetIcon(m_hIcon, TRUE);     // Set small icon

The small icon loads perfectly the problem is with the big icon, it does not load at all, the handle gets set and all seems fine but when the taskbar button shows, it shows the default windows console app icon.

I have been at this for a week now and nothing seems to work. I have tried other 32x32 icons, tried loading the dialog from a different thread. I tried to make the callback post a message to the main thread to create the dialog. All the controls in the dialog works fine. It gets all the necessary messages but it doesn't draw the icon.

Would appreciate any help possible. Thanks

1
In general, the MFC framework pick the first icon.. If you other icon/resource as first, MFC would fail to load the iconuser90150
thanks for the comment. I have solved the issue and posted the answer to this thread. The problem wasn't from the resource/image but thanks.Zaid Amir

1 Answers

1
votes

Just fixed it by using Sending WM_SETICON message to the main window instead of calling the seticon function