使用 ws_ex_transparent 活动 c++ 注册鼠标点击 [英] Registering mouseclicks with ws_ex_transparent active c++

查看:41
本文介绍了使用 ws_ex_transparent 活动 c++ 注册鼠标点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使 ws_ex_transparent 已打开,我如何让我的窗口注册鼠标点击?

How do I get my window to register mouseclicks even tho ws_ex_transparent is on?

HWND hWnd = CreateWindowEx(WS_EX_LAYERED| WS_EX_TRANSPARENT, szAppName, wcWndName,
    WS_VISIBLE | WS_POPUP, 255, 150, w, h,
    NULL, NULL, hThisInst, NULL);

窗口被标记为分层和透明,以及

The window is flagged to be layered and transparent, along with

SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED);

把它放在最上面"(前面)使它可以作为一个覆盖层工作,但遗憾的是,它根本没有注册鼠标点击.

placing it "topmost" (infront) makes it work as an overlay, but sadly, it doesnt register mouseclicks at all.

case WM_LBUTTONDOWN:
    PostQuitMessage(0); //does it listen?

所以我的问题很简单:如何让我的分层的、最顶层的、透明的窗口注册我点击鼠标?

So my question is easy: How do I get my layered, topmost, transparent window to register me clicking the mouse?

任何帮助都会有帮助.谢谢

any help would be, well, helpful. thanks

解决方案原来是使用相当标准的钩子功能,包括在窗口标题中.

The solution turns out to be using a fairly standard hook feature, included in the windows header.

键盘钩子看起来与鼠标钩子有点不同,但由于我在鼠标钩子之后,这是我发布的解决方案.(如果你碰巧寻找 一个键盘钩子)

The keyboard hook looks a bit different than the mousehook, but since im after the mousehook, this is the solution im posting. (if u happen to look for a keyboard hook)

mousehook; //global declaration
LRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT k = (PKBDLLHOOKSTRUCT)(lParam);
    if (wParam == WM_LBUTTONDOWN)
{
MessageBox(NULL, "LM is pressed", "key pressed", MB_ICONINFORMATION);
}
    if (wParam == WM_RBUTTONDOWN)
{
MessageBox(NULL, "RM is pressed", "key pressed", MB_ICONINFORMATION);
}
return CallNextHookEx(Mousehook, nCode, wParam, lParam);
}

并在 winmain 中调用它(在 msg 之前)

and calling it in winmain (before msg)

Mousehook = SetWindowsHookEx(WH_MOUSE_LL, HookCallback, NULL, 0);

推荐答案

你为什么将 WS_EX_LAYAREDWS_EX_TRANSPARENT 混合在一起,而不是使用分层透明?

Why are you mixing WS_EX_LAYARED and WS_EX_TRANSPARENT together, instead of using Layered Transparency?

无论如何,请参阅本文以了解有关 WS_EX_TRANSPARENT 实际作用的一些信息:

In any case, see this article for some info about what WS_EX_TRANSPARENT actually does:

就像蛋糕一样,WS_EX_TRANSPARENT 是谎言,或者至少不是全部真相

对于您的要求,您需要处理 WM_NCHITTEST 并让它返回 HTCLIENT 而不是 HTTRANSPARENT 用于您想要的任何区域可以在透明窗口上点击.但是,WM_NCHITTEST 不适用于 WS_EX_LAYERED,因此您必须删除 WS_EX_LAYERED 并单独使用 WS_EX_TRANSPARENT,然后处理 WM_ERASEBKGND 并让它返回 1 而不绘制任何东西以获得透明效果.然后你可以使用WM_NCHITTEST.

For what you are asking, you need to handle WM_NCHITTEST and have it return HTCLIENT instead of HTTRANSPARENT for any area that you want to be clickable on a transparent window. However, WM_NCHITTEST does not work with WS_EX_LAYERED, so you will have to remove WS_EX_LAYERED and use WS_EX_TRANSPARENT by itself, and then process WM_ERASEBKGND and have it return 1 without drawing anything to get the transparent effect. Then you can use WM_NCHITTEST.

这篇关于使用 ws_ex_transparent 活动 c++ 注册鼠标点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆