Jump to content
Sign in to follow this  
goldenix

SetPixel close dll question

Recommended Posts

goldenix

I used this sample as a reference & made my script, but I have 2 questions:

1)

Is there an easy way to delete the rectangle after I move my mouse to new position? Right now it just keeps creating new rectangles. Or I need to get the pixels from my mouse coordinates, put them into array & then replace my old rectangle with those pixels to create illusion that the rectangle was deleted?

2)

Im I doing this right? Closing resources? Honestly I have no clue what im doing with those objects & dlls.

Edit: I asked around & it seems I need to get pixels, then use pen to draw rectangle, & then use pen to redraw the old pixels after all.

HotKeySet( "{ESC}", "Get_Exit")

    Global $Mpos_x = "", $Mpos_y = "", $line = ""
    $LineColor = 0x0000ff; color BGR
    $LineWidth = 1

    Global $user_dll = DllOpen('user32.dll')
    Global $gdi_dll = DllOpen("gdi32.dll")

    while 1
        GUICtrlDelete($line)

        $pos = MouseGetPos()

            $Mpos_x = $pos[0]
            $Mpos_y = $pos[1]

            _make_Rectangle(25,30) ; size 10x10 [x,y]

        Sleep(200)
    WEnd


Func _make_Rectangle($x_len,$y_len)

;~  ## First Line right
    $hd = DllCall($user_dll, "int", "GetDC", "hwnd", 0)
    $pen = DllCall($gdi_dll, "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    $obj_orig = DLLCall($gdi_dll,"int","SelectObject","int",$hd[0],"int",$pen[0])

    DllCall($gdi_dll, "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y, "int", 0)
    DllCall($gdi_dll, "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_x+$x_len, "int", $Mpos_y)

;~  ## then Line down
    $pos_1_x = $Mpos_x+$x_len
    $pos_1_y = $Mpos_y
    $pos_2_x = $Mpos_x+$x_len
    $pos_2_y = $Mpos_y+$y_len

    DllCall($gdi_dll, "int", "MoveToEx", "hwnd", $hd[0], "int", $pos_1_x, "int", $pos_1_y, "int", 0)
    DllCall($gdi_dll, "int", "LineTo", "hwnd", $hd[0], "int", $pos_2_x, "int", $pos_2_y)

    DLLCall($gdi_dll,"int","SelectObject","int",$hd[0],"int",$obj_orig[0])
    DLLCall($gdi_dll,"int","DeleteObject","int",$pen[0])
    DllCall($user_dll, "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])

EndFunc


Func Get_Exit()
    DllClose($gdi_dll)
    DllClose($user_dll)
    Exit
EndFunc
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×