Jump to content
Sign in to follow this  

GUIRegisterMsg not releasing on mouseup

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>

While 1
If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit

Func CreateTheGUI()
$hGUI = GUICreate("", 300, 300, -1, -1)
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'

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)
EndFunc ;==>MouseMoveCheck
Edited by Morthawt

Share this post

Link to post
Share on other sites

At first glance, probably because the message is posted to the new window (label) that you create and not the main window.




Share this post

Link to post
Share on other sites


Add $fLeftMouseDown = false at the end of MouseMoveCheck()


Edit: releases the mouse but screws up the drawing

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.