16,472
社区成员
发帖
与我相关
我的任务
分享
BOOL CCMenuDlg::OnInitDialog()
{
SetTimer(1, 1500, NULL); //设置定时器,每100ms获取一次焦点
}
void CCMenuDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//if (nIDEvent == GET_FOCUS_ID) {
if(::GetForegroundWindow() == m_hWnd)
return;
HWND hCurWnd = NULL;
DWORD lMyID;
DWORD lCurID;
hCurWnd = ::GetForegroundWindow();
lMyID = ::GetCurrentThreadId();
lCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
::AttachThreadInput(lMyID, lCurID, TRUE);
SetForegroundWindow();
::AttachThreadInput(lMyID, lCurID, FALSE);
// }
CCMenuDlg::SetWindowPos(&CDialog.wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
CDialog::OnTimer(nIDEvent);
}
switch(nIDEvent)
{
case 1:
//do sth
}