从MS Windows任务栏隐藏窗口

Dra*_*ter 3 python windows winapi pygtk win32gui

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

图像代表我的问题:

在此输入图像描述

如何从任务栏隐藏此"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()
Run Code Online (Sandbox Code Playgroud)

Dra*_*ter 6

再次感谢David Heffernan.作品完美!

对于想要在python中获得完整解决方案的人.

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

窗口是从任务栏隐藏的,它在顶部是另一个.

我知道它不是一个很好的代码,但在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")
Run Code Online (Sandbox Code Playgroud)