AutoHotkey Community

It is currently May 26th, 2012, 6:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: dllcall help rectangle
PostPosted: April 22nd, 2008, 1:31 pm 
Offline

Joined: June 5th, 2007, 10:57 pm
Posts: 89
Location: USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2008, 1:48 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
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=-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 10:46 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Tipsy3000 and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group