重启资源管理器导致托盘图标消失的解决方法

重写DefWindowProc即可解决,如:

LRESULT CTestDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	// TODO: 在此添加专用代码和/或调用基类

	static UINT const WM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated"));

	if(message == WM_TASKBARCREATED)
	{
		m_tndData.hIcon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
		m_tndData.cbSize = NOTIFYICONDATA_V2_SIZE;
		m_tndData.hWnd = GetSafeHwnd();
		m_tndData.uID = IDR_MAINFRAME;
		m_tndData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
		m_tndData.uCallbackMessage = NULL;
		m_tndData.dwInfoFlags = NIIF_INFO;
		m_tndData.uTimeout = 1000;

		CString strTips = "";
		CString strTitle = "托盘测试";
		_tcscpy(m_tndData.szTip, (LPCTSTR)strTitle);
		_tcscpy(m_tndData.szInfoTitle, (LPCTSTR)strTitle);
		_tcscpy(m_tndData.szInfo, (LPCTSTR)strTips);

		Shell_NotifyIcon(NIM_ADD,&m_tndData);

		return TRUE;
	}

	return CDialog::DefWindowProc(message, wParam, lParam);
}


你可能感兴趣的:(备忘)