Jump to content

Recommended Posts

Posted

OK first I have to apologize for this sloppy code. I was trying to write a program that marks up the desktop (or any app pulled up). Basically I wanted a little GUI with a button that toggled from draw mode to disabled. Sounds simple right? Well not for me, Ive been trying this for 3 hours now (now that I know how to use the GDI32.dll) though the program sort of works there are several things that I cant get over

1) I do not know how to disable mouse input so the click and drag is erasing my red line (if you pull the program up in something that doesnt refresh, like the grey area in MSPAINT, it works, kind of)

2) My draw rate is pretty spotty if you move the mouse to fast. This isnt horrible though I feel that I can handle the latency

3) I do not know how to wait for the user to click the mouse (ie draw a line) and still take input from the button. Basically I want

While _ispressed(01) and GUICtrlRead ($toggle)=Draw Mode
monitor for mouse click
Wend

However when I am monitoring this loop I cant update the GUI (ie allow the user to uninitiate the function).

I am so close to have a nifty app and I searched this forum and the only thing I could find that was close was that line drawing program. I think this will be much more usefull.

I'd like to say I'm new to AutoIT but I'm not, however this is one of my first attempts at the GUI and my absolute first attempt at pixel play.

Here is my complete/butchered code.

#Include <Misc.au3>
#include <Array.au3>
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$mainwindow = GuiCreate("Screen Draw", 200, 200,"","",$WS_EX_APPWINDOW)
WinSetOnTop ( "Screen Draw", "", 1 )
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

$linecolor = 0x0000ff; color BGR
$linewidth = 3
$hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
$pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)

; BUTTON
$toggle = GuiCtrlCreateButton("Disabled", 75, 75, 70, 30)
GUICtrlSetOnEvent($toggle, "FunDraw")

;Position of button
$windowpos = WinGetPos("Screen Draw")
$buttonposx = $windowpos[0]+75
$buttonposy = $windowpos[1]+75



; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func CLOSEClicked()
    Exit
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While 1
    Sleep(100)
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunDraw()
$state=GUICtrlRead ($toggle)
If $state = "Disabled" Then
    GUICtrlSetData ($toggle, "Draw Mode" )
    WinSetState ( "Screen Draw", "", @SW_MINIMIZE )
    $pos = MouseGetPos()
    While WinActive ( "Screen Draw" )=0
        If _IsPressed("01") Then
            $pos = MouseGetPos()
            For $xcoord = 1 to $linewidth
                For $ycoord = 1 to $linewidth
                    DllCall("gdi32.dll","long","SetPixel", "long", $hd[0], "long", $xcoord+$pos[0], "long", $ycoord+$pos[1], "long", $LineColor)
                Next
            Next
        Endif
    WEnd
Else
GUICtrlSetData ($toggle, "Disabled" )
EndIf
EndFunc

Thanks a bunch

Posted

Definetly. This is only the UTLRA alpha, I just started writting it recently. However it still is a bit glitchy. Once some people help refine it I will put the completed script in the exampels section (colors and all).

Posted

Definetly. This is only the UTLRA alpha, I just started writting it recently. However it still is a bit glitchy. Once some people help refine it I will put the completed script in the exampels section (colors and all).

Ideas:

1) Try GUIGetCursorInfo() instead of _IsPressed() - maybe it will be faster (not tested)

2) instead of double For Next with SetPixel use some other API, for example "Circle" which will be sized by desired "pen width"

Posted

ha ha, cool

Made a sort of brush pattern infact it's more of a knackered roller :)

#Include <Misc.au3>
#include <Array.au3>
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$mainwindow = GuiCreate("Screen Draw", 200, 200,"","",$WS_EX_APPWINDOW)
WinSetOnTop ( "Screen Draw", "", 1 )
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

$linecolor = 0x0000ff; color BGR
$linewidth = 3
$hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
$pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)

; BUTTON
$toggle = GuiCtrlCreateButton("Disabled", 75, 75, 70, 30)
GUICtrlSetOnEvent($toggle, "FunDraw")

;Position of button
$windowpos = WinGetPos("Screen Draw")
$buttonposx = $windowpos[0]+75
$buttonposy = $windowpos[1]+75



; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func CLOSEClicked()
    Exit
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While 1
    Sleep(100)
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunDraw()
$state=GUICtrlRead ($toggle)
If $state = "Disabled" Then
    GUICtrlSetData ($toggle, "Draw Mode" )
    WinSetState ( "Screen Draw", "", @SW_MINIMIZE )
    $pos = MouseGetPos()
    While WinActive ( "Screen Draw" )=0
        If _IsPressed("01") Then
            $pos = MouseGetPos()
            For $xcoord = 1 to $linewidth
                For $ycoord = 1 to $linewidth
                    For $t = -10 to 10
                    DllCall("gdi32.dll","long","SetPixel", "long", $hd[0], "long", $xcoord+$pos[0]+$t, "long", $ycoord+$pos[1]+$t, "long", $LineColor)
                    Next
                Next
            Next
        Endif
    WEnd
Else
GUICtrlSetData ($toggle, "Disabled" )
EndIf
EndFunc

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
  • Recently Browsing   0 members

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