开发者

Activate windows under mouse through mouse hook

Basically i make mousestruct in the hook

MOUSEHOOKSTRUCT* str;

Then make it from lparam,

LRESULT CALLBACK MouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
str = (MOUSEHOOKSTRUCT *) lParam;
    ...

Then I catch mousemovements

case WM_MOUSEMOVE:
    wParm = AU3_WM_MOUSEMOVE;
    fromp = WindowFromPoint(str->pt);

Then validate and try not to send to many messages...

if (fromp != currentwindow) 
{
    currentwindow= fromp;
    PostMessage(m_hHwndMouse, wParm,(WPARAM)( (MOUSEHOOKSTRUCT*) lParam )->hwnd, LPARAM(fromp));
}
break;

This sends the mousemove message along with hwnd to my autoit app which inspects hwnd and if that hwnd is not active it activates it.

Func mouse_func($hWndGUI, $MsgID, $wParam, $lParam)

Select


    Case $MsgID = $WM_AUTOITMOUSEMOVE

        If GUICtrlRead($activateundermouse) = 1 And $sitting = 0 Then
            ;Local $starttime = _Timer_Init()
            If StringInStr(WinGetTitle($lParam), "ID=") Then
                If Not WinActive($lParam) Then
                    开发者_JS百科;ConsoleWrite("HOVERING NEW, Activate It: " & WinGetTitle($lParam) & @LF)
                    WinActivate($lParam)
                EndIf
                ;ConsoleWrite("diff is > " & _Timer_Diff($starttime) & @LF)
            EndIf
        EndIf

This is how I am activating window that is hovered by the mouse but the problem is that rarely autoit wont read the message that should signal new window being hovered(or the dll with hook didnt send it, I dont know)

Also if the window is overlapping another window and both of them are valid windows that should be activate once hovered I get flickering as autoit is constantly trying to activate the current window and the overlapped one, in a loop

Is there something that perhaps I missed or could be doing wrong here?


It's easiest just to use the facility built into Windows. For example on Windows 7 it looks like this:

Activate windows under mouse through mouse hook

This capability is present in older versions of Windows too but is not exposed in such a simple interface. Instead you have to set it with a PowerToy or through SystemParametersInfo.

As Raymond Chen explains, this is a user preference which should not be changed without the user's consent.


You can use the blocking SendMessage instead depending on surrounding implementation. PostMessage will send to the window message queue but may not have the priority you expect as it returns without waiting for the processing of the message.

Also check out SetCapture and ReleaseCapture to change which window is capturing mouse events based on a hit test in mouse move as an alternative to forwarding. Only one window at a time can capture mouse events using these functions so that will solve your flicker issue of the windows forwarding messages to each other most likely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜