0

I'm trying to rename a window and remove all borders from it. I can shape it just fine using pygetwindow but for example, win = pygetwindow.getWindowsWithTitle('Notepad')[0] renames this window to Notepad1 so I can call another Notepad and rename it Notepad2 and control them independently, preferably not renaming them within the script but so the Windows process would be renamed.

The next step, I can see information for using tkinter to remove a title bar from my own program but how would I go about it for removing it from another application?

tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

2

You need to get a handle to the window and call SetWindowLong from winapi. This answer is translation of this answer from c# to python. (You need pywin32 if your python version >= 3.7)

import win32gui

windowHandle = win32gui.FindWindowEx(None, None, None, "Untitled - Notepad")
GWL_STYLE = -16  #  see https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlonga

#  get current window style
currentStyle = win32gui.GetWindowLong(windowHandle, GWL_STYLE)

#  remove titlebar elements
currentStyle = currentStyle & ~(0x00C00000)  #  WS_CAPTION
currentStyle = currentStyle & ~(0x00080000)  #  WS_SYSMENU
currentStyle = currentStyle & ~(0x00040000)  #  WS_THICKFRAME
currentStyle = currentStyle & ~(0x20000000)  #  WS_MINIMIZE
currentStyle = currentStyle & ~(0x00010000)  #  WS_MAXIMIZEBOX

#  apply new style
win32gui.SetWindowLong(windowHandle, GWL_STYLE, currentStyle)
unlut
  • 3,525
  • 2
  • 14
  • 23