doestergaard Posted November 8, 2015 Share Posted November 8, 2015 (edited) HiI have created a form (main gui) which reads user inputs. From time to time, the user may need to set additional settings for the program, which is hidden because it doesn't make sense to put that on the main gui. Im therefore trying to create a child gui, which is activated by CTRL+S, but I only want that shortcut to be active, while the main gui is active.The problem is, that the HotKey gets bound so CTRL+S will not work in other applications. Also, the CTRL+S is not disabled when the ShowChildGUI is called.My question is how i can disable the CTRL+S hotkey while the child gui is shown, and reenable it, when the main gui takes back focus. Thanks in advance Here is the example: (note: only for illustration)Opt("GUIOnEventMode", 1) #include <GUIConstants.au3> Global Const $WM_ACTIVEAPP = 0x001C Global $hGUIMain, $hGUIChild GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys") ; Parent GUI $hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1) GUISetState(@SW_SHOW, $hGUIMain) ; Child GUI $hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1) While 1 Sleep(10) WEnd Func ShowChildGUI() GUISetState(@SW_DISABLE, $hGUIMain) GUISetState(@SW_SHOW, $hGUIChild) EndFunc Func HotKeys() If WinActive($hGUIMain) Then HotKeySet("^{s}", "ShowChildGUI") Else HotKeySet("^{s}") EndIf EndFunc Edited November 8, 2015 by doestergaard Link to comment Share on other sites More sharing options...
doestergaard Posted November 8, 2015 Author Share Posted November 8, 2015 Okay, i found out, that in my program, the child GUI is actually getting created in the ShowChildGUI function, so multiple instances of the child gui is created when the hotkey is activated.Can it be, that you have to create the child gui outside ShowChildGUI and just call the SetState() function when the HotKey is activated? Hope it makes sense Link to comment Share on other sites More sharing options...
doestergaard Posted November 8, 2015 Author Share Posted November 8, 2015 (edited) Okay, it seems that the ChildGUI is not active, unless i click on it in the taskbar. I put in a MsgBox to show when the Child GUI was the active Windows, but it isn't unless i click on it in the taskbar.The weird thing is though, if I use ConsoleWrite to output which windows is active, it outputs the Child GUI? :s But the MsgBox doesn't show until i click on the child gui windows in the taskbar:expandcollapse popupOpt("GUIOnEventMode", 1) #include <GUIConstants.au3> Global Const $WM_ACTIVEAPP = 0x001C Global $hGUIMain, $hGUIChild GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys") ; Parent GUI $hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1) GUISetState(@SW_SHOW, $hGUIMain) ; Child GUI $hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1) While 1 Sleep(10) WEnd Func ShowChildGUI() GUISetState(@SW_DISABLE, $hGUIMain) GUISetState(@SW_SHOW, $hGUIChild) $handle = WinGetHandle("[ACTIVE]") ConsoleWrite("Title: " & WinGetTitle($handle) & @CRLF) ; outputs: ChildGUI ConsoleWrite("Process: " & WinGetProcess($handle) & @CRLF) ; outputs: 3568 EndFunc Func HotKeys() If WinActive($hGUIMain) Then HotKeySet("^{s}", "ShowChildGUI") ElseIf WinActive($hGUIChild) Then MsgBox(64, "Message", "Child GUI is the active window", 0) Else HotKeySet("^{s}") EndIf EndFunc Edited November 8, 2015 by doestergaard Link to comment Share on other sites More sharing options...
jguinch Posted November 8, 2015 Share Posted November 8, 2015 Here is another way, using GUISetAccelerators (CTRL+S = show the child window, CTRL+h = hide the child window) :expandcollapse popupOpt("GUIOnEventMode", 1) #include <GUIConstants.au3> Global Const $WM_ACTIVEAPP = 0x001C Global $hGUIMain, $hGUIChild ; GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys") ; Parent GUI $hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1) $idDummyShow = GUICtrlCreateDummy() GUICtrlSetOnEvent($idDummyShow, "ShowChildGUI") GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") Local $aKeysMain = [["^s", $idDummyShow]] GUISetAccelerators($aKeysMain) GUISetState(@SW_SHOW, $hGUIMain) ; Child GUI $hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1) $idDummyHide = GUICtrlCreateDummy() GUICtrlSetOnEvent($idDummyHide, "HideChildGUI") Local $aKeysChild = [["^h", $idDummyHide] ] GUISetAccelerators($aKeysChild) While 1 Sleep(10) WEnd Func ShowChildGUI() ConsoleWrite("show" & @CRLF) GUISetState(@SW_DISABLE, $hGUIMain) GUISetState(@SW_SHOW, $hGUIChild) EndFunc Func HideChildGUI() ConsoleWrite("hide" & @CRLF) GUISetState(@SW_ENABLE, $hGUIMain) GUISetState(@SW_HIDE, $hGUIChild) EndFunc Func _Quit() Exit EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now