简体   繁体   English

Aero Snap不适用于我的应用程序

[英]Aero Snap not working for my application

I have a problem with Aero Snap not working with the application I'm working on (Windows desktop, native C++ application), and I'm a bit confused as to what's happening, as it seems like it should just work, out of the box. 我有一个问题,Aero Snap没有使用我正在处理的应用程序(Windows桌面,本机C ++应用程序),我对发生的事情感到有点困惑,因为它看起来应该只是起作用,框。

I've used Spy++ on a mininal win32 application, and get the following messages when I press Win-Left: 我在mininal win32应用程序上使用了Spy ++,并在按下Win-Left时收到以下消息:

<00070> 00030D1C P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:0 fUp:0 <00071> 00030D1C P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0 <00072> 00030D1C P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0 <00088> 00030D1C S WM_GETMINMAXINFO lpmmi:0043FCBC <00070> 00030D1C P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:0 fUp:0 <00071> 00030D1C P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0 <00072> 00030D1C P WM_KEYDOWN nVirtKey: VK_LWIN c重复:1 ScanCode:5B f重复:1 fUp:0 <00088> 00030D1C S WM_GETMINMAXINFO lpmmi:0043FCBC
<00089> 00030D1C R WM_GETMINMAXINFO lpmmi:0043FCBC <00089> 00030D1C R WM_GETMINMAXINFO lpmmi:0043FCBC
<00090> 00030D1C S WM_WINDOWPOSCHANGING lpwp:0043FCC4 <00090> 00030D1C S WM_WINDOWPOSCHANGING lpwp:0043FCC4
<00091> 00030D1C S WM_GETMINMAXINFO lpmmi:0043F8E8 <00091> 00030D1C S WM_GETMINMAXINFO lpmmi:0043F8E8
<00092> 00030D1C R WM_GETMINMAXINFO lpmmi:0043F8E8 <00092> 00030D1C R WM_GETMINMAXINFO lpmmi:0043F8E8
<00093> 00030D1C R WM_WINDOWPOSCHANGING 00030D1C R WM_WINDOWPOSCHANGING
.. and so on .. 等等

So I can see that the WM_KEYDOWN for the left key isn't reaching the application, but I'm getting the aero snap "resize window" stuff instead. 所以我可以看到左键的WM_KEYDOWN没有到达应用程序,但我得到了aero snap“resize window”的东西。

When I Spy++ my application, I can see that the left key isn't being "intercepted", but instead being passed on to the application, so I don't get any snapping goodness. 当我使用Spy ++我的应用程序时,我可以看到左键没有被“拦截”,而是被传递给应用程序,所以我没有得到任何攫取的好处。

<00043> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:0 fUp:0 <00043> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:0 fUp:0
<00044> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0 <00044> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0
<00045> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0 <00045> 000F0F12 P WM_KEYDOWN nVirtKey:VK_LWIN cRepeat:1 ScanCode:5B fRepeat:1 fUp:0
<00060> 000F0F12 P WM_KEYUP nVirtKey:VK_LEFT cRepeat:1 ScanCode:4B fRepeat:0 fUp:1 <00060> 000F0F12 P WM_KEYUP nVirtKey:VK_LEFT cRepeat:1 ScanCode:4B fRepeat:0 fUp:1

I'm going to dig into the cores of our message handling and see what's going on, but I'll take all the tips I can get :) 我将深入研究我们的消息处理的核心,看看发生了什么,但我将采取所有我可以得到的提示:)

Edit I noticed that Win-Up and Win-Shift-Left/Right actually work correctly, so it's just Win-Down and Win-Left/Right that aren't being "aero snapped" into the correct position/size. 编辑我注意到Win-Up和Win-Shift-Left / Right实际上工作正常,所以它只是Win-Down和Win-Left / Right而不是“aero snapped”到正确的位置/大小。

Edit Ok, the problem seems to be that my window wasn't been created with the WS_THICKFRAME flag. 编辑确定,问题似乎是我的窗口没有使用WS_THICKFRAME标志创建。 If I add the flag, snap works. 如果我添加标志,快照工作。 Now, I don't actually want the border there in the first place, but at least I know what was causing the weird behavior.. 现在,我实际上并不首先想要那里的边界,但至少我知道造成这种奇怪行为的原因。

Hopefully a final edit Getting rid of the border was as simple as responding to WM_NCCALCSIZE, and making the client occupy the whole window. 希望最终编辑摆脱边界就像响应WM_NCCALCSIZE一样简单,并使客户端占据整个窗口。

I can't remember the specific messages, but Aero Snap is disabled if you process the WM_MOVING/WM_MOVE and/or WM_SIZING/WM_SIZE messages for the main window. 我不记得具体的消息,但如果您处理主窗口的WM_MOVING / WM_MOVE和/或WM_SIZING / WM_SIZE消息,则会禁用Aero Snap。 If these do not reach DefWindowProc Aero Snap won't work. 如果这些没有达到DefWindowProc Aero Snap将无法正常工作。 I guess DefWindowProc is responsible for implementing Aero Snap, so if you make sure those messages reach it, that might help. 我想DefWindowProc负责实现Aero Snap,所以如果你确保这些消息到达它,那可能会有所帮助。

I discovered this implementing custom window dragging code so the application continues to execute and update the screen while the window is dragged, which meant processing these messages, but it disabled Aero Snap. 我发现这实现了自定义窗口拖动代码,因此应用程序继续执行并在拖动窗口时更新屏幕,这意味着处理这些消息,但它禁用了Aero Snap。

Edit: On further inspection, the application I mentioned handles WM_SYSCOMMAND and checks (wParam & 0xFFF0) == SC_MOVE to indicate a window move beginning. 编辑:进一步检查时,我提到的应用程序处理WM_SYSCOMMAND并检查(wParam & 0xFFF0) == SC_MOVE以指示窗口移动开始。 It then returns 0 and simulates the window dragging by updating the window position periodically whilst still running the application, drawing etc. This causes Windows to think the window is unmovable and that the user cannot drag it, but my application is updating the position to make it look like it's still being dragged, until WM_LBUTTONUP. 然后返回0并通过在运行应用程序,绘图等时定期更新窗口位置来模拟窗口拖动。这会导致Windows认为窗口不可移动且用户无法拖动它,但我的应用程序正在更新位置看起来它仍然被拖动,直到WM_LBUTTONUP。 Obviously Windows won't try any Aero Snap stuff if it doesn't think the window is being dragged. 显然,如果不认为窗口被拖动,Windows将不会尝试任何Aero Snap。 Maybe your application does something similar (if anyone has a better way to keep the app running during a drag, I'd be interested to hear). 也许你的应用程序做了类似的事情(如果有人有更好的方法来保持应用程序在拖动期间运行,我有兴趣听到)。

I doubt it is message handling, the message loop never sees the WM_KEYDOWN message. 我怀疑它是消息处理,消息循环永远不会看到WM_KEYDOWN消息。 After trying various things unsuccessfully, I can only guess at Windows thinking your app is incompatible somehow. 在尝试了各种不成功的事情之后,我只能猜测Windows认为你的应用程序是不兼容的。 Using SetWindowsHookEx() in your program for example. 例如,在程序中使用SetWindowsHookEx()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM