Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C++ Builder > Активное окно.


Автор: NikSer 15.5.2006, 19:43
Зравствуйте!

Как при наведении курсора мыши над окном сделать окно активным автоматически?.  

Автор: BreakPointMAN 16.5.2006, 05:44
Гм... вероятно, как-то так:

Код
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;
           }
       }
   }
 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)