Jump to content

GUIRegisterMsg not releasing on mouseup


 Share

Recommended Posts

Since the examples section is not really supposed to be for getting help I will post this modification here. I am trying to get my random colour drawer script to work using GUIRegisterMsg instead of using loops, sleeps and _ispressed all the time.

The issue is even though there are no blocking loops it is not detecting the mouse up's or any other down's and so it just wants to let you draw endlessly without having any way to stop. Can you have a quick look to see what I am doing wrong? Why won't it stop drawing (creating labels or colouring them) when you release the left mouse button?

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
Edited by Morthawt
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

  • Recently Browsing   0 members

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