[python-win32] win32ui and flashing box

Richard Bell rbell01824 at earthlink.net
Fri Jul 27 05:03:49 CEST 2007


Tim,

Thanks for the help.  Here's what I've got

import win32gui
import win32ui
import time
gui_dc = win32gui.GetDC(0)                      # int handle of DC for
screen
pycdc = win32ui.CreateDCFromHandle(gui_dc)      # PyCDC object
pycdc.SetROP2(7)                                # R2_XOR (i think)
for i in range(0,5):
    pycdc.Rectangle((1400, 200, 1500, 300))     # make a solid rectangle
(but how to make hollow)
    time.sleep(.250)                            # hang out
    pycdc.Rectangle((1400, 200, 1500, 300))     # put the screen back
    time.sleep(.250)                            # hang out
win32gui.ReleaseDC(gui_dc,0)                    # is this all I have to
release?
print 'done'

It seems to basically work but am I releasing/deleting things appropriately
(I read something online about being sure to do so)?

Regards,
Richard

|-----Original Message-----
|From: python-win32-bounces at python.org [mailto:python-win32-
|bounces at python.org] On Behalf Of Tim Roberts
|Sent: Thursday, July 26, 2007 6:07 PM
|To: Python-Win32 List
|Subject: Re: [python-win32] win32ui and flashing box
|
|Richard Bell wrote:
|> I'm working on an application that automated IE and want to draw a
|flashing
|> box around screen elements.  I can find the coordinates OK but am a bit
|> unclear on how to actually draw a box in such a fashion that when the
|> flashing stops the screen is as it was before it started.  A bit of
|> investigation suggests that something like this ought to work:
|>
|> import win32gui, win32ui
|> def box(hdc, x, y, w, h):
|>     hdc.MoveTo(x, y)
|>     hdc.LineTo(x+w, y)
|>     hdc.LineTo(x+w, y+h)
|>     hdc.LineTo(x, h+h)
|>     hdc.LineTo(x, y)
|>
|> hdc = win32ui.CreateDCFromHandle(win32gui.GetDesktopWindow())
|>
|
|CreateDCFromHandle creates a Python wrapper from a Windows HDC handle.
|You're passing it a window handle, not a DC handle.  Try this instead:
|
|  hdc = win32ui.CreateDCFromHandle( win32gui.GetDC( 0 ) )
|
|You can use win32gui.GetDesktopWindow() instead of the 0 if you want.
|They should do the exact same thing.
|
|> But when I run the code I get a win32ui: LineTo failed exception.  Is
|there
|> a simple way of doing this?
|>
|
|This is NOT going to draw it in an erasable way.  If you want to draw a
|flashing box that can be removed, you need to change the ROP2 to, for
|example, R2_NOT.  That will invert the colors every time you draw it.
|Draw it once, you see it; draw it again, it disappears.
|
|Also note that dc.Rectangle is quicker than four LineTo calls.
|
|--
|Tim Roberts, timr at probo.com
|Providenza & Boekelheide, Inc.
|
|_______________________________________________
|Python-win32 mailing list
|Python-win32 at python.org
|http://mail.python.org/mailman/listinfo/python-win32



More information about the Python-win32 mailing list