有什么方法可以设置窗口的焦点而不更改其相对zorder?

问题描述

应用程序(IntelliJ IDEA)中存在一个错误,无法遵循鼠标(X鼠标)的关注。当我将鼠标移到IntelliJ顶部时,它会闪烁窗口。我认为我可以捕捉到闪烁的图像,然后强迫它聚焦。使用AHK进行了尝试。它几乎可以正常工作(让RegisterShellHookWindow正常工作,它将运行回叫消息),但是我无法使用SetFocus来赋予窗口焦点,大概是因为我在不同的处理空间中吗?我尝试了其他一些方法来赋予窗口焦点,但所有方法似乎都可以提高窗口大小,这是不可接受的。

我是否有某种方式可以强制窗口在其他进程空间中捕获焦点,或者由于某些安全限制而无法实现?

如果有兴趣的人,这里是AHK代码(带有调试语句)(尽管不必用AHK编写):

; Register shell hook to detect flashing windows.
DllCall("RegisterShellHookWindow","Ptr",A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage","Str","SHELLHOOK"),"ShellEvent")

fhex( int,pad=0 ) { ; Function by [VxE]. Formats an integer (decimals are truncated) as hex.
  ; "Pad" may be the minimum number of digits that should appear on the right of the "0x".
  Static hx := "0123456789ABCDEF"
  If !( 0 < int |= 0 )
    Return !int ? "0x0" : "-" fhex( -int,pad )
  s := 1 + Floor( Ln( int ) / Ln( 16 ) )
  h := SubStr( "0x0000000000000000",1,pad := pad < s ? s + 2 : pad < 16 ? pad + 2 : 18 )
  u := A_IsUnicode = 1
  Loop % s
    Numput( *( &hx + ( ( int & 15 ) << u ) ),h,pad - A_Index << u,"UChar" ),int >>= 4
  Return h
}

FlashWindowEx(hWnd := 0,dwFlags := 0,uCount := 0,dwTimeout := 0) {
   Static A64 := (A_PtrSize = 8 ? 4 : 0) ; alignment for pointers in 64-bit environment
   Static cbSize := 4 + A64 + A_PtrSize + 4 + 4 + 4 + A64
   VarSetCapacity(FLASHWINFO,cbSize,0) ; FLASHWINFO structure
   Addr := &FLASHWINFO
   Addr := Numput(cbSize,Addr + 0,"UInt")
   Addr := Numput(hWnd,A64,"Ptr")
   Addr := Numput(dwFlags,"UInt")
   Addr := Numput(uCount,"UInt")
   Addr := Numput(dwTimeout,"Uint")
   Return DllCall("User32.dll\FlashWindowEx",&FLASHWINFO,"UInt")
}

SetFocus(HWND) {
   HPREV := HWND
   While (HPREV := DllCall("User32.dll\Getwindow",HPREV,"UInt",3,"UPtr")) ; GW_HWNDPREV = 3
      If DllCall("User32.dll\IsWindowVisible","UInt")
         Break
   WinActivate,ahk_id %HWND%
   If (HPREV)
      DllCall("User32.dll\SetwindowPos",HWND,"Int",0x0B)
}

ShellEvent(wParam,lParam) {
    _wParam := fhex(wParam)
    _lParam := fhex(lParam)
    X := 0
    Y := 0
    MouseGetPos,X,Y
    
    ToolTip % "1: (" . X . "," . Y . ") Trying to activate " . _wParam . "," . _lParam . ".",(X+1),(Y+1),1 
    if (wParam = 0x8006) ; HSHELL_FLASH
    {   ; lParam contains the ID of the window which flashed:
        FlashWindowEx(lParam)
        ;WinActivate,ahk_id %lParam%
        ;SetFocus(lParam)
        DLLCall("User32.dll\SetFocus",lParam,"Ptr")
        ToolTip % "2: (" . X . "," . Y . ") Trying to activate " _wParam . ",(Y+21),2
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)