hide window from MS windows taskbar

前端 未结 3 1259
别跟我提以往
别跟我提以往 2021-01-06 11:49

Using pyGtk I created a window without decoration. The Window is hidden from task bar and top of all windows. On linux it works fine, but on MS Windows window sometimes it h

相关标签:
3条回答
  • 2021-01-06 12:18

    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!

    0 讨论(0)
  • 2021-01-06 12:19

    Win32 solution provided in the other answer is not very easy and it does not play well with the GtkWindow::show method. A simple solution now in Gtk3 is:

    win->set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_UTILITY); //This works
    win->set_skip_taskbar_hint(); //This does not guarantee to work
    
    0 讨论(0)
  • 2021-01-06 12:32

    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")
    
    0 讨论(0)
提交回复
热议问题