hide window from MS windows taskbar

99封情书 提交于 2019-12-01 00:36:39

You have two options to remove a window from the taskbar:

  1. Add the WS_EX_TOOLWINDOW extended window style. But this has other consequences and I cannot say whether or not they are serious.
  2. Give the window an owner that is not visible. This allows you freedom to use whatever window styles and extended styles you wish, but does involve more work.

It's natural that your window will go beneath other windows. That's how windows works. If you want to make your window appear on top, show it with HWND_TOPMOST.

I've no idea how any of this is (or is not) implemented under PyGtk. I've just given you the Win32 answer!

Again thanks David Heffernan. Works perfect!

For people who want a full solution in python.

  • Name your windowin a characteristic way for example: 'alamakota'
  • Use find_window('alamakota'),
  • With given handler use hide_from_taskbar(handler)
  • Last use set_topmost(handler)

Window is hidden from taskbar and it's alwoays on top.

I know it's not a beatyfull code, but works fine on windows XP and above.

import ctypes
import win32gui
import win32api
from win32con import SWP_NOMOVE 
from win32con import SWP_NOSIZE 
from win32con import SW_HIDE
from win32con import SW_SHOW
from win32con import HWND_TOPMOST
from win32con import GWL_EXSTYLE 
from win32con import WS_EX_TOOLWINDOW

@staticmethod
def find_window(name):
    try:
        return win32gui.FindWindow(None, name)
    except win32gui.error:
        print("Error while finding the window")
        return None

@staticmethod   
def hide_from_taskbar(hw):
    try:
        win32gui.ShowWindow(hw, SW_HIDE)
        win32gui.SetWindowLong(hw, GWL_EXSTYLE,win32gui.GetWindowLong(hw, GWL_EXSTYLE)| WS_EX_TOOLWINDOW);
        win32gui.ShowWindow(hw, SW_SHOW);
    except win32gui.error:
        print("Error while hiding the window")
        return None

@staticmethod
def set_topmost(hw):
    try:
          win32gui.SetWindowPos(hw, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE)
    except win32gui.error:
        print("Error while move window on top")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!