可以将哪种Winapi迷住以防止Chrome激活Chrome?
我正在使用 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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论