Apps under Vista that are not linked with WINVER=6 will receive a misleading set of values here, that do not account for the extra padding of "glass" pixels Vista Aero applies to the window. This appears to happen even in Aero Basic (without Glass) to retain sizing consistency. The workaround (if you don't want to set WINVER=6) seems to be to dynamically bind to dwmapi.dll and use GetProcAddress() to obtain the DwmGetWindowAttribute() function, and call it with the DWMWA_EXTENDED_FRAME_BOUNDS argument to request the genuine window frame dimensions.
因此,基本上,使用类似的方法(您可能必须使用ctypes从Python中执行此操作):
RECT r;
HRESULT stat = DwmGetWindowAttribute (
hwnd,
DWMWA_EXTENDED_FRAME_BOUNDS,
&r,
sizeof(r));
我知道这是一个有点老的话题。但这需要相当多的搜索,我自己也经历了cTypesPain,才让paxdiablo的解决方案在Python中工作。只想分享wxPython的工作代码示例:
我的第一个想法列在下面,但是如果,正如您所说的,您确定
GetWindowRect
返回的值不正确,请参阅下面的RESOLUTION部分。“
GetSystemMetrics(SM_CXBORDER)
和GetSystemMetrics(SM_CYBORDER)
怎么了?你使用的方法似乎是一种非常迂回的方法,如果你可以调用} 。
GetWindowRect()
,我很确定你也可以调用^{另一种可能是使用^{} 获取窗口的整个边框,使用^{} 获取客户端(非边框)区域的边框。
这个应该给你类似于
(100,200),(1000,900)
和(112,227),(988,888)
的东西,你可以计算出上边框为227-200
,下边框为900-888
,左边框为112-100
,右边框为900-888
(27,12,12,12)。分辨率:
有人调查了一下。这是2006年的一个线程,指出您可能无法从
GetWindowsRect
获得正确的值。我所指的那条线说:因此,基本上,使用类似的方法(您可能必须使用ctypes从Python中执行此操作):
这会给你一个正确的边界矩形。
DwmGetWindowAttribute属性
http://msdn.microsoft.com/en-us/library/aa969515%28VS.85%29.aspx
相关问题 更多 >
编程相关推荐