如何通过WinAPI禁用Aero Shake但保留窗口停靠功能?
Disable Aero Shake via WinAPI While Keeping Window Snap Enabled
Great question! I’ve dealt with this exact issue before—using SPI_SETWINARRANGING is indeed too heavy-handed since it kills both Aero Shake and window snap. The trick is to target the specific registry setting that controls Aero Shake alone, just like the Group Policy Editor or manual Regedit changes do, but do it programmatically with WinAPI.
Here’s the step-by-step solution:
- The registry key that controls Aero Shake (without affecting snap) is located at:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced - The DWORD value
DisallowShakingdictates whether Aero Shake is enabled:- Set it to
1to disable Aero Shake - Set it to
0to re-enable it
- Set it to
WinAPI Code Example (C++)
You can use the standard registry manipulation functions from WinAPI to modify this value, then notify Explorer to apply the changes immediately:
#include <windows.h> BOOL DisableAeroShakePreserveSnap() { HKEY hAdvancedKey; // Open the target registry key LONG openResult = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", 0, KEY_SET_VALUE, &hAdvancedKey); if (openResult != ERROR_SUCCESS) { return FALSE; } // Set DisallowShaking to 1 (disable Aero Shake) DWORD shakeDisabled = 1; LONG setResult = RegSetValueEx(hAdvancedKey, L"DisallowShaking", 0, REG_DWORD, (BYTE*)&shakeDisabled, sizeof(DWORD)); RegCloseKey(hAdvancedKey); // Notify Windows Explorer to refresh settings (no restart needed) SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 5000, nullptr); return setResult == ERROR_SUCCESS; }
Key Notes:
- Permissions: Modifying
HKCU(Current User) settings only requires standard user privileges—no admin rights needed. - Immediate Effect: Sending the
WM_SETTINGCHANGEmessage ensures Explorer picks up the change right away; you don’t have to restart the process. - No Snap Impact: This setting exclusively controls Aero Shake. Window snap (the docking feature) is governed by separate registry keys and system parameters, so it will continue working normally.
If you ever need to re-enable Aero Shake, just change shakeDisabled to 0 and run the same logic.
内容的提问来源于stack exchange,提问作者Evgeniy Kozlov
相关产品推荐
相关产品推荐

