加载对话框的任务栏图标时出现问题
我在显示我的应用程序创建的对话框的任务栏图标时遇到一些问题。主要应用程序是基于系统托盘的 Windows 应用程序。
这是我用来创建对话框的代码:
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();
g_pMainWnd 是指向主类的全局指针,因为对话框的创建是在子线程的回调中进行的。
任务栏图标是在 MFC 的 OnInitDialog 方法中创建的,如下所示:
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
小图标完美加载,问题在于大图标,它根本不加载,句柄已设置,一切看起来都很好,但是当任务栏按钮显示时,它显示默认的 Windows 控制台应用程序图标。
我已经这样做了一个星期了,但似乎没有任何效果。我尝试过其他 32x32 图标,尝试从不同的线程加载对话框。我尝试让回调向主线程发送消息以创建对话框。对话框中的所有控件都工作正常。它获取所有必要的消息,但不绘制图标。
将不胜感激任何可能的帮助。 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用发送 WM_SETICON 消息到主窗口而不是调用 seticon 函数来修复它
Just fixed it by using Sending WM_SETICON message to the main window instead of calling the seticon function