GetWindowRect too small on Windows 7

前端 未结 6 1029
灰色年华
灰色年华 2020-11-28 11:41

The actual problem I\'m trying to solve is, I want to automatically find out the size of the margins around windows. If you can find a better way, please by all means answer

6条回答
  •  旧巷少年郎
    2020-11-28 12:10

    I know it is a bit old topic. But it took quite a bit of searching and I went through the ctypes pain myself to get paxdiablo's solution working in Python. Just wanted to share working code sample for wxPython:

    try:
        f = ctypes.windll.dwmapi.DwmGetWindowAttribute
    except WindowsError:
        f = None
    if f: # Vista & 7 stuff
        rect = ctypes.wintypes.RECT()
        DWMWA_EXTENDED_FRAME_BOUNDS = 9
        f(ctypes.wintypes.HWND(self.GetHandle()),
          ctypes.wintypes.DWORD(DWMWA_EXTENDED_FRAME_BOUNDS),
          ctypes.byref(rect),
          ctypes.sizeof(rect)
          )
        size = (rect.right - rect.left, rect.bottom - rect.top)        
    else:      
        size = self.GetSize()
    

提交回复
热议问题