Hi!
I am trying to making an On-Screen Display, which is implemented by
wx.Frame.
Basically I created a wx.Frame with style like
super(OSDBase, self).__init__( parent, id, title,
style = wx.STAY_ON_TOP |
wx.FRAME_NO_TAS KBAR |
wx.TRANSPARENT_ WINDOW |
wx.NO_BORDER)
self.SetTranspa rent(128)
But if I try to draw an image with alpha channel(like PNG format), I
always get
a background behind this image. But I don't want the background.
Then I read this article, http://www.codeproject.com/csharp/OSDwindow.asp
The demo program is written in C#. I understand that I need to use
UpdateLayeredWi ndow to update visual content of a layered window.
But I always got an error:
Traceback (most recent call last):
File "osd_post.p y", line 60, in <module>
osd.Update()
File "osd_post.p y", line 56, in Update
2)
pywintypes.erro r: (87, 'UpdateLayeredW indow', 'The parameter is
incorrect.')
I am not sure did I use UpdateLayeredWi ndow correctly.
Any help would be appreciated.
My Python is 2.5, pywin32 is 210, wxPython is 2.8.1
UpdateLayeredWi ndow Function Help from MSDN:
http://msdn2.microsoft.com/en-us/library/ms633556.aspx
UpdateLayeredWi ndow Function Help from pywin32:
My source code:
"""pyitctrl - OSD"""
# Created Date : 2007/03/14
# Author: livibetter
import wx, winxpgui, win32con
class OSDBase(wx.Fram e):
def __init__(self, parent, id, title):
super(OSDBase, self).__init__( parent, id, title,
style = wx.STAY_ON_TOP |
wx.FRAME_NO_TAS KBAR |
wx.TRANSPARENT_ WINDOW |
wx.NO_BORDER)
self.SetTranspa rent(128)
print hex(winxpgui.Ge tWindowLong(sel f.GetHandle(),
win32con.GWL_EX STYLE))
print winxpgui.GetLay eredWindowAttri butes(self.GetH andle())
self.img = wx.Image("icon. png")
self.bmp = self.img.Conver tToBitmap()
w, h = self.bmp.GetWid th(), self.bmp.GetHei ght()
self.SetClientS ize( (w, h) )
def Update(self):
print "Update"
screenDC = winxpgui.GetDC( winxpgui.GetDes ktopWindow())
print screenDC
cScreenDC = winxpgui.Create CompatibleDC(0)
print cScreenDC
(w, h) = self.GetSizeTup le()
bmp = wx.EmptyBitmap( w, h)
tmpDC = wx.MemoryDC()
tmpDC.SelectObj ect(bmp)
tmpDC.SetBackgr ound(wx.Brush(" BLACK"))
tmpDC.Clear()
tmpDC.DrawBitma p(self.bmp,0,0, True)
tmpDC.Destroy()
del tmpDC
winxpgui.Select Object(cScreenD C, bmp.GetHandle() )
winxpgui.Update LayeredWindow(s elf.GetHandle() ,
screenDC,
self.GetPositio nTuple(),
self.GetSizeTup le(),
cScreenDC,
(0,0),
0,
(0,0,128,1),
win32con.ULW_AL PHA)
app = wx.App(False)
osd = OSDBase(None, wx.ID_ANY, 'OSD Frame')
osd.Update()
osd.Show()
app.MainLoop()
I am trying to making an On-Screen Display, which is implemented by
wx.Frame.
Basically I created a wx.Frame with style like
super(OSDBase, self).__init__( parent, id, title,
style = wx.STAY_ON_TOP |
wx.FRAME_NO_TAS KBAR |
wx.TRANSPARENT_ WINDOW |
wx.NO_BORDER)
self.SetTranspa rent(128)
But if I try to draw an image with alpha channel(like PNG format), I
always get
a background behind this image. But I don't want the background.
Then I read this article, http://www.codeproject.com/csharp/OSDwindow.asp
The demo program is written in C#. I understand that I need to use
UpdateLayeredWi ndow to update visual content of a layered window.
But I always got an error:
Traceback (most recent call last):
File "osd_post.p y", line 60, in <module>
osd.Update()
File "osd_post.p y", line 56, in Update
2)
pywintypes.erro r: (87, 'UpdateLayeredW indow', 'The parameter is
incorrect.')
I am not sure did I use UpdateLayeredWi ndow correctly.
Any help would be appreciated.
My Python is 2.5, pywin32 is 210, wxPython is 2.8.1
UpdateLayeredWi ndow Function Help from MSDN:
http://msdn2.microsoft.com/en-us/library/ms633556.aspx
UpdateLayeredWi ndow Function Help from pywin32:
My source code:
"""pyitctrl - OSD"""
# Created Date : 2007/03/14
# Author: livibetter
import wx, winxpgui, win32con
class OSDBase(wx.Fram e):
def __init__(self, parent, id, title):
super(OSDBase, self).__init__( parent, id, title,
style = wx.STAY_ON_TOP |
wx.FRAME_NO_TAS KBAR |
wx.TRANSPARENT_ WINDOW |
wx.NO_BORDER)
self.SetTranspa rent(128)
print hex(winxpgui.Ge tWindowLong(sel f.GetHandle(),
win32con.GWL_EX STYLE))
print winxpgui.GetLay eredWindowAttri butes(self.GetH andle())
self.img = wx.Image("icon. png")
self.bmp = self.img.Conver tToBitmap()
w, h = self.bmp.GetWid th(), self.bmp.GetHei ght()
self.SetClientS ize( (w, h) )
def Update(self):
print "Update"
screenDC = winxpgui.GetDC( winxpgui.GetDes ktopWindow())
print screenDC
cScreenDC = winxpgui.Create CompatibleDC(0)
print cScreenDC
(w, h) = self.GetSizeTup le()
bmp = wx.EmptyBitmap( w, h)
tmpDC = wx.MemoryDC()
tmpDC.SelectObj ect(bmp)
tmpDC.SetBackgr ound(wx.Brush(" BLACK"))
tmpDC.Clear()
tmpDC.DrawBitma p(self.bmp,0,0, True)
tmpDC.Destroy()
del tmpDC
winxpgui.Select Object(cScreenD C, bmp.GetHandle() )
winxpgui.Update LayeredWindow(s elf.GetHandle() ,
screenDC,
self.GetPositio nTuple(),
self.GetSizeTup le(),
cScreenDC,
(0,0),
0,
(0,0,128,1),
win32con.ULW_AL PHA)
app = wx.App(False)
osd = OSDBase(None, wx.ID_ANY, 'OSD Frame')
osd.Update()
osd.Show()
app.MainLoop()
Comment