从MS Windows任务栏隐藏窗口

时间:2013-10-17 11:08:32

标签: python windows winapi pygtk win32gui

使用pyGtk我创建了一个没有装饰的窗口。窗口隐藏在任务栏和所有窗口的顶部。在Linux上它工作正常,但在MS Windows窗口有时它隐藏在其他窗口下,并且在Windows中始终有“python.exe”任务栏。

代表我问题的图片:

enter image description here

如何从任务栏隐藏此“python.exe”窗口?

我的代码:

class Infowindow(gtk.Window):
'''
Klasa okienka informacyjnego
'''
def __init__(self, json, index, destroy_cb, device):
    gtk.Window.__init__(self)
    self.size_x = 260+48
    self.size_y = 85
    self.separator_size = 10
    self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN)
    self.set_decorated(False)
    self.set_property('skip-taskbar-hint', True)
    self.set_opacity(1)
    self.set_keep_above(True)
    self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
    self.connect("enter-notify-event", self.__on_hover)
    self.connect("leave-notify-event", self.__on_leave)
    self.connect("button_press_event", self.__on_click)
    self.set_size_request(self.size_x, self.size_y)
    color = gtk.gdk.color_parse('#f3f3f3')
    self.modify_bg(gtk.STATE_NORMAL, color)

    self.expanded = False
    self.index = index
    self.destroy_cb = destroy_cb
    self.json = json['data']
    self.system_info = False if 'system' not in self.json or not self.json['system'] else True
    self.device = device
    f = gtk.Frame()
    self.move_window(index) #move window to specified place
    self.box_area = gtk.VBox()
    self.box_area.set_spacing(10)
    f.add(self.box_area)
    self.add(f)
    self.show_all()

3 个答案:

答案 0 :(得分:6)

再次感谢David Heffernan。工作完美!

对于想要在python中使用完整解决方案的人。

  • 以特有的方式命名您的窗口,例如:'alamakota'
  • 使用find_window('alamakota'),
  • 使用给定的处理程序使用hide_from_taskbar(处理程序)
  • 上次使用set_topmost(handler)

窗口在任务栏中隐藏,而且它在顶部是一直存在的。

我知道这不是一个很好的代码,但在Windows XP及更高版本上运行良好。

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")

答案 1 :(得分:3)

您有两个选项可以从任务栏中删除窗口:

  1. 添加WS_EX_TOOLWINDOW扩展窗口样式。但这有其他后果,我不能说他们是否认真。
  2. 为窗口提供不可见的所有者。这允许您自由地使用您希望的任何窗口样式和扩展样式,但确实涉及更多工作。
  3. 很自然,你的窗户会在其他窗户下方。这就是Windows的工作原理。如果您想让窗口显示在顶部,请使用HWND_TOPMOST显示。

    我不知道在PyGtk下如何实现(或不实现)。我刚刚给你Win32答案!

答案 2 :(得分:0)

在另一个答案中提供的

Win32解决方案不是很容易,并且不能与GtkWindow :: show方法配合使用。现在,在Gtk3中一个简单的解决方案是:

win->set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_UTILITY); //This works
win->set_skip_taskbar_hint(); //This does not guarantee to work