可以将哪种Winapi迷住以防止Chrome激活Chrome?

发布于 2025-02-05 12:33:31 字数 3505 浏览 2 评论 0原文

我正在使用 easyhook hook google> google chrome,试图防止窗口被激活。在使用postmessage发送单击时,我挂钩 wm_windowposchanging 和'强制'它删除标志swp_noactivate | swp_nozorder,但是当我发送postmessage单击:

lParam = MAKELPARAM(x, y);
PostMessageW(hWnd, WM_LBUTTONDOWN, 0x0001, lParam);
PostMessageW(hWnd, WM_LBUTTONUP, 0, lParam);

窗口仍然被激活时,我确认挂钩正常工作,问题是找到正确的winapi钩/拦截。

    typedef LRESULT __stdcall DefDlgProcWFunc(HWND, UINT, WPARAM, LPARAM);
    
    // Innermost hook handler
    LRESULT __stdcall DefDlgProcW_Hook(HWND   hWnd, UINT   Msg, WPARAM wParam, LPARAM lParam)
    {
        DefWindowProcW_Msg(hWnd, Msg, wParam, lParam, 1);
    
        // Innermost hook just call original
        return DefDlgProcW(hWnd, Msg, wParam, lParam);
    }
    
    
    
    void DefWindowProcW_Msg(HWND hWnd, UINT& Msg, WPARAM& wParam, LPARAM& lParam, int CalledByFunction)
    {
        if (!hooks_enabled)
            return;
    
        std::wstringstream str;

        HWND hwnd = nullptr;
        HWND hwndInsertAfter = nullptr;
        tagWINDOWPOS* wp;
        int x;
        int y;
        int cx;
        int cy;
        UINT flags;
    
        switch (Msg)
        {
            case WM_WINDOWPOSCHANGING:
            {
                wp = reinterpret_cast<tagWINDOWPOS*>(lParam);
                hwnd = wp->hwnd;
                hwndInsertAfter = wp->hwndInsertAfter;
                x = wp->x;
                y = wp->y;
                cx = wp->cx;
                cy = wp->cy;
                flags = wp->flags;
    
    
                HWND hWnd2 = FindWindow(0, L"New Tab - Google Chrome");
    
                str << L"\nWM_WINDOWPOSCHANGING"
                    << L"\nx:                   " << x  << L"        y:        " << y
                    << L"\nw:                   " << cx << L"        h:        " << cy
                    << L"\nhwnd:                " << hwnd
                    << L"\nflags:               " << flags
                    << L"\n";
                OutputDebugString(str.str().c_str());
    
                if (hWnd == hWnd2) {
                    OutputDebugString(L"CHROME!!!!\n");
                    wp->flags &= ~(SWP_NOACTIVATE | SWP_NOZORDER);
                    return;
                }
    
                return;
            }
        }
    }

这起作用:

为了防止在不使用dll注入的情况下激活应用程序(放在前面)?

但是弊端是:您始终需要在发送消息之前和之后呼叫lockset ForeforggroundWindow发送消息(解锁),如果我尝试在任务栏被锁定时在任务栏中执行单击,则不会激活窗口。

在链接中,有一个提及setWineventhook event_system_foreground 当事件返回时,窗口已经更改了,这无济于事。

我还尝试了挂钩

这是发送postmessage单击: https:// i。 sstatic.net/02wui.png

我的目标是使用postmessage ui自动化/JavaScript

Im using EasyHook to hook google chrome, trying to prevent the window from being activated when sending clicks to it using PostMessage, i hooked WM_WINDOWPOSCHANGING and 'forced' it to remove the flags SWP_NOACTIVATE | SWP_NOZORDER, but when i send the PostMessage click:

lParam = MAKELPARAM(x, y);
PostMessageW(hWnd, WM_LBUTTONDOWN, 0x0001, lParam);
PostMessageW(hWnd, WM_LBUTTONUP, 0, lParam);

the window still get activated, i confirmed that the hook is working correctly, the problem is just finding the correct WINAPI to hook/intercept.

    typedef LRESULT __stdcall DefDlgProcWFunc(HWND, UINT, WPARAM, LPARAM);
    
    // Innermost hook handler
    LRESULT __stdcall DefDlgProcW_Hook(HWND   hWnd, UINT   Msg, WPARAM wParam, LPARAM lParam)
    {
        DefWindowProcW_Msg(hWnd, Msg, wParam, lParam, 1);
    
        // Innermost hook just call original
        return DefDlgProcW(hWnd, Msg, wParam, lParam);
    }
    
    
    
    void DefWindowProcW_Msg(HWND hWnd, UINT& Msg, WPARAM& wParam, LPARAM& lParam, int CalledByFunction)
    {
        if (!hooks_enabled)
            return;
    
        std::wstringstream str;

        HWND hwnd = nullptr;
        HWND hwndInsertAfter = nullptr;
        tagWINDOWPOS* wp;
        int x;
        int y;
        int cx;
        int cy;
        UINT flags;
    
        switch (Msg)
        {
            case WM_WINDOWPOSCHANGING:
            {
                wp = reinterpret_cast<tagWINDOWPOS*>(lParam);
                hwnd = wp->hwnd;
                hwndInsertAfter = wp->hwndInsertAfter;
                x = wp->x;
                y = wp->y;
                cx = wp->cx;
                cy = wp->cy;
                flags = wp->flags;
    
    
                HWND hWnd2 = FindWindow(0, L"New Tab - Google Chrome");
    
                str << L"\nWM_WINDOWPOSCHANGING"
                    << L"\nx:                   " << x  << L"        y:        " << y
                    << L"\nw:                   " << cx << L"        h:        " << cy
                    << L"\nhwnd:                " << hwnd
                    << L"\nflags:               " << flags
                    << L"\n";
                OutputDebugString(str.str().c_str());
    
                if (hWnd == hWnd2) {
                    OutputDebugString(L"CHROME!!!!\n");
                    wp->flags &= ~(SWP_NOACTIVATE | SWP_NOZORDER);
                    return;
                }
    
                return;
            }
        }
    }

This works:

Is it possible to prevent an application from being activated (brought to front) without using DLL injection?

but the cons is: you always need to call LockSetForegroundWindow before and after sending the message (to unlock), if i try to perform a click in the taskbar while it are locked no window is activated.

In the link there's a mention to SetWinEventHook with the event EVENT_SYSTEM_FOREGROUND
it would not help as when the event is returned the window already changed.

I also tried hooking SetForegroundWindow, but looks like chrome is not calling it.

This is all window message triggered after sending a PostMessage click: https://i.sstatic.net/02WuI.png

My goal is to get it working using PostMessage, and not UI Automation/JavaScript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文