Sign in to follow this  
Followers 0
Morthawt

Example random colour GUI based drawer

19 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

You're missing important parameters for GUIRegisterMsg.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
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.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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. :)

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

@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

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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

  • Similar Content

    • DicatoroftheUSA
      By DicatoroftheUSA
      Here are Twotoo stupid scripts, You need the attached wordlist file for it to work. I only tested with autoit3 beta and XP.

      I was just playing around with things that could be done with a wordlist. I might make some games with a wordlist, but this one just has too many words that are uncommon.

      You need this word dictionary
      http://www.filefactory.com/file/1y14t7tazsun/n/Words_sqlite

      I generated the word dictionary from moby word list. The first script is a mad-lib generator, the second is a random sentence generators. It made me giggle like a school girl in heat, so I though I would share.

      The attachment will expire after seven days of inactivity, so let me know if it needs to be re-upped.
      #include <file.au3> #include<array.au3> #include <SQLite.au3> #include <SQLite.dll.au3> $sWordlist="mobypos.txt" #region -word types ;~ Interjection ! ;~ Adjective A ;~ Conjunction C ;~ Definite Article D ;~ Noun Phrase h ;~ Verb (intransitive) i ;~ Indefinite Article I ;~ Noun N ;~ Nominative o ;~ Plural p ;~ Preposition P ;~ Pronoun r ;~ Verb (transitive) t ;~ Verb (usu participle) V ;~ Adverb v #endregion _SQLite_Startup() _SQLite_Open("Words.sqlite") global $gsText="Then God spoke all these words, saying, “I am the LORD your God, who brought you out of the land of Egypt, out of the house of slavery. “You shall have no other gods before Me. “You shall not make for yourself an idol, or any likeness of what is in heaven above or on the earth beneath or in the water under the earth. You shall not worship them or serve them; for I, the LORD your God, am a jealous God, visiting the iniquity of the fathers on the children, on the third and the fourth generations of those who hate Me, but showing lovingkindness to thousands, to those who love Me and keep My commandments. “You shall not take the name of the LORD your God in vain, for the LORD will not leave him unpunished who takes His name in vain. “Remember the sabbath day, to keep it holy. Six days you shall labor and do all your work, but the seventh day is a sabbath of the LORD your God; in it you shall not do any work, you or your son or your daughter, your male or your female servant or your cattle or your sojourner who stays with you. For in six days the LORD made the heavens and the earth, the sea and all that is in them, and rested on the seventh day; therefore the LORD blessed the sabbath day and made it holy. “Honor your father and your mother, that your days may be prolonged in the land which the LORD your God gives you. “You shall not murder. “You shall not commit adultery. “You shall not steal. “You shall not bear false witness against your neighbor. “You shall not covet your neighbor’s house; you shall not covet your neighbor’s wife or his male servant or his female servant or his ox or his donkey or anything that belongs to your neighbor.”" global $gsWord global $giSillinesFactor=30 ;less = more silly _SQLite_Exec(-1,"PRAGMA case_sensitive_like=1") Local $gsFinal $gaText=StringSplit($gsText, " ") for $x=1 to StringLen($gsText)/$giSillinesFactor $y=random(1,$gaText[0],1) _SQLite_Exec(-1, 'select type from tblwords where word= "'&$gaText[$y]&'"',"_cb") $gsOldWord= $gaText[$y] if $gsWord<>"" then _SQLite_Exec(-1, 'select word from tblwords where type like "'&$gsWord&'" ORDER BY RANDOM() LIMIT 1',"_cb") if $gsWord=$gsOldWord then ContinueLoop $gaText[$y]=$gsWord EndIf Next for $x=1 to $gaText[0] $gsFinal&=$gaText[$x]&" " Next MsgBox(0,"",$gsFinal) Func _cb($aRow) For $s In $aRow $gsWord=$s Next EndFunc _SQLite_Close() _SQLite_Shutdown()


      #include <file.au3> #include<array.au3> #include <SQLite.au3> #include <SQLite.dll.au3> ;~ $sWordlist="mobypos.txt" #region -word types ;~ Interjection ! ;~ Adjective A ;~ Conjunction C ;~ Definite Article D ;~ Noun Phrase h ;~ Verb (intransitive) i ;~ Indefinite Article I ;~ Noun N ;~ Nominative o ;~ Plural p ;~ Preposition P ;~ Pronoun r ;~ Verb (transitive) t ;~ Verb (usu participle) V ;~ Adverb v #endregion _SQLite_Startup() _SQLite_Open("Words.sqlite") Global $gsRandomReturn global $gsNounPhase global $gxPluralSwitch=False Global $gsAdjetiveRandomness=.5 global $gsPostNounModifierRandomness=.9 global $gsAdverbRanomness=.9 _SQLite_Exec(-1,"PRAGMA case_sensitive_like=1") _SQLite_Exec(-1, 'select * from tblwords where word like "run" ',"_cb") _CreateSentenceType() func _CreateSentenceType() _createnounphrase() ;~ _createVerbPhrase() EndFunc Func _createnounphrase() _PickNounPhrase() EndFunc Func _PickNounPhrase() _SQLite_Exec(-1, 'select word from tblwords where type like "%D%" ORDER BY RANDOM() LIMIT 1;',"_SetArticlePhrase") while random(0,1)<$gsAdjetiveRandomness _SQLite_Exec(-1, 'select word from tblwords where type like "%A%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") WEnd if $gxPluralSwitch=false then _SQLite_Exec(-1, 'select word from tblwords where type like "%h%" OR type like "%N%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") else _SQLite_Exec(-1, 'select word from tblwords where type like "%p%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") EndIf if random(0,1)<$gsPostNounModifierRandomness then _SQLite_Exec(-1, 'select word from tblwords where type like "%P%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") _SQLite_Exec(-1, 'select word from tblwords where type like "%N%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") EndIf _SQLite_Exec(-1, 'select word from tblwords where type like "%V%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") if random(0,1)<$gsAdverbRanomness then _SQLite_Exec(-1, 'select word from tblwords where type like "%v%" ORDER BY RANDOM() LIMIT 1;',"_SetPhrase") MsgBox(0,"Warning!",$gsNounPhase) EndFunc func _SetArticlePhrase($aRow) For $s In $aRow $gsNounPhase&=$s & " " Switch $s case "One","The","a","an", "that", "each" $gxPluralSwitch=False case "my", "his" , "her", "their", "what" if random(0,1,1)=1 Then $gxPluralSwitch=True Else $gxPluralSwitch=False EndIf case Else $gxPluralSwitch=True EndSwitch Next EndFunc func _SetPhrase($aRow) For $s In $aRow $gsNounPhase&=$s & " " Next EndFunc _SQLite_Close() _SQLite_Shutdown()


      Here is an example from the mad-lib generator

      Here is an example from the random phrase generator.