VC++实现窗口置顶

 最近在跟着Visual C++网络编程开发与实战视频教程做HttpSourceViewer这个MFC项目时,可以看我Github上的项目HttpSourceViewer,目前基本实现了所有功能,就是关于ALT搜索和调用迅雷7SDK下载还有些问题。看到作者jhkdiy的置顶窗口,于是Google了一下相关方法,没想到蛮简单的。

比如我需要单击CheckBox选择框,可以设置主对话框是否为窗口置顶,可以这么做,代码如下:

// 实现主窗口置顶
void CHttpSourceViewerDlg::OnClickedCheckTopmostWindow()
{
	// TODO: 在此添加控件通知处理程序代码
	HWND hWnd = this->m_hWnd;
	// whether if the window is topmost
	if (::GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
	{
		// The window is topmost.
		// Revert back
		::SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
	}
	else
	{
		// The window is not topmost.
		// Make topmost
		::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
	}
}

参考资料:

1、CodeProject上 作者Tsuda Kageyu提供的方法:链接是:How to determine if your window is topmost.

2、VC++ 判断你的窗口是否置顶

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=289fydvat5ess

原文地址:https://www.cnblogs.com/ccf19881030/p/12004821.html