Jump to content

Multiple windows loops handler


NikonD800E
 Share

Recommended Posts

I made one main window and make one button to launch a new window.
At last I found there is another one loop in the sub function.

It causes the secondary window cannot be close (neither the main window).

Is there any solution to make the secondary window works normally?

Help me plz~~~

Thank you very much!

HotKeySet( "{PGUP}", "_Capture" )
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Test Utility Manager", 500, 400, -1, -1)

$Button1 = GUICtrlCreateButton("Function1", 0, 0, 75, 25)

GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GuiEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "_GuiEvents")

GUICtrlSetOnEvent($Button1, "_Button1_OnEvent")


GUISetState(@SW_SHOW)

While 1
    Sleep(500)
WEnd

Func _GuiEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE)
        Case $GUI_EVENT_RESTORE

    EndSwitch
EndFunc   ;==>_GuiEvents

Func _Button1_OnEvent()
    GUISetState(@SW_MINIMIZE)
    If FileExists("C:\GetMousePos.txt") Then
    FileWrite("C:\GetMousePos.txt", $date & @CRLF)
        Else
            FileOpen("C:\GetMousePos.txt", 1)
            FileWrite("C:\GetMousePos.txt", $date & @CRLF)
        EndIf

    Global $GUI = GUICreate("GetMousePos v1.1", "150", "40", "-1", "-1", "-1", "128")
    GUISetOnEvent(-3, "_ExitCapture")
    GUISetFont ("9", "600", "", "Arial")
    $Input = GUICtrlCreateInput("", "0", "0", "150", "20", "1")
    $Input2 = GUICtrlCreateInput("", "0", "20", "150", "20", "1")
    GUICtrlSetState($Input, 128)
    GUICtrlSetState($Input2, 128)
    GUISetState(@SW_SHOW, $GUI)
    WinSetOnTop($GUI, "", "1")  ;always on top

    While 1
    Sleep(15)
    WEnd

EndFunc

Func _Capture()
   $pos = MouseGetPos()
   MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1])
   $var = PixelGetColor( $pos[0] , $pos[1])
   MsgBox(0,"The decimal color is", Hex($var, 6))
   FileWrite("C:\GetMousePos.txt", $pos[0] & "," & $pos[1] & "; " & Hex($var, 6) & @CRLF)
EndFunc 

 
 

Link to comment
Share on other sites

Maybe this is more what you're looking to do?

#include <GUIConstantsEx.au3>
Global $GUI
HotKeySet("{PGUP}", "_Capture")
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Test Utility Manager", 500, 400, -1, -1)
$Button1 = GUICtrlCreateButton("Function1", 0, 0, 75, 25)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiEvents")
GUICtrlSetOnEvent($Button1, "_Button1_OnEvent")
GUISetState(@SW_SHOW)
While 1
    Sleep(50)
WEnd
Func _Button1_OnEvent()
    GUISetState(@SW_MINIMIZE)
    If FileExists("C:\GetMousePos.txt") Then
;~      FileWrite("C:\GetMousePos.txt", $date & @CRLF)
    Else
;~      FileOpen("C:\GetMousePos.txt", 1)
;~      FileWrite("C:\GetMousePos.txt", $date & @CRLF)
    EndIf
    $GUI = GUICreate("GetMousePos v1.1", "150", "40", "-1", "-1", "-1", "128")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitCapture")
    GUISetFont("9", "600", "", "Arial")
    $Input = GUICtrlCreateInput("", "0", "0", "150", "20", "1")
    $Input2 = GUICtrlCreateInput("", "0", "20", "150", "20", "1")
    GUICtrlSetState($Input, 128)
    GUICtrlSetState($Input2, 128)
    GUISetState(@SW_SHOW, $GUI)
    WinSetOnTop($GUI, "", "1") ;always on top
EndFunc   ;==>_Button1_OnEvent
Func _Capture()
    $pos = MouseGetPos()
    MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1])
    $var = PixelGetColor($pos[0], $pos[1])
    MsgBox(0, "The decimal color is", Hex($var, 6))
    FileWrite("C:\GetMousePos.txt", $pos[0] & "," & $pos[1] & "; " & Hex($var, 6) & @CRLF)
EndFunc   ;==>_Capture
Func _GuiEvents()
    Exit
EndFunc   ;==>_GuiEvents
Func _ExitCapture()
    GUIDelete($GUI)
EndFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

No

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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