MFC之使用FindWindow函数获取指定窗口句柄进行窗口操作(实测:关闭Windows的格式化弹窗)

方法一:

 

  •  1、使用FindWindow之前需先将操作窗口的类名或窗口名用RegisterClass函数进行注册
WNDCLASS m_WindClass1;	
m_WindClass1.lpszClassName = _T("Microsoft Windows");
::RegisterClass(&m_WindClass1);

获取窗口类名或窗口名的方法(https://jingyan.baidu.com/article/3a2f7c2e76584a26aed61174.html)

  •  2、调用FindWindow获取窗口的句柄
HWND hWinHandle = NULL;
hWinHandle = ::FindWindow(_T("#32770"),_T("Microsoft Windows")); //(LPCTSTR)"#32770"

 

  • 示例:自动关闭Windows的格式化弹窗(MFC实测ok)
/*******************************************************************
Function Name:  
Version:  
Input:
Output:
Return:
Description:  关闭断上电之后弹出的格式化窗口
*******************************************************************/
void CAXToolDlg::CloseFormatWindow()
{
	HWND hWinHandle = NULL;
	WNDCLASS m_WindClass1;	//隐藏窗口类
	m_WindClass1.lpszClassName = _T("Microsoft Windows");

	::RegisterClass(&m_WindClass1);
	//hWinHandle = ::FindWindow(NULL,_T("Microsoft Windows")); //(LPCTSTR)"#32770"
	hWinHandle = ::FindWindow(_T("#32770"),_T("Microsoft Windows")); //(LPCTSTR)"#32770"

	if (hWinHandle  != NULL)
	{
		::PostMessage(hWinHandle,WM_CLOSE,NULL,NULL);
		//::SendMessage(hWinHandle,WM_CLOSE,NULL,NULL);
	}

}

 

 

 方法二(未经测试):

博文#11位置:https://bbs.csdn.net/topics/392051989

 

感谢以下博主的帮助:

https://blog.csdn.net/mjlsuccess/article/details/9227785

https://blog.csdn.net/weixin_40923268/article/details/86694628

 

 

你可能感兴趣的:(C++,MFC,MFC)