[python-win32] win32gui and PyHANDLE

Alexandru Ionescu q_crack at yahoo.com
Thu Aug 19 08:24:52 CEST 2010


Hello,


In the last two weeks I've been trying to properly use UpdateLayeredWindow in 
Python but I'm only getting errors. I want to make a quality window with per 
pixel alpha graphics. I tried with win32gui & win32api and I also tried 
with ctypes. I got all kinds of errors. In the end I got this error:
gwl = win32api.GetWindowLong(hwnd,  GWL_EXSTYLES)
OverflowError: Python int too large to convert to C long
Here is my latest code (made with win32gui & win32api):
#==================================================================
import wx
import win32gui
import win32api      #for RGB

GWL_EXSTYLE = 0xFFFFFFEC
WS_EX_LAYERED = 0x00080000
WS_EX_TRANSPARENT = 0x00000020
LWA_ALPHA = 0x00000002
LWA_COLORKEY = 0x00000001
AC_SRC_ALPHA = 0x01
AC_SRC_OVER = 0x00

class  MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, title = "Test")
        hwnd = self.GetHandle()  
        gwl = win32api.GetWindowLong(hwnd, GWL_EXSTYLE)
        win32gui.SetWindowLong(hwnd, GWL_EXSTYLE, (gwl | WS_EX_LAYERED))
        
        self.bmp = wx.EmptyBitmap(800,600)
        jpg1 = wx.Image('Multiple alpha.png', wx.BITMAP_TYPE_PNG)
        self.bmp = jpg1.ConvertToBitmap()
        w1, h1 = self.bmp.GetWidth(), self.bmp.GetHeight()
        self.SetClientSize( (w1, h1) )
         
        screenDC = win32gui.GetDC(None)
        cScreenDC = win32gui.CreateCompatibleDC(screenDC)
        win32gui.SelectObject(cScreenDC, self.bmp.GetHandle())
        p = wx.Point(50,50)
        p2 = wx.Point(0,0)
        s = wx.Size(816,612)
        blend = PyBLENDFUNCTION(AC_SRC_OVER,0,200,AC_SRC_ALPHA)
        
        crkey = win32api.RGB(255,255,0)
        flags = (LWA_ALPHA | LWA_COLORKEY)
        
        print win32gui.UpdateLayeredWindow(hwnd,
                                           screenDC,
                                          p,
                                          s,
                                          cScreenDC,
                                          p2,
                                          crkey,
                                           blend,
                                          flags)

app = wx.App()
frame = MyFrame()
frame.Show()
app.SetTopWindow(frame)
app.MainLoop()
#==================================================================


You can find a multi layer PNG at the following link
http://en.wikipedia.org/wiki/File:PNG_transparency_demonstration_1.png
or you can use another image.

Thank you,
Alexandru Ionescu



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100818/576f99a9/attachment.html>


More information about the python-win32 mailing list