MFC-GetForegroundWindow获取系统中被激活的窗口

HWND hWnd = ::FindWindow(_T("Notepad"), NULL);//获取记事本句柄 if (!hWnd) { AfxMessageBox(_T("请打开记事本")); ExitProcess(0); } CString str; str.Format(_T("记事本句柄hWnd=%X\r\n"), hWnd); OutputDebugString(str); HWND hWnd2 = GetSafeHwnd();//获取代码所在顶级窗口的句柄 str.Format(_T("本程序窗口句柄hWnd2=%X\r\n"), hWnd2); OutputDebugString(str); ::SetForegroundWindow(hWnd); HWND hWnd5=::GetForegroundWindow();//获取系统中被激活的窗口 str.Format(_T("hWnd5=%X\r\n"), hWnd5); OutputDebugString(str);


浙公网安备 33010602011771号