【MFC】基于对话框的窗口置底

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/h84121599/article/details/82431043

环境:win10,vs2017

之前发过一篇窗口置底的文章,最近找到了一种新的方法,感觉效果更好一点。

思路就是,将自己程序的父窗口设为桌面,程序就会嵌入到桌面内部,便可实现置顶。

代码如下

将置底部分添加到OnInitDialog函数里面:

BOOL CDesktopEvaDlg::OnInitDialog()
{
        //...

	//窗口置底
	HWND hDesktop = ::FindWindow(_T("Progman"), NULL);
	hDesktop = ::GetWindow(hDesktop, GW_CHILD);
	CWnd* pWndDesktop = CWnd::FromHandle(hDesktop);
	this->SetParent(pWndDesktop);

	//...
}

以上功能能满足绝大部分情况。

但经过仍有部分情况会导致置底失效。

有遇到这个情况,可以参考我另一篇博客https://blog.csdn.net/h84121599/article/details/82503464

猜你喜欢

转载自blog.csdn.net/h84121599/article/details/82431043