Гм... вероятно, как-то так:
| Код | bool BringWindowToForeground (HWND Wnd) { HWND hCurWnd; DWORD dwThreadID, dwCurThreadID, OldTimeOut; if(Wnd==NULL || !IsWindow(Wnd)) return 0; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &OldTimeOut, 0); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, NULL, 0); SetWindowPos(Wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
hCurWnd = GetForegroundWindow();
while(true) { dwThreadID = GetCurrentThreadId(); dwCurThreadID = GetWindowThreadProcessId(hCurWnd, NULL); AttachThreadInput(dwThreadID, dwCurThreadID, true); if(SetForegroundWindow(Wnd)) break; AttachThreadInput(dwThreadID, dwCurThreadID, false); }
SetWindowPos(Wnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &OldTimeOut, 0); return true; }
//---------------------------------------------------------------------------
void __fastcall TForm1::ApplicationEvents1Message(tagMSG &Msg, bool &Handled) { if(Msg.message!=WM_MOUSEMOVE) return;
if(!Application->Active) BringWindowToForeground(Application->Handle);
for(int i=0;i<Screen->FormCount;i++) { TForm *F=Screen->Forms[i]; if(Msg.hwnd==F->Handle && !F->Focused()) { F->SetFocus(); break; } } } |
|