Sign in to follow this  
Followers 0
boogieoompa

Screen writting program

7 posts in this topic

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

Share this post


Link to post
Share on other sites



lol thats the coolest thing ive ever seen. you should change though that you click draw mose to start drawing and disable to stop. And maybe allow the user to change colors with radio buttons.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

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"

Share this post


Link to post
Share on other sites

I couldn't find a circle, I tried using the brush and pen but it seems like it can only work on a control so there are some issues with it going across windows.

Share this post


Link to post
Share on other sites

Any ideas?

Share this post


Link to post
Share on other sites

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

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  
Followers 0