开发者

Problem loading taskbar icon for dialog

开发者 https://www.devze.com 2023-03-09 05:40 出处:网络
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.

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 fi开发者_如何学Pythonne 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消