// 创建非模态窗口
if(!CWnd::CreateEx(WS_EX_TOOLWINDOW|WS_EX_LAYERED,_T("Static"),StrTipText,WS_POPUP|SS_NOTIFY,CRect(x,y,x+nWidth,y+nHeight),CWnd::FromHandle(hDeskListView),0))
{return FALSE;
}
HWND hDesktop = Null;
if(xp系统)
{
hDesktop = ::FindWindow(_T("Progman"), NULL);
hDesktop = ::GetWindow(hDesktop, GW_CHILD);
}
else if(vista、win7或者win7之上)
{
HWND hWnd = ::FindWindow(_T("WorkerW"),NULL);//先当WIN7系统查找
while(hWnd)
{
HWND hShellView=::FindWindowEx(hWnd, NULL, _T("SHELLDLL_DefView"), NULL);
if(hShellView)
{
hDesktop = ::FindWindowEx(hShellView, NULL, _T("SysListView32"), NULL);
break;
}
hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
}
}
::SetParent(GetSafeHwnd(), hDesktop);
// 修改Z序
SetWindowPos(NULL, x,y,x+nWidth,y+nHeight, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
本文介绍如何使用MFC创建非模态窗口并将其嵌入到桌面,以便实现桌面快捷方式气泡提示。针对不同系统(如XP、Vista、Win7及以上),代码通过FindWindow和GetWindow函数定位桌面窗口,并使用SetParent设置窗口父级,确保窗口能正确显示在桌面。同时,通过SetWindowPos调整窗口Z序,确保窗口在前台显示。
782

被折叠的 条评论
为什么被折叠?



