简体   繁体   English

在 Windows 7 上保存和恢复 Aero Snap 位置

[英]Save and restore Aero Snap position on Windows 7

Let's say I have a window and I want to save its position when the window closes and restore it when the window is opened again.假设我有一个窗口,我想在窗口关闭时保存它的位置,并在窗口再次打开时恢复它。 The typical way to do this is to call GetWindowPlacement / SetWindowPlacement.执行此操作的典型方法是调用 GetWindowPlacement / SetWindowPlacement。 This takes care of remember the position and the maximized / minimized state.这需要记住位置和最大化/最小化状态。

On Windows 7, you can dock a window to the side of the screen using the "Aero Snap" feature.在 Windows 7 上,您可以使用“Aero Snap”功能将窗口停靠在屏幕一侧。 My question is how do you save and restore windows that have been "Snapped" so that you can restore the "Snap" state.我的问题是如何保存和恢复已“捕捉”的窗口,以便您可以恢复“捕捉”状态。 GetWindowPlacement / SetWindowPlacement does not solve this problem (to my knowledge) and I haven't seen any "Snap" API's in Windows 7. GetWindowPlacement / SetWindowPlacement 没有解决这个问题(据我所知),我在 Windows 7 中没有看到任何“Snap”API。

There is a similar question on here How to detect window was resized by Windows7 but in this case it seems that the OP just wanted the restore position, not the "Snap" state.这里有一个类似的问题How to detect window was resized by Windows7但在这种情况下,OP 似乎只是想要恢复位置,而不是“Snap”状态。

解决方法是调用GetWindowRect()来获取实际窗口坐标并将它们复制到WINDOWPLACEMENT::rcNormalPosition的坏坐标上。

The way I solved it was to override CWinAppEx::SaveState, to update the WINDOWPLACEMENT before saving it:我解决它的方法是覆盖 CWinAppEx::SaveState,在保存之前更新 WINDOWPLACEMENT:

BOOL MyApp:SaveState(LPCTSTR lpszSectionName, CFrameImpl *pFrameImpl)
{
  WINDOWPLACEMENT wp;
  wp.length = sizeof(WINDOWPLACEMENT);
  m_pMainWnd->GetWindowPlacement(&wp);
  if (wp.showCmd == SW_SHOWNORMAL)
  {
    m_pMainWnd->GetWindowRect(&wp.rcNormalPosition);
    m_pMainWnd->SetWindowPlacement(&wp);
  }

  return __super::SaveState(lpszSectionName, pFrameImpl);
}

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

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