Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > UpdateLayeredWindow in pywin32

Reply
Thread Tools

UpdateLayeredWindow in pywin32

 
 
livibetter
Guest
Posts: n/a
 
      04-16-2007
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_TASKBAR |
wx.TRANSPARENT_WINDOW |
wx.NO_BORDER)
self.SetTransparent(12

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
UpdateLayeredWindow to update visual content of a layered window.

But I always got an error:

Traceback (most recent call last):
File "osd_post.py", line 60, in <module>
osd.Update()
File "osd_post.py", line 56, in Update
2)
pywintypes.error: (87, 'UpdateLayeredWindow', 'The parameter is
incorrect.')

I am not sure did I use UpdateLayeredWindow correctly.

Any help would be appreciated.


My Python is 2.5, pywin32 is 210, wxPython is 2.8.1

UpdateLayeredWindow Function Help from MSDN:
http://msdn2.microsoft.com/en-us/library/ms633556.aspx

UpdateLayeredWindow Function Help from pywin32:
http://aspn.activestate.com/ASPN/doc...ndow_meth.html

My source code:

"""pyitctrl - OSD"""
# Created Date : 2007/03/14
# Author: livibetter

import wx, winxpgui, win32con

class OSDBase(wx.Frame):
def __init__(self, parent, id, title):
super(OSDBase, self).__init__(parent, id, title,
style = wx.STAY_ON_TOP |
wx.FRAME_NO_TASKBAR |
wx.TRANSPARENT_WINDOW |
wx.NO_BORDER)
self.SetTransparent(12

print hex(winxpgui.GetWindowLong(self.GetHandle(),
win32con.GWL_EXSTYLE))
print winxpgui.GetLayeredWindowAttributes(self.GetHandle ())

self.img = wx.Image("icon.png")
self.bmp = self.img.ConvertToBitmap()
w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
self.SetClientSize( (w, h) )

def Update(self):
print "Update"

screenDC = winxpgui.GetDC(winxpgui.GetDesktopWindow())
print screenDC
cScreenDC = winxpgui.CreateCompatibleDC(0)
print cScreenDC

(w, h) = self.GetSizeTuple()
bmp = wx.EmptyBitmap(w, h)
tmpDC = wx.MemoryDC()
tmpDC.SelectObject(bmp)
tmpDC.SetBackground(wx.Brush("BLACK"))
tmpDC.Clear()
tmpDC.DrawBitmap(self.bmp,0,0, True)
tmpDC.Destroy()
del tmpDC

winxpgui.SelectObject(cScreenDC, bmp.GetHandle())

winxpgui.UpdateLayeredWindow(self.GetHandle(),
screenDC,
self.GetPositionTuple(),
self.GetSizeTuple(),
cScreenDC,
(0,0),
0,
(0,0,128,1),
win32con.ULW_ALPHA)

app = wx.App(False)
osd = OSDBase(None, wx.ID_ANY, 'OSD Frame')
osd.Update()
osd.Show()

app.MainLoop()

 
Reply With Quote
 
 
 
 
livibetter
Guest
Posts: n/a
 
      04-17-2007
I have found the cause

"Please note that after SetLayeredWindowAttributes has been called,
subsequent UpdateLayeredWindow calls will fail until the layering
style bit is cleared and set again."
from http://msdn2.microsoft.com/en-us/lib...9.aspx#layered

But I still can't use winxpgui.UpdateLayeredWindow, Now I am using
ctypes to enable calling UpdateLayeredWindow, and this works.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pywin32 support for CreateTypeLib2 Philip Rittenhouse Python 6 06-30-2004 07:57 PM
pywin32 custom i/f COM servers do not support variable or optional args Philip Rittenhouse Python 0 06-30-2004 07:25 PM
pywin32 201.1 Windows98SE Problem? Bob Chapman Python 4 05-30-2004 05:14 AM
ANNOUNCE: Build 200 of the pywin32 extensions (win32all) available Mark Hammond Python 11 02-17-2004 12:16 AM
pywin32 COM Problem with Excel Range Offset? Michael Jordan Python 2 02-12-2004 07:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57