Jump to content

Postmessages and Paint


Slaiochi
 Share

Recommended Posts

Trying to make a program that reads numbers from a file, and based on these numbers picks a color and "draws" an image. It was soooo slow with the MouseClick function (Around 6-7 minutes for a 88x72 pixel picture x[) So, I made decided to use a Postmessage function I used for making game bots, the exception is that it is no longer working when I try to use Paint.

#include <PostMessage_UDF.au3>
HotKeySet("{PGDN}", "Terminate")

Global $read, $i, $hWnd

$file = FileOpen("C:\PixelInfo.txt", 0)
Do
$read &= FileRead($file, 1)
Until @error = -1

MsgBox(0, "File Read", "Information has been parsed.")

$hWnd = WinGetHandle("untitled - Paint")

If @error Then
    MsgBox(0, "Window Not Found", "Window couldn't be found.")
    Exit
EndIf

For $yInc = 0 to 71
For $xInc = 0 to 87
$x = $xInc + 61
$y = $yInc + 43
$numRead = StringMid($read, $i, 1)
_GetColor()
_MouseClick ($hWnd, "left", $x, $y, 1, 1)
$i = $i + 1
$prg = Int((($yInc / 71) * 100))
ToolTip("Progress: [" & $prg & "%]", -1, -1)
Next
Next

Func _GetColor()
    If $numRead = 0 Then
        _MouseClick ($hWnd, "left", 43, 682, 1, 0)
    EndIf
    If $numRead = 1 Then
        _MouseClick ($hWnd, "left", 59, 682, 1, 0)
    EndIf
    If $numRead = 2 Then
        _MouseClick ($hWnd, "left", 75, 682, 1, 0)
    EndIf
    If $numRead = 3 Then
        _MouseClick ($hWnd, "left", 91, 682, 1, 0)
    EndIf
    If $numRead = 4 Then
        _MouseClick ($hWnd, "left", 107, 682, 1, 0)
    EndIf
    If $numRead = 5 Then
        _MouseClick ($hWnd, "left", 123, 682, 1, 0)
    EndIf
    If $numRead = 6 Then
        _MouseClick ($hWnd, "left", 139, 682, 1, 0)
    EndIf
    If $numRead = 7 Then
        _MouseClick ($hWnd, "left", 155, 682, 1, 0)
    EndIf
EndFunc

Func Terminate()
    Exit 0
EndFunc

Also, the _MouseClick function:

Func _MouseClick($hWnd, $button, $x, $y, $times=1, $delay=250)
    If $hWnd = 0 Then
        SetError(-1)
        Return
    EndIf
    
    Local $ix
    Local $lParam = _MakeLong($x, $y)
    Local $user32 = DllOpen("user32.dll")
    
    $button = StringLower($button)
    
    If $button = "left" Then
        For $ix = 1 To $times
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", $lParam)
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 1, "long", $lParam)
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", $lParam)
            
            If $ix < $times Then Sleep($delay)
        Next
    ElseIf $button = "right" Then
        For $ix = 1 To $times
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", $lParam)
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x204, "int", 2, "long", $lParam)
            DllCall($user32, "int", "PostMessage", "hwnd", $hWnd, "int", 0x205, "int", 0, "long", $lParam)
            
            If $ix < $times Then Sleep($delay)
        Next
    Else
        SetError(-2)
        If $user32 <> -1 Then DllClose($user32)
        Return
    EndIf
    If $user32 <> -1 Then DllClose($user32)
EndFunc

Any thoughts? :)

Link to comment
Share on other sites

Work area - ControlGetHandle("[CLASS:MSPaintApp]", "", "[CLASS:Afx:1000000:8]")

Color toolbar - ControlGetHandle("[CLASS:MSPaintApp]", "", "[CLASS:AfxWnd42u]")

Edited by Siao

"be smart, drink your wine"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...