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, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
