Jump to content

Example random colour GUI based drawer


Morthawt
 Share

Recommended Posts

So, I was board :) What have I done? Well using a GUI and label controls I have made a bit of a rubbish time waster drawer script that lets you draw randomly coloured dots inside the black area by using your left mouse button. You can erase with the right mouse button. If you want to completely clear it you can press your middle mouse button (scroller wheel)

Enjoy lol....

AutoItSetOption('MouseCoordMode', 2)
Global $hBox[62][62], $hGUI, $iTest

$iTest = 0 ; Set this to 1 to force random and automatic dot placement.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
$hDll = DllOpen('user32.dll')
CreateTheGUI()

While 1
$x = Floor(MouseGetPos(0) / 5)
$y = Floor(MouseGetPos(1) / 5)
If $iTest = 1 Then
$x = Floor(Random(1, 300, 1) / 5)
$y = Floor(Random(1, 300, 1) / 5)
EndIf

If $x >= 0 And $y >= 0 Then
If $x <= 60 And $y <= 60 Then
If _IsPressed('01', $hDll) Or $iTest = 1 Then
If GUICtrlGetHandle($hBox[$x][$y]) = 0 Then $hBox[$x][$y] = GUICtrlCreateLabel("", $x * 5, $y * 5, 5, 5)
GUICtrlSetBkColor($hBox[$x][$y], '0x' & Random(1, 16581375, 1))
EndIf
If _IsPressed('02', $hDll) Then
If GUICtrlGetHandle($hBox[$x][$y]) Then $hBox[$x][$y] = GUICtrlDelete($hBox[$x][$y])
EndIf
If _IsPressed('04', $hDll) Then
While _IsPressed('04', $hDll)
Sleep(50)
WEnd
GUIDelete($hGUI)
Global $hBox = 0
Sleep(50)
Global $hBox[62][62]
CreateTheGUI()
Sleep(50)
EndIf
EndIf
EndIf
If GUIGetMsg() = $GUI_EVENT_CLOSE Then _Exit()
Sleep(1)
WEnd

Func CreateTheGUI()
$hGUI = GUICreate("", 300, 300, -1, -1)
GUISetBkColor('0x000000')
GUISetState(@SW_SHOW)
EndFunc ;==>CreateTheGUI

Func _Exit()
DllClose($hDll)
Exit
EndFunc ;==>_Exit

post-64654-0-76587300-1354350969_thumb.p

Edited by Morthawt
Link to comment
Share on other sites

Another variation of this (again useless but cool) http://pastebin.com/raw.php?i=BYZh5jMy (non-interactive)

Watch it unfold before your very eyes! All with nothing other than colour values and label controls lol..

Edited by Morthawt
Link to comment
Share on other sites

Morthawt

AutoItSetOption('MouseCoordMode', 2)
Global $hBox[62][62], $hGUI

#include <GUIConstantsEx.au3>
#include <Misc.au3>
$hDll = DllOpen('user32.dll')
CreateTheGUI()

While 1
    $msg = GUIGetMsg()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $GUI_EVENT_PRIMARYDOWN
            While 1
                Sleep(10)
                $aCur_Info = GUIGetCursorInfo($hGUI)
                If Not $aCur_Info[2] Or $aCur_Info[0] < 0 Or $aCur_Info[1] < 0 Or $aCur_Info[0] > 300 Or $aCur_Info[1] > 300 Then ExitLoop
                $x = Int($aCur_Info[0] / 5)
                $y = Int($aCur_Info[1] / 5)
                If GUICtrlGetHandle($hBox[$x][$y]) = 0 Then $hBox[$x][$y] = GUICtrlCreateLabel("", $x * 5, $y * 5, 5, 5)
                GUICtrlSetBkColor($hBox[$x][$y], Random(1, 16581375, 1))
            WEnd
        Case $GUI_EVENT_SECONDARYDOWN
            While 1
                Sleep(10)
                $aCur_Info = GUIGetCursorInfo($hGUI)
                If $aCur_Info[4] Then GUICtrlDelete($aCur_Info[4])
                If Not $aCur_Info[3] Then ExitLoop
            WEnd
    EndSwitch

    If _IsPressed('04', $hDll) Then
        If $x >= 0 And $y >= 0 And $x <= 300 And $y <= 300 Then
            While _IsPressed('04', $hDll)
                Sleep(50)
            WEnd
            GUIDelete($hGUI)
            Dim $hBox[62][62]
            CreateTheGUI()
        EndIf
    EndIf
WEnd

Func CreateTheGUI()
    $hGUI = GUICreate("", 300, 300, -1, -1)
    GUISetBkColor('0x000000')
    GUISetState(@SW_SHOW)
EndFunc   ;==>CreateTheGUI

Func _Exit()
    DllClose($hDll)
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Well I got this but it is not releasing the left click for some reason.

AutoItSetOption('MouseCoordMode', 2)
Global $hBox[62][62], $hGUI, $fLeftMouseDown = False, $fRightMouseDown = False, $x, $y, $fColourRandom = True

$iTest = 0 ; Set this to 1 to force random and automatic dot placement.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
CreateTheGUI()

While 1
If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Func CreateTheGUI()
$hGUI = GUICreate("", 300, 300, -1, -1)
GUISetBkColor('0x000000')
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_MOUSEMOVE, "MouseMoveCheck")
GUIRegisterMsg($WM_LBUTTONDOWN, "LeftMouseDown")
GUIRegisterMsg($WM_LBUTTONUP, "LeftMouseUp")
GUIRegisterMsg($WM_RBUTTONDOWN, "RightMouseDown")
GUIRegisterMsg($WM_RBUTTONUP, "RightMouseUp")
EndFunc ;==>CreateTheGUI


Func LeftMouseDown($finput)
ConsoleWrite('L-Down ' & Random(1, 1000, 1) & @CRLF)
$fLeftMouseDown = True
$fColourRandom = True
EndFunc ;==>LeftMouseDown


Func RightMouseDown($finput)
ConsoleWrite('R-Down ' & Random(1, 1000, 1) & @CRLF)
$fRightMouseDown = True
$fColourRandom = False
EndFunc ;==>RightMouseDown


Func RightMouseUp($finput)
ConsoleWrite('R-Up ' & Random(1, 1000, 1) & @CRLF)
$fRightMouseDown = False
EndFunc ;==>RightMouseUp


Func LeftMouseUp($finput)
ConsoleWrite('L-Up ' & Random(1, 1000, 1) & @CRLF)
$fLeftMouseDown = False
EndFunc ;==>LeftMouseUp


Func MouseMoveCheck()
$x = Floor(MouseGetPos(0) / 5)
$y = Floor(MouseGetPos(1) / 5)

Switch $fColourRandom
Case True
$colour = '0x' & Hex(Random(1, 16581375, 1), 6)
Case False
$colour = '0x000000'
EndSwitch

If $x >= 0 And $y >= 0 And $x <= 60 And $y <= 60 And $fLeftMouseDown = True Then
If GUICtrlGetHandle($hBox[$x][$y]) = 0 Then $hBox[$x][$y] = GUICtrlCreateLabel("", $x * 5, $y * 5, 5, 5)
GUICtrlSetBkColor($hBox[$x][$y], $colour)
EndIf
EndFunc ;==>MouseMoveCheck

Any clue why it is not working correctly?

Edited by Morthawt
Link to comment
Share on other sites

Morthawt

We'll wait for a response from Shaggi

"Label" prevents the creation of a click event

AutoItSetOption('MouseCoordMode', 2)
Global $hBox[62][62], $hGUI, $fLeftMouseDown = False, $fRightMouseDown = False, $x, $y, $fColourRandom = True, $k

$iTest = 0 ; Set this to 1 to force random and automatic dot placement.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
CreateTheGUI()

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Func CreateTheGUI()
    $hGUI = GUICreate("", 300, 300, -1, -1)
    GUISetBkColor(0)
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_MOUSEMOVE, "MouseMoveCheck")
    GUIRegisterMsg($WM_LBUTTONDOWN, "LeftMouseDown")
    GUIRegisterMsg($WM_LBUTTONUP, "LeftMouseUp")
    GUIRegisterMsg($WM_RBUTTONDOWN, "RightMouseDown")
    GUIRegisterMsg($WM_RBUTTONUP, "RightMouseUp")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
EndFunc   ;==>CreateTheGUI

Func LeftMouseDown($finput)
    $k += 1
    WinSetTitle($hGui, '', 'LB DOWN ' & $k)
    $fLeftMouseDown = True
    $fColourRandom = True
EndFunc   ;==>LeftMouseDown

Func RightMouseDown($finput)
    $k += 1
    WinSetTitle($hGui, '', 'RB DOWN ' & $k)
    $fRightMouseDown = True
    $fColourRandom = False
EndFunc   ;==>RightMouseDown

Func RightMouseUp($finput)
    WinSetTitle($hGui, '', 'RB UP ' & $k)
    $fRightMouseDown = False
EndFunc   ;==>RightMouseUp

Func LeftMouseUp($finput)
    WinSetTitle($hGui, '', 'LB UP ' & $k)
    $fLeftMouseDown = False
EndFunc   ;==>LeftMouseUp

Func MouseMoveCheck($hWnd, $iMsg, $wParam, $lParam)
    Local $key, $X, $Y
    $x = Floor(BitAND($lParam, 0xFFFF) / 5)
    $y = Floor(BitShift($lParam, 16) / 5)
    
    If $fColourRandom Then
        $colour = Random(0x1, 0xFFFFFF, 1)
    Else
        $colour = 0
    EndIf

    If $fLeftMouseDown And $x >= 0 And $y >= 0 And $x <= 60 And $y <= 60 Then
        If GUICtrlGetHandle($hBox[$x][$y]) = 0 Then $hBox[$x][$y] = GUICtrlCreateLabel("", $x * 5, $y * 5, 5, 5)
        GUICtrlSetBkColor($hBox[$x][$y], $colour)
    EndIf
EndFunc   ;==>MouseMoveCheck

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    If $nID Then
    $fRightMouseDown = False
    $fLeftMouseDown = False
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

You're missing important parameters for GUIRegisterMsg.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

^What?

Here's an event handler that combines all the functions into one. See if it works

Func CreateTheGUI()
$hGUI = GUICreate("", 300, 300, -1, -1)
GUISetBkColor('0x000000')
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_MOUSEMOVE, "EventHandler")
GUIRegisterMsg($WM_LBUTTONDOWN, "EventHandler")
GUIRegisterMsg($WM_LBUTTONUP, "EventHandler")
GUIRegisterMsg($WM_RBUTTONDOWN, "EventHandler")
GUIRegisterMsg($WM_RBUTTONUP, "EventHandler")
EndFunc ;==>CreateTheGUI

Func EventHandler($hWnd, $Msg, $WParam, $LParam)
    If $hWnd <> $hGui Then Return $GUI_RUNDEFMSG

    Local $szMsg = ""

    Local $Coords[2] = [_WinAPI_LoWord ($lParam), _WinApi_HiWord($lParam)]

    Static $MK_LBUTTON = 0x1
    Static $MK_RBUTTON = 0x2
    Static $MK_MBUTTON = 0x10


    Switch $Msg
        Case $WM_MOUSEMOVE

            ;In case of mouse being dragged, $wparam contains one of these values.
            ;It doesn't support multiple values at one time, you need to BitOr $wparam with the value you want to check.
            Switch $WParam
                Case $MK_LBUTTON
                    $szMsg &= "Mouse was l-dragged to "
                Case $MK_RBUTTON
                    $szMsg &= "Mouse was r-dragged to "
                Case $MK_MBUTTON
                    $szMsg &= "Mouse was m-dragged to "
                Case 0
                    $szMsg &= "Mouse was moved to "
            EndSwitch

            ConsoleWrite($szMsg & $Coords[0] & ", " & $Coords[1] & @LF)
        Case $WM_LBUTTONDOWN
            $szMsg &= "Left button clicked at "
            ConsoleWrite($szMsg & $Coords[0] & ", " & $Coords[1] & @LF)
        Case $WM_LBUTTONUP
            $szMsg &= "Left button released at "
            ConsoleWrite($szMsg & $Coords[0] & ", " & $Coords[1] & @LF)
        Case $WM_RBUTTONDOWN
            $szMsg &= "Right button clicked at "
            ConsoleWrite($szMsg & $Coords[0] & ", " & $Coords[1] & @LF)
        Case $WM_RBUTTONUP
            $szMsg &= "Right button released at "
            ConsoleWrite($szMsg & $Coords[0] & ", " & $Coords[1] & @LF)
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Needs to #include <Winapi.au3>

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

I tried that source and even with tweaking I still could not get it to work. Either way using that kind of method is beyond me. Just confuses me with windows things that I know nothing about. I like using things that the help is almost all the help you need. I absolutely hate things that make you try and go through Microsoft's technical data every time you want to do something.

I figured I would try the GUIRegisterMsg method out because it looked simple: register this message and do this function boom... done. Well its a way deeper function than I like to get into. The only reason I gave some WMI a go was because scriptomatic made things known to me so that I could make use of it in a logical manner without having to trawl through Microsoft's technical data pages.

My memorization/learning and patience are limited to the things that I can clearly make use of without constantly referencing third party sites information :|. It is nice however, to see different methods.

Edited by Morthawt
Link to comment
Share on other sites

Shaggi,

My comment was aimed at the mandatory $hWnd, $iMsg, $wParam & $lParam parameters, not GUIRegister itself. Bad wording on my part. Sorry.

My memorization/learning and patience are limited to the things that I can clearly make use of without constantly referencing third party sites information :|. It is nice however, to see different methods.

Shame really, because you're only limiting yourself as a developer. How can one improve if they're not willing to go out of their comfort zone? Just so you know the only language I know is AutoIt (& VBScript due to similar syntax) and I can understand MSDN after a year of painstakingly breaking down WinAPIEx & WinAPI.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Yeah that's the thing with me, I only even got into Autoit because of the level of coding ease coupled with sufficient abilities. I like to be able to just do things and not take a year to learn infinitely more complex things. That's why I would never get into a full on programming language like C++ or anything because I just don't have the patience to learn something that complicated and convoluted. Autoit is perfect for me. I do learn more over time but it is gradual. There are some things however that I just can't get into especially when it comes to having to learn a lot of Microsoft specifics and codes for things etc.

I just like reading something in the help file and being able to just use it straight away. I love that about Autoit. 90% of everything in it is all in the helpfile and easy to use. About all I have seen I don't want to get into (so far) are dealing with DLL's, that GUI register I tried, Windows API and the GDI or what ever it is for graphics.

I am sure there are other things I would have an allergic reaction to if I see them but really I don't feel limited because I come from making batch files and so this feels like the galaxy has opened up to me, in comparison lol.. I just can't travel to other galaxies. That does not prevent me from learning about new solar systems now and then. :)

Link to comment
Share on other sites

@Morthawt

Weird, it works just fine here? Ofcourse it wouldn't work without the original script, if that's what you are trying .. ?

Try this one out.

#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

Global $hGUI, $hGraphic, $hBrush
CreateTheGUI()

;Launch GDI & globals
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBrush = _GDIPlus_BrushCreateSolid()


While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

;Clean up
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_Shutdown()

Func CreateTheGUI()
    $hGUI = GUICreate("", 300, 300, -1, -1)
    GUISetBkColor('0x000000')
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_MOUSEMOVE, "EventHandler")
    GUIRegisterMsg($WM_LBUTTONDOWN, "EventHandler")
    GUIRegisterMsg($WM_LBUTTONUP, "EventHandler")
    GUIRegisterMsg($WM_RBUTTONDOWN, "EventHandler")
    GUIRegisterMsg($WM_RBUTTONUP, "EventHandler")
EndFunc ;==>CreateTheGUI

Func EventHandler($hWnd, $Msg, $WParam, $LParam)
    If $hWnd <> $hGui Then Return $GUI_RUNDEFMSG

    Local $szMsg = ""

    Local $Coords[2] = [_WinAPI_LoWord ($lParam), _WinApi_HiWord($lParam)]

    Static $MK_LBUTTON = 0x1
    Static $MK_RBUTTON = 0x2
    Static $MK_MBUTTON = 0x10


    Switch $Msg
        Case $WM_MOUSEMOVE
            Switch $WParam
                Case $MK_LBUTTON ;Paint while dragging
                    Paint($Coords[0],$Coords[1])
                Case $MK_RBUTTON ;Erase while dragging
                    Erase($Coords[0], $Coords[1])
                Case $MK_MBUTTON
                Case 0
            EndSwitch
        Case $WM_LBUTTONDOWN ;Paint on click
            Paint($Coords[0],$Coords[1])
        Case $WM_LBUTTONUP
        Case $WM_RBUTTONDOWN ;Erase on click
            Erase($Coords[0], $Coords[1])
        Case $WM_RBUTTONUP
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func Paint($x, $y)
    _GDIPlus_BrushSetSolidColor($hBrush, 0xFF & Random(1, 16777215, 1))
    _GDIPlus_GraphicsFillRect($hGraphic, Int($x/5) * 5, Int($y/5) * 5, 5, 5, $hBrush)
EndFunc

Func Erase($x, $y)
    _GDIPlus_GraphicsFillRect($hGraphic, Int($x/5) * 5, Int($y/5) * 5, 5, 5) ;Omitting $hBrush defaults to painting a black rectangle (erasing)
EndFUnc

Edited by Shaggi

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Link to comment
Share on other sites

Shaggi,

You can be safe in the knowledge it works for me and that at most it uses 2.4% of CPU when moving the mouse vigorously around the GUI.

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

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

×
×
  • Create New...