Jump to content

GUIGetMsg() question


 Share

Recommended Posts

I need my script to run a check of a registry key every 10th seconds while still being able to look for mesages sent from buttons in the GUI.

I know that Sleep() don't work well in a GUIGetMsg() since it halts the process from getting messages from controlls.

So i came up with a very clumbsy wy of doing this and was wondering if anyone has a better idea of how to do this.

This is what i wanted to do:

GUICreate("My GUI")
$Button = GUICtrlCreateButton ( "Registry value",  10, 30, 100)
GUISetState (@SW_SHOW) 

While 1
    $msg = GUIGetMsg()

    $RegVal = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")

    If $msg = $Button then MsgBox(0, 'The registry value is now:', $RegVal)

    Sleep (10000)

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WendoÝ÷ Ù8^²W¥û§rب)íéh¢®÷¬*,zÜç$x-ëÚç½êò×Ka±ç(Öl¢¥¶Ëa{béh¢(¶­×m­æ¶´ß©¬*-+"³Z¶'bu«­¢+ÙU%
ÉÑ ÅÕ½Ðí5äU$ÅÕ½Ðì¤(ÀÌØí   ÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíI¥ÍÑÉäÙ±ÕÅÕ½Ðì°ÄÀ°ÌÀ°ÄÀÀ¤)U%MÑMÑÑ¡M]}M!=¤()¥´ÀÌØí±äôÀ°ÀÌØíIY°ôII ÅÕ½Ðí!-e}1=
1}5
!%9ÀäÈíM=Q]IÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÅÕ½Ðì°ÅÕ½ÐíAɽɵ¥±Í¥ÈÅÕ½Ðì¤)]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤((ÀÌØí±äôÀÌØí±ä¬Ä(%ÀÌØí±äôÄÀÀÀÑ¡¸(ÀÌØíIY°ôII ÅÕ½Ðí!-e}1=
1}5
!%9ÀäÈíM=Q]IÀäÈí5¥É½Í½ÐÀäÈí]¥¹½ÝÌÀäÈí
ÕÉɹÑYÉÍ¥½¸ÅÕ½Ðì°ÅÕ½ÐíAɽɵ¥±Í¥ÈÅÕ½Ðì¤(ÀÌØí±äôÀ(¹¥((%ÀÌØíµÍôÀÌØí   ÕÑѽ¸Ñ¡¸5Í ½à À°ÌäíQ¡É¥ÍÑÉäٱե̹½ÜèÌäì°ÀÌØíIY°¤((%ÀÌØíµÍôÀÌØíU%}Y9Q}
1=MQ¡¸á¥Ñ1½½À)]¹

Instead of the script actually pausing 10 seconds it adds 1 to a delay variable until it reaches aproximatly 10 seconds (don't need it to be exactly 10 anyways) and then checks the registry and resets the delay varible.

I'm not prowd of this solution and even though i havn't noticed it, this way may defeat the "automatic CPU idle" function of GUIGetMsg()... is there a better way of doing it?

Cheers, Faldo

Link to comment
Share on other sites

I don't know how well this would work, and it's not a whole lot different than your last example, but I just wanted to mention the TimerInit and TimerDiff functions. Where you used a variable that you constantly added 1 to and approximated that each 1 would be a millisecond, the timer functions would give you more correct results.

You would use them as such (to modify your example):

GUICreate("My GUI")
$Button = GUICtrlCreateButton ( "Registry value",  10, 30, 100)
GUISetState (@SW_SHOW) 

Dim $RegVal = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
Dim $Timer = TimerInit()
While 1
    $msg = GUIGetMsg()
    
    If TimerDiff($Timer) > 10000 Then
        $RegVal = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
        $Timer = TimerInit()
    Endif

    If $msg = $Button then MsgBox(0, 'The registry value is now:', $RegVal)

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Like I said, not much different, but a little more exact, and you may find the functions handy for future use. :shocked:

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