Skip to content

Instantly share code, notes, and snippets.

@goraj
Created June 11, 2018 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goraj/a2916da98806e30423d27671cfee21b6 to your computer and use it in GitHub Desktop.
Save goraj/a2916da98806e30423d27671cfee21b6 to your computer and use it in GitHub Desktop.
Borderless opencv window
def make_window_borderless(self):
"""
Requires: pywin32
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
import win32gui as wg
import win32api as wa
import win32con as wc
Based on: https://github.com/howardjohn/pyty/blob/master/src/window_api.py
"""
def restore(hwnd):
"""
Restores (unmaximizes) the window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_RESTORE)
def maximize(hwnd):
"""
Maximizes the window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_MAXIMIZE)
def hwnd_for_title(title):
def cb(hwnd, param):
title = ''.join(char for char in wg.GetWindowText(hwnd) if ord(char) <= 126)
d[title] = hwnd
d = {}
wg.EnumWindows(cb, title)
if title in d:
return d[title]
else:
return None
hwnd = hwnd_for_title(self.window_name)
style = wg.GetWindowLong(hwnd, wc.GWL_STYLE)
style &= ~wc.WS_OVERLAPPEDWINDOW
style |= wc.WS_POPUP
wg.SetWindowLong(hwnd, wc.GWL_STYLE, style)
rgb = wg.CreateSolidBrush(wa.RGB(0, 0, 0))
GCLP_HBRBACKGROUND = -10
wa.SetClassLong(hwnd, GCLP_HBRBACKGROUND, rgb)
maximize(hwnd)
restore(hwnd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment