Jump to content
Sign in to follow this  
Slaiochi

Postmessages and Paint

Recommended Posts

Slaiochi

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? :)

Share this post


Link to post
Share on other sites
Sardith

You wrote this?

Talk to Outshynd. lol


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites
Slaiochi

I never claimed to have written the PostMessage function, only that I had used it before and it always worked.

Still not working, any help?

Share this post


Link to post
Share on other sites
Siao

Use the handle of paint area control, not the handle of program window.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites
Slaiochi

Tried doing that, maybe I got the wrong control name.. Giving it another try.

Can't find the paint area control, need other control handles as well, as this program has to change colors. D=

Edited by Slaiochi

Share this post


Link to post
Share on other sites
Siao

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

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

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites
Slaiochi

It's definitely clicking in the windows now, but it's very buggy. Sometimes drags the color box around and such >_>

Share this post


Link to post
Share on other sites
Slaiochi

Never mind, had to update coords to be relative to the control, not the window.

Cheers!

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  

×