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 ctypes and I also tried with win32gui & win32api. I got all kinds of errors. In the end I got the error code 5 (ERROR_ACCESS_DENIED) and nothing appears on the screen.
Here is my latest code (made with ctypes): -
import wx
-
import win32api #for RGB
-
import ctypes
-
-
cUser32 = ctypes.windll.user32
-
cGdi32 = ctypes.windll.gdi32
-
cKernel32 = ctypes.windll.kernel32
-
-
class POINT(ctypes.Structure):
-
_fields_ = [("x", ctypes.c_int), ("y", ctypes.c_int)]
-
-
class SIZE(ctypes.Structure):
-
_fields_ = [("cx", ctypes.c_int), ("cy", ctypes.c_int)]
-
-
class BLENDFUNCTION(ctypes.Structure):
-
_fields_ = [("AlphaFormat", ctypes.c_int), ("BlendFlags", ctypes.c_int),("BlendOp", ctypes.c_int),("SourceConstantAlpha", ctypes.c_int)]
-
-
ULW = cUser32.UpdateLayeredWindow
-
ULW.argtypes = [ctypes.c_ulong,
-
ctypes.c_ulong,
-
ctypes.POINTER(POINT),
-
ctypes.POINTER(SIZE),
-
ctypes.c_ulong,
-
ctypes.POINTER(POINT),
-
ctypes.c_ulong,
-
ctypes.POINTER(BLENDFUNCTION),
-
ctypes.c_ulong]
-
-
ULW.restype = ctypes.c_long
-
-
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()
-
print hwnd
-
gwl = cUser32.GetWindowLongA(hwnd, GWL_EXSTYLE)
-
print gwl
-
print cUser32.SetWindowLongA(hwnd, GWL_EXSTYLE, (gwl | WS_EX_LAYERED))
-
print cKernel32.GetLastError()
-
-
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 = cUser32.GetDC(None)
-
cScreenDC = cGdi32.CreateCompatibleDC(screenDC)
-
cGdi32.SelectObject(cScreenDC, self.bmp.GetHandle())
-
p = POINT(50,50)
-
p2 = POINT(0,0)
-
s = SIZE(816,612)
-
blend = BLENDFUNCTION(AC_SRC_OVER,0,AC_SRC_ALPHA,200)
-
-
crkey = win32api.RGB(255,255,255)
-
flags = (LWA_ALPHA | LWA_COLORKEY)
-
-
print cUser32.UpdateLayeredWindow(hwnd,
-
screenDC,
-
ctypes.byref(p),
-
ctypes.byref(s),
-
cScreenDC,
-
ctypes.byref(p2),
-
crkey,
-
ctypes.byref(blend),
-
flags)
-
-
print cKernel32.GetLastError()
-
-
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
I also attached this image and the code (in a .pyw file).
My email address is q_crack@yahoo.com
Thank you,
Alex
0 1360 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Edmond Rusjan |
last post by:
Hi All,
I'd like to use Python-2.3.4 on OSF1 V4.0, but have trouble
installing.
With a plain "./configure; make" build, I cannot import socket.
If I uncomment the socketmodule in Modules/Setup,...
|
by: tjv |
last post by:
Hi all,
I am working with images in python using PIL. I come from a MATLAB
background so I am finding it to be sometimes frustrating to do things
correctly and quickly. All I need to do is load an...
|
by: eduardo.padoan |
last post by:
I'm reading about "high order messages" in Ruby by Nat Pryce, and
thinking if it could be util and if so, if it could be done in Python.
Someone already tried?
References:...
|
by: Allan |
last post by:
I've been trying to get this to work for days. I have a form which needs to
be transparent (only the form background). On the form there are two images
(32 bit PNGs) with alpha channel...
|
by: Andrew Christiansen |
last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for
instance in Photoshop text with a dropshadow with a transparent canvas) I've
been saving in PNG format and then using...
|
by: illegal.prime |
last post by:
Hi all, I'm looking for the right way to create a checkered background
in a PictureBox. I will be applying various images to this PictureBox
and I want to to see the checkered background based on...
|
by: Carsten Schmitt |
last post by:
Hello,
I want to draw a simple pixel (i.e. a red pixel in the center of the
screen), which is always in the foreground - even when running a fullscreen
application like a DirectX game.
I need...
|
by: Gernot Frisch |
last post by:
Hi,
I have this code that blends 2 pixels, but it's not really fast. Can
someone help me speeding it up?
#define GETR(a) (unsigned char)(((((a)>>11)&31)*255)/31)
#define GETG(a) (unsigned...
|
by: livibetter |
last post by:
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 =...
|
by: raylopez99 |
last post by:
After refering to the below thread, I take it for C# Forms 2.0, there
a way to draw a 1 pixel by 1 pixel rectangle, which I was able to do
just now successfully.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |