欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MFC定位窗口焦点

程序员文章站 2024-02-10 22:07:10
...
// 把焦点定位到桌面端主界面
	{
		HWND hMainWnd = NULL;
		CLib_Global::GetAPI().pITools->GetWindowHandle(hMainWnd);
		FALSE_RETURN(NULL!=hMainWnd);
		CWnd *pWnd = CWnd::FromHandle(hMainWnd);
		if (pWnd != NULL && pWnd->GetParent() != NULL)
		{
			CDC dc;
			dc.Attach(::GetWindowDC(pWnd->GetParent()->GetSafeHwnd()));
			dc.GetWindow()->SetActiveWindow();
		}
		else
		{
			CDC dc;
			dc.Attach(::GetWindowDC(hMainWnd));
			dc.GetWindow()->SetActiveWindow();
		}
	}