 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
philz
Joined: 05 Jun 2007 Posts: 78 Location: USA
|
Posted: Tue Apr 22, 2008 1:31 pm Post subject: dllcall help rectangle |
|
|
how can I get this to redraw so older rectangles are erased?
I know it sounds like a vague question but run the code, click the mouse somewhere, move your mouse in one direction for a bit, then move your mouse back. You will notice that all of the older, bigger rectangles are still there. How could I get rid of those
Here's the code which is inspired by this script.
| Code: |
lbutton::
mousegetpos,x1,y1
settimer, rectangle, 100
return
rectangle:
mousegetpos,x2,y2,win
winset,redraw,,ahk_id %win%
drawrect(x1,y1,x2,y2)
return
drawrect(x1,y1,x2,y2,color=0x0000ff)
{
guiID := WinExist()
hdc := DllCall("GetDC", "UInt", guiID, "UInt")
ps_Dash:=1
hPen := DllCall("CreatePen", "Int",PS_DASH, "Int", 1, "Int", color, "UInt")
objB := DllCall("SelectObject", "UInt", hdc, "UInt", brush, "UInt")
objP := DllCall("SelectObject", "UInt", hdc, "UInt", hPen, "UInt")
DllCall("Rectangle", "UInt", hdc, "Int", x1, "Int", y1, "Int", x2, "Int", y2)
}
escape::
exitapp
return
|
for my purposes I will need to also be able to remove this rectangle. |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 295 Location: canada
|
Posted: Tue Apr 22, 2008 1:48 pm Post subject: |
|
|
to clean the screen after I use
| Code: | DllCall("ReleaseDC", UInt, 0, UInt, hDrwArea)
DllCall("FreeLibrary", "UInt", hDrwArea)
DllCall("RedrawWindow", "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0x81) |
for my scripts
I hope thats what you need.
it will remove all drawn lines _________________ -=Raz=- |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2492 Location: Australia, Qld
|
Posted: Mon May 19, 2008 10:46 am Post subject: |
|
|
In this thread I offered critique of code that it seems was copied from this thread, so here it is again:
| I wrote: | Device contexts retrieved via GetDC must be released via ReleaseDC, or your script will leak resources. Similarly, GDI objects which you create (such as pens) must also be deleted manually, after reselecting the original object of the relevant type in the device context:
| Code: | ; after calling Rectangle():
; Reselect the original pen so hPen can be deleted:
DllCall("SelectObject", "uint", hdc, "uint", objP)
; Delete hPen:
DllCall("DeleteObject", "uint", hPen)
; This may or may not be necessary if you don't need to delete 'brush':
DllCall("SelectObject", "uint", hdc, "uint", objB)
; Release the device context returned by GetDC:
DllCall("ReleaseDC", "uint", guiID, "uint", hdc)
| ...
Since PS_DASH has not been assigned a value, it is interpreted as 0, which is PS_SOLID. Substitute PS_DASH in your code for the value 1, or assign PS_DASH:=1 before calling CreatePen.
| Quote: | DllCall("ReleaseDC", UInt, 0, UInt, hDrwArea)
DllCall("FreeLibrary", "UInt", hDrwArea) | I'm guessing these are copy-paste remnants, since your script doesn't seem to assign hDrwArea a value. ReleaseDC expects a handle to a device context, whereas FreeLibrary expects a handle to a module (DLL). One, the other, or both are sure to fail. In this case it is probably best to delete both lines. |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|