创建两个窗口会导致第二个创建的窗口失效

发布于 2024-12-07 20:24:56 字数 1391 浏览 1 评论 0原文

我正在尝试使用热键将分层窗口从透明更改为允许鼠标消息通过。

在我的主函数中,我调用

// make hotkey with WM_HOTKEY messages sent to hwnd's window procedure, id 1, 
// no other keys to work, F5 as hotkey  
// while checking for errors and it completes successfully. I also do the same 
// (id of 2) for VK_F7 and it completes successfully.

RegisterHotKey (hwnd, 1, 0, VK_F5); 
RegisterHotKey (hwnd, 2, 0, VK_F7);

在我的窗口过程中,我

case WM_HOTKEY: 
    MessageBox (hwnd, "Got here", "Attention", MB_OK);
    // Other stuff I need to do here

尝试添加 MOD_CONTROL,但无济于事。

这实际上以前确实有效。现在唯一的区别是我意识到两个窗口可以解决我一直遇到的问题。上次我只有一个,现在我的应用程序中有两个窗口过程。我确保一切都正确,但我不应该仅限于 1 个窗口...窗口本身会显示,因为我将透明度设置为 100/255,因此它会稍微屏蔽视图,并且我可以看到那个屏幕。

更改密钥本身不会执行任何操作,并且 WM_HOTKEY 消息将被发布到队列中。我将尝试手动将它们发送到窗口。

编辑:^ with SendMessage() 不起作用,要查看它是否收到任何消息,并且当我使用它时与其他窗口相同。

编辑:好吧,我觉得这样说就像个白痴,但是我已经 RegisterHotKey 进入了一个空 hwnd,因为我实际上还没有创建该窗口(我创建了一个没有首先获取热键消息的窗口)之后就有了这些)。 问题是即使我可以看到这个窗口,并且如果我将其全部注释掉,视图会有所不同(没有屏幕),但它不会收到任何消息。

编辑:我将标题更改为更适合此额外信息的内容。如果这是任何人都经历过的普遍现象,我很高兴听到。现在,我假设它是我的包装器并手动创建它们。

主要编辑:我只是尝试使用原始 API 而不是我的包装器,但在注册第二个时出现错误。我更改了类名称,现在类注册并创建窗口。热键出现的消息框也会显示。我想我忘了为他们放置显示窗口,我会在一秒钟内说明它是如何工作的(编辑:在我再次重新启动计算机后!!!)。在你问之前,我还没有在我的包装器上花费太长时间,是的,它有错误检查,但使用类似的系统来设置/获取lasterror(),并且自第二个以来我没有检查它们的返回值一个似乎是之前创建的。

I'm trying to use a hotkey to change a layered window from being transparent to allowing mouse messages to come through.

In my main function I call

// make hotkey with WM_HOTKEY messages sent to hwnd's window procedure, id 1, 
// no other keys to work, F5 as hotkey  
// while checking for errors and it completes successfully. I also do the same 
// (id of 2) for VK_F7 and it completes successfully.

RegisterHotKey (hwnd, 1, 0, VK_F5); 
RegisterHotKey (hwnd, 2, 0, VK_F7);

In my window procedure, I have

case WM_HOTKEY: 
    MessageBox (hwnd, "Got here", "Attention", MB_OK);
    // Other stuff I need to do here

I tried adding MOD_CONTROL, but to no avail.

This did actually work before. The only difference now is that I realized that two windows would solve the problems I've been having. Last time I only had one, and now I have two window procedures in my application. I made sure it's all going to the right one and everything, but I shouldn'e be limited to just 1 window... The window itself displays, as I set the transparency to 100/255 so it screens the view a bit, and I can see that screen.

Changing the key itself does nothing, and the WM_HOTKEY messages are being posted to the queue. I'm going to try manually sending them to the window.

edit: ^ with SendMessage() isn't working, going to see if it's getting any messages, and same with the other window while I'm at it.

edit: okay I feel like an idiot for saying this, but I had RegisterHotKey going to a null hwnd since I didn't actually create that window yet (I created the one not getting hotkey message first and originally had these right after that). The problem is that even though I can see this window, and if I comment it all out the view is different (no screen), it isn't receiving any messages.

edit: I changed the title to something more suitable with this extra info. If this is a generic thing anyone's experienced, I'd be glad to hear. For now, I'm assuming it's my wrapper and creating them manually.

major edit: I just tried using raw API instead of my wrapper and it had an error registering the second. I changed the class name and now the classes register and the windows get created. The message box that comes up for hotkeys shows too. I think I forgot to put the showwindow for them though, I'll say how that works in a second (edit: after I restart my computer yet again!!!). Before you ask, I didn't spend too long on my wrapper yet, and yes, it has error checking, but uses a similar system to set/get lasterror() and I didn't check the return values on them since the second one seemed to be created before.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍笑 2024-12-14 20:24:56

问题是两个窗口具有相同的类名。这确实让我有点困惑,因为我认为他们被允许这样做,然后我将向我的包装器添加一个静态实例计数成员。最终结果是该领域的所有问题现在都已修复:D
编辑:我在学习后只需添加此内容,但我发现您可以创建两个具有相同类名的窗口,但它们必须使用相同的窗口过程。学习这一点实际上增强了我对这个主题的理解,所以如果我为其他人澄清这一点,我会很高兴。 /编辑

以防万一您想知道这样做的目的是什么,我添加了它的一个小镜头。它有望成为你可以为屏幕“换肤”的东西。现在它确实保持在顶部并跟随您,所以大部分工作都已完成。正如您所看到的,这不是最好的计算机

正在运行的程序的屏幕截图

当我添加退出方式时,控制台窗口将被隐藏。

The problem was that both windows had the same class name. This does confuse me a bit, as I thought they were allowed to, and I shall be adding a static instance counting member to my wrapper then. The final result is that every problem in this area is now fixed :D
EDIT: I just had to add this after learning it, but I came upon the knowledge that you can create two windows with the same class name, but they must use the same window procedure. Learning this actually strengthened my understanding of this topic a lot, so if I clear this up for even one other person I'll be happy. /EDIT

Just in case you're wondering what the purpose of this was, I'm including a little shot of it. It's hopefully going to turn into something that you can "skin" your screen with. It does stay on top and follow you around now so most of it is done. As you can see, not the nicest computer to work with

screenshot of program in action

The console window will be hidden later when I add a way to exit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文