mpower Posted June 23, 2014 Share Posted June 23, 2014 (edited) I'm having trouble detecting a click on a disable GUI, my example below: When you click the options button (wrench icon in top right, near minimise) the child window is active and the main window is disabled and has an overlaying semi-transparent gui for visual effect. I would like to detect a click on the $mainguicover gui whilst the options gui is active, is that possible?? expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #EndRegion ### includes ### Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) $mainguicover = GUICreate('', $iWidth + 1, $iHeight + 1, 0, 0, $WS_POPUP, Default, $maingui) GUISetBkColor(0x000000, $mainguicover) GUISetState(@SW_DISABLE, $mainguicover) WinSetTrans($mainguicover,"",100) GUISetState(@SW_SHOW, $maingui) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) GUISetState(@SW_DISABLE, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### Func ShowOptionsGUI() $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) WinMove($mainguicover, '', $aPos[0], $aPos[1]) GUISetState(@SW_DISABLE, $maingui) GUISetState(@SW_SHOW, $mainguicover) GUISetState(@SW_SHOW, $optionsgui) EndFunc While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX GUIDelete($maingui) Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_ENABLE, $maingui) GUISetState(@SW_HIDE, $mainguicover) GUISetState(@SW_HIDE, $optionsgui) EndSwitch EndSwitch WEnd Edited June 23, 2014 by mpower Link to comment Share on other sites More sharing options...
BrewManNH Posted June 23, 2014 Share Posted June 23, 2014 No, it's not possible because you disabled it. If you want it to be still active, don't disable it. Also, even if it were still active, you've covered it with another window, so anything you're clicking on is actually the top window and not your main GUI. 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 GudeHow 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 More sharing options...
mpower Posted June 23, 2014 Author Share Posted June 23, 2014 (edited) Thanks BrewManNH, I might not have explained this clearly. Essentially what I would like to do is capture a click anywhere on the grey area ($mainguicover) and then be able to act on that click. I don't need to click on $maingui, just the gui that is covering it. At the same time I don't want the $optionsgui to lose focus.. Edited June 23, 2014 by mpower Link to comment Share on other sites More sharing options...
BrewManNH Posted June 23, 2014 Share Posted June 23, 2014 Act on it in what way? What are you trying to acheive by deactivating the window and then covering it? What are you trying to acheive by clicking on the blocking window? 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 GudeHow 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 More sharing options...
mpower Posted June 23, 2014 Author Share Posted June 23, 2014 Act on it in what way? What are you trying to acheive by deactivating the window and then covering it? What are you trying to acheive by clicking on the blocking window? Â Essentially I would like to have the main window "activate" in the taskbar and gain focus. To demonstrate this just run the script and then open another application e.g. Notepad. Whilst Notepad has focus try and click anywhere on the greyed out GUI on the script. It won't bring the GUI forward (as the gui is disabled). I'd like to detect a click on the disabled gui and basically do WinActive() - similar to what would happen here when you Show Child/Lock Parent - if you click on the Child GUI whilst the parent GUI is locked, the script is brought forward (i.e. gains focus) and the child gui flashes, but the parent stays disabled/locked : expandcollapse popup#include <GUIConstants.au3> Global $iWidth = 800, $iHeight = 600, $bWidth = 200, $bHeight = 30, $cWidth = 300, $cHeight = 150, $mainparentGUI, $childGUI, $parentGUI $mainparentGUI = GUICreate('Example Main Parent GUI', $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2) $iButton = GUICtrlCreateButton('Show Child GUI and Lock Parent GUI', $iWidth/2 - $bWidth/2, $iHeight/2 - $bHeight/2, $bWidth, $bHeight) GUISetState() $childGUI = GUICreate('Example Child GUI', $cWidth, $cHeight, -1, -1, -1, $WS_EX_MDICHILD, $mainparentGUI) $cButton = GUICtrlCreateButton('Hide Child GUI and Unlock Parent GUI', $cWidth/2 - $bWidth/2, $cHeight/2 - $bHeight/2, $bWidth, $bHeight) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $mainparentGUI Switch $msg[0] Case $GUI_EVENT_CLOSE GUIDelete($mainparentGUI) Exit Case $iButton GUISetState(@SW_DISABLE, $mainparentGUI) GUISetState(@SW_SHOW, $childGUI) EndSwitch Case $childGUI Switch $msg[0] Case $GUI_EVENT_CLOSE GUIDelete($childGUI) Case $cButton GUISetState(@SW_ENABLE, $mainparentGUI) GUISetState(@SW_HIDE, $childGUI) EndSwitch Case $parentGUI Switch $msg[0] Case $GUI_EVENT_CLOSE GUIDelete($parentGUI) EndSwitch EndSwitch WEnd Link to comment Share on other sites More sharing options...
mpower Posted June 25, 2014 Author Share Posted June 25, 2014 So after much playing around I managed to get the desired effect I want. No flashing yet, but now I can get the script to gain focus even if the gui that's being clicked on is disabled Quite proud of myself, even though I'm sure there may be a cleaner way to do it. expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Misc.au3> #EndRegion ### includes ### Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $focus = 1 #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) GUISetState(@SW_DISABLE, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### GUISetState(@SW_SHOW, $maingui) Func ShowOptionsGUI() $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) WinMove($mainguicover, '', $aPos[0], $aPos[1]) ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui EndFunc Func ShowMainGUICover() $aPos = WinGetPos($maingui) GUISetState(@SW_DISABLE, $maingui) $mainguicover = GUICreate('mainguicover', $iWidth + 1, $iHeight + 1, 0, 0, $WS_POPUP, Default, $maingui) GUISetBkColor(0x000000, $mainguicover) GUISetState(@SW_DISABLE, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) EndFunc While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_ENABLE, $maingui) GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 EndSwitch EndSwitch If WinActive($activechildwindow) = 0 And $mainguicover <> 0 And $focus = 1 Then $focus = 0 ElseIf WinActive($activechildwindow) <> 0 And $focus = 0 Then $focus = 1 EndIf If $mainguicover <> 0 And $focus = 0 Then $mouPos = MouseGetPos() $MainWinPos = WinGetPos($mainguicover) $MainWinX_left = $MainWinPos[0] $MainWinX_right = $MainWinX_left + $MainWinPos[2] $MainWinY_top = $MainWinPos[1] $MainWinY_bot = $MainWinY_top + $MainWinPos[3] If _IsPressed("01") Then If $mouPos[0] >= $MainWinX_left And $mouPos[0] <= $MainWinX_right And $mouPos[1] >= $MainWinY_top And $mouPos[1] <= $MainWinY_bot Then WinActivate($maingui) WinActivate($activechildwindow) $focus = 1 EndIf EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
mpower Posted June 25, 2014 Author Share Posted June 25, 2014 And now I have gone ahead and added the *flashing* child window effect, to draw attention to the active child window. This now pretty much mimics the parent/child relationship when working with non $WS_POPUP guis: Hopefully someone finds this useful expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Misc.au3> #EndRegion ### includes ### Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $activechildwindowcover = 0, $focus = 1 #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) GUISetState(@SW_DISABLE, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### GUISetState(@SW_SHOW, $maingui) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_ENABLE, $maingui) GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 EndSwitch EndSwitch If WinActive($activechildwindow) = 0 And $mainguicover <> 0 And $focus = 1 Then $focus = 0 ElseIf WinActive($activechildwindow) <> 0 And $focus = 0 Then $focus = 1 EndIf If $mainguicover <> 0 And $focus = 0 Then $mouPos = MouseGetPos() $MainWinPos = WinGetPos($mainguicover) $MainWinX_left = $MainWinPos[0] $MainWinX_right = $MainWinX_left + $MainWinPos[2] $MainWinY_top = $MainWinPos[1] $MainWinY_bot = $MainWinY_top + $MainWinPos[3] If _IsPressed("01") Then If $mouPos[0] >= $MainWinX_left And $mouPos[0] <= $MainWinX_right And $mouPos[1] >= $MainWinY_top And $mouPos[1] <= $MainWinY_bot Then $focus = 1 WinActivate($maingui) WinActivate($activechildwindow) If $activechildwindowcover <> 0 Then FlashActiveChildWindow() EndIf EndIf EndIf WEnd Func ShowOptionsGUI() $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) WinMove($mainguicover, '', $aPos[0], $aPos[1]) ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui $activechildwindowcover = $optionsguicover EndFunc Func ShowMainGUICover() $aPos = WinGetPos($maingui) GUISetState(@SW_DISABLE, $maingui) $mainguicover = GUICreate('mainguicover', $iWidth + 1, $iHeight + 1, 0, 0, $WS_POPUP, Default, $maingui) GUISetBkColor(0x000000, $mainguicover) GUISetState(@SW_DISABLE, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) EndFunc Func FlashActiveChildWindow() $ChildWinPos = WinGetPos($activechildwindow) $ChildWin_X = $ChildWinPos[0] $ChildWin_Y = $ChildWinPos[1] GUISetBkColor(0xFFFFFF, $activechildwindowcover) WinSetTrans($activechildwindowcover,"",220) WinMove($activechildwindowcover, '', $ChildWin_X, $ChildWin_Y) GUISetState(@SW_SHOWNOACTIVATE, $activechildwindowcover) Sleep(100) GUISetState(@SW_HIDE, $activechildwindowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $activechildwindowcover) Sleep(100) GUISetState(@SW_HIDE, $activechildwindowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $activechildwindowcover) Sleep(100) GUISetState(@SW_HIDE, $activechildwindowcover) GUISetBkColor(0x000000, $activechildwindowcover) WinSetTrans($activechildwindowcover,"",100) EndFunc Link to comment Share on other sites More sharing options...
mpower Posted June 26, 2014 Author Share Posted June 26, 2014 (edited) so after some testing I realised that it still doesn't do what i want... unfortunately with the way I've coded it at present if you click anywhere in the area of the $maingui even if you click in another window it will bring up my gui. this is not the desired effect. I really want to detect the click on $mainguicover only, it seems odd that I can't capture a click on it because certainly clicking on it makes the current application lose focus, but my gui doesnt gain focus. so there is obviously some event happening that makes other applications lose focus upon a click on $mainguicover. Anyone have any thoughts??? Here is the latest version of my script: expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #EndRegion ### includes ### Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $activechildwindowcover = 0 #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) GUISetState(@SW_DISABLE, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### GUISetState(@SW_SHOW, $maingui) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_ENABLE, $maingui) GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 EndSwitch EndSwitch WEnd Func ShowOptionsGUI() If BitAND(WinGetState($optionsgui) <> 7, WinGetState($activechildwindow) <> 7) Then Local $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) If WinGetState($mainguicover) = 0 Then ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui $activechildwindowcover = $optionsguicover ElseIf WinGetState($activechildwindow) = 7 Then FlashWindow($activechildwindow, $activechildwindowcover) Else FlashWindow($optionsgui, $optionsguicover) EndIf EndFunc ;==>ShowOptionsGUI() Func ShowMainGUICover() $aPos = WinGetPos($maingui) $mainguicover = GUICreate('', $iWidth + 1, $iHeight - 22, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $maingui) GUISetBkColor(0x000000, $mainguicover) GUISetState(@SW_DISABLE, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1] + 22) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) EndFunc ;==>ShowMainGUICover() Func FlashWindow($window, $windowcover) Local $aPos = WinGetPos($window) GUISetBkColor(0xFFFFFF, $windowcover) WinSetTrans($windowcover,"",220) WinMove($windowcover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) WinActivate($window) GUISetBkColor(0x000000, $windowcover) WinSetTrans($windowcover,"",100) EndFunc ;==>FlashWindow() Edited June 26, 2014 by mpower Link to comment Share on other sites More sharing options...
BrewManNH Posted June 26, 2014 Share Posted June 26, 2014 Put a label control on the cover gui and if anyone clicks on the label, you can get that click the same way as any other control. Although, I'm still not 100% clear as to what exactly it is you're trying to do that can probably be done another way without going through all of this gui gymnastics. 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 GudeHow 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 More sharing options...
mpower Posted June 26, 2014 Author Share Posted June 26, 2014 Here we go, this works: expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #EndRegion ### includes ### OnAutoItExitRegister("MemRelease") Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $activechildwindowcover = 0 Global $___hNew_WndProc = DllCallbackRegister("WM_MOUSEACTIVATE", "int", "hwnd;uint;wparam;lparam") Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc) Global $___pOld_WndProc #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), Default, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) GUISetState(@SW_DISABLE, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### GUISetState(@SW_SHOW, $maingui) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_ENABLE, $maingui) GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 EndSwitch EndSwitch WEnd Func WM_MOUSEACTIVATE($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_LBUTTONDOWN FlashWindow($activechildwindow, $activechildwindowcover) Return 3 EndSwitch Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_MOUSEACTIVATE() Func _SubClass($hWnd, $pNew_WindowProc) Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc) If @error Then Return SetError(1, 0, 0) If $iRes = 0 Then Return SetError(1, 0, 0) Return SetError(0, 0, $iRes) EndFunc ;==>_SubClass Func MemRelease() _SubClass(WinGetHandle($mainguicover), $___pOld_WndProc) DllCallbackFree($___hNew_WndProc) EndFunc ;==>MemRelease Func ShowOptionsGUI() If BitAND(WinGetState($optionsgui) <> 7, WinGetState($activechildwindow) <> 7) Then Local $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) If WinGetState($mainguicover) = 0 Then ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui $activechildwindowcover = $optionsguicover ElseIf WinGetState($activechildwindow) = 7 Then FlashWindow($activechildwindow, $activechildwindowcover) Else FlashWindow($optionsgui, $optionsguicover) EndIf EndFunc ;==>ShowOptionsGUI() Func ShowMainGUICover() $aPos = WinGetPos($maingui) $mainguicover = GUICreate('', $iWidth + 1, $iHeight - 22, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $maingui) GUISetBkColor(0x000000, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1] + 22) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) $___pOld_WndProc = _SubClass(WinGetHandle($mainguicover), $___pNew_WndProc) EndFunc ;==>ShowMainGUICover() Func FlashWindow($window, $windowcover) WinActivate($window) Local $aPos = WinGetPos($window) GUISetBkColor(0xFFFFFF, $windowcover) WinSetTrans($windowcover,"",220) WinMove($windowcover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) GUISetBkColor(0x000000, $windowcover) WinSetTrans($windowcover,"",100) EndFunc ;==>FlashWindow() Link to comment Share on other sites More sharing options...
mpower Posted June 26, 2014 Author Share Posted June 26, 2014 (edited) Hmm so whilst this works fine when I only have a single child popup gui on top of my $maingui, it doesn't work quite well when there is a secondary child gui. For example: To demonstrate the problem I have do the following: Run script Click options button (wrech icon) in top right corner of GUI Click anywhere on the 'greyed out' main GUI- you will notice the options GUI *flashes* and becomes Active Similarly if you have another application open and partially on top of my greyed out GUI (e.g. a notepad window) and you click on the greyed out main GUI, it will Activate the current child GUI and *flash* it to draw the user's attention to it However, if you then click the Test button on the Options GUI, creating an App Msg GUI, and click anywhere on top of the now greyed out Options GUI you will notice that the Options GUI cover becomes active and now the App Msg GUI is under the Options GUI cover - preventing any actions. (If you click outside the greyed out Options GUI it works fine, as expected). I would like to trap the mouse click on top of the greyed options gui also, much like already happens when you click the greyed out main GUI so that the focus remains on the App Msg GUI. Essentially it's the Parent/Child window relationship, but since I am using $WS_POPUP the standard relationship doesn't appear to work, so I have to work around it. Because I ported this solution from an existing script I have no idea how to add additional GUIs to the WM_MOUSEACTIVATE hook. Any help would be greatly appreciated! expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #EndRegion ### includes ### OnAutoItExitRegister("MemRelease") Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $activechildwindowcover = 0, $clickcover = 0, _ $appmsggui_hButtonX, $appmsggui_W = 240, $appmsggui_H = 140, $appmsggui, $appmsgparentgui, $appmsgparentguicover Global $hNew_WndProc = DllCallbackRegister("WM_MOUSEACTIVATE", "int", "hwnd;uint;wparam;lparam") Global $pNew_WndProc = DllCallbackGetPtr($hNew_WndProc) Global $pOld_WndProc #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsgui_testbutton = GUICtrlCreateButton('Test button', 10, 60, 100, 57, $SS_CENTER) $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### #Region ### $appmsggui ### $appmsggui = GUICreate('', $appmsggui_W, $appmsggui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $optionsgui) $appmsggui_yes = GUICtrlCreateButton('Yes', 10, 110, 50) $appmsggui_no = GUICtrlCreateButton('No', 10, 110, 50) $appmsggui_cancel = GUICtrlCreateButton('Cancel', 10, 110, 50) $appmsggui_retry = GUICtrlCreateButton('Retry', 10, 110, 50) $appmsggui_okay = GUICtrlCreateButton('Okay', 10, 110, 50) $appmsgparentgui = $optionsgui $appmsgparentguicover = $optionsguicover #EndRegion ### $appmsggui ### GUISetState(@SW_SHOW, $maingui) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 Case $optionsgui_testbutton GenerateAppMsg($optionsgui, $optionsguicover, 'Test message body', 'Test title') EndSwitch Case $appmsggui Switch $msg[0] Case $GUI_EVENT_CLOSE, $appmsggui_hButtonX, $appmsggui_okay GUISetState(@SW_ENABLE, $appmsgparentgui) GUISetState(@SW_HIDE, $appmsgparentguicover) GUISetState(@SW_HIDE, $appmsggui) GUIDelete($appmsggui) $activechildwindow = $appmsgparentgui $activechildwindowcover = $appmsgparentguicover EndSwitch EndSwitch WEnd Func WM_MOUSEACTIVATE($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_MOUSEACTIVATE If $clickcover = 0 Then $clickcover = 1 FlashWindow($activechildwindow, $activechildwindowcover) EndIf Return 3 EndSwitch Return _WinAPI_CallWindowProc($pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_MOUSEACTIVATE() Func _SubClass($hWnd, $pNew_WindowProc) Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc) If @error Then Return SetError(1, 0, 0) If $iRes = 0 Then Return SetError(1, 0, 0) Return SetError(0, 0, $iRes) EndFunc ;==>_SubClass Func MemRelease() _SubClass(WinGetHandle($mainguicover), $pOld_WndProc) DllCallbackFree($hNew_WndProc) EndFunc ;==>MemRelease Func ShowOptionsGUI() If BitAND(WinGetState($optionsgui) <> 7, WinGetState($activechildwindow) <> 7) Then Local $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) If WinGetState($mainguicover) = 0 Then ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui $activechildwindowcover = $optionsguicover ElseIf WinGetState($activechildwindow) = 7 Then FlashWindow($activechildwindow, $activechildwindowcover) Else FlashWindow($optionsgui, $optionsguicover) EndIf EndFunc ;==>ShowOptionsGUI() Func ShowMainGUICover() $aPos = WinGetPos($maingui) $mainguicover = GUICreate('', $iWidth + 1, $iHeight - 22, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $maingui) GUISetBkColor(0x000000, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1] + 22) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) $pOld_WndProc = _SubClass(WinGetHandle($mainguicover), $pNew_WndProc) EndFunc ;==>ShowMainGUICover() Func FlashWindow($window, $windowcover) WinActivate($window) Local $aPos = WinGetPos($window) GUISetBkColor(0xFFFFFF, $windowcover) WinSetTrans($windowcover,"",220) WinMove($windowcover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) GUISetBkColor(0x000000, $windowcover) WinSetTrans($windowcover,"",100) $clickcover = 0 EndFunc ;==>FlashWindow() Func GenerateAppMsg($parentgui, $parentguicover, $windowmsg, $title) GUIDelete($appmsggui) $appmsgparentgui = $parentgui $appmsgparentguicover = $parentguicover $appmsggui = GUICreate('', $appmsggui_W, $appmsggui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $parentgui) GUISetBkColor(0xFFFFFF, $appmsggui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - ' & $title, 0, 0, $appmsggui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $appmsggui_hButtonX = GUICtrlCreateLabel(" X", $appmsggui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") GUICtrlCreateLabel($windowmsg, 10, 45, $appmsggui_W - 20, 63, $SS_CENTER) GUICtrlSetFont(-1, 11, 400, -1) $iSpacing1 = $appmsggui_W/2 $iSpacing2 = $appmsggui_W/3 $iSpacing3 = $appmsggui_W/4 $ibWidth = 50 $appmsggui_retry = GUICtrlCreateButton('Retry', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_yes = GUICtrlCreateButton('Yes', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_no = GUICtrlCreateButton('No', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_cancel = GUICtrlCreateButton('Cancel', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_okay = GUICtrlCreateButton('Okay', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) If $title <> 'Test title' Then GUICtrlSetState($appmsggui_retry, $GUI_SHOW) GUICtrlSetPos($appmsggui_retry, $iSpacing2 - ($ibWidth/2), 105) GUICtrlSetState($appmsggui_cancel, $GUI_SHOW) GUICtrlSetPos($appmsggui_cancel, ($iSpacing2 * 2) - ($ibWidth/2), 105) Else GUICtrlSetState($appmsggui_okay, $GUI_SHOW) GUICtrlSetPos($appmsggui_okay, $iSpacing1 - ($ibWidth/2), 105) EndIf $appmsgguicover = GUICreate('', $appmsggui_W + 1, $appmsggui_H + 1, 0, 0, $WS_POPUP, Default, $appmsggui) GUISetBkColor(0x000000, $appmsgguicover) WinSetTrans($appmsgguicover,"",100) $aPos = WinGetPos($parentgui) WinMove($parentguicover, '', $aPos[0], $aPos[1]) WinMove($appmsggui, '', $aPos[0] + (($aPos[2]/2) - ($appmsggui_W/2)), $aPos[1] + (($aPos[3]/2) - ($appmsggui_H/2))) GUISetState(@SW_SHOWNOACTIVATE, $parentguicover) GUISetState(@SW_SHOW, $appmsggui) $activechildwindow = $appmsggui $activechildwindowcover = $appmsgguicover EndFunc ;==>GenerateAppMsg() Edited June 26, 2014 by mpower Link to comment Share on other sites More sharing options...
Solution mpower Posted June 26, 2014 Author Solution Share Posted June 26, 2014 Yay it seems that this is the final working script!! It does everything I wanted!!! Let's hope I didn't waste my time and that there wasn't an easy fix  : Essentially I've abandoned the idea of having each window have an individual 'grey out' cover popup gui and have gone for a single main GUI cover, utilising _WinAPI_SetWindowPos expandcollapse popup#Region ### includes ### #include-once #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #EndRegion ### includes ### OnAutoItExitRegister("MemRelease") Global $topLabel, $hButtonX, $hMinimize, $maingui, $iHeight, $iWidth, $iHeight = 700, $iWidth = 850, $appver = '1.0', $appname = 'TestApp', $dTitleBarColor = 0xD8DDE8, _ $optionsgui, $optionsgui_W = 450, $optionsgui_H = 185, $hButtonX_optionsgui, $mainguicover = 0, $activechildwindow = 0, $activechildwindowcover = 0, $clickcover = 0, _ $appmsggui_hButtonX, $appmsggui_W = 240, $appmsggui_H = 140, $appmsggui, $appmsgparentgui, $appmsgparentguicover Global $hNew_WndProc = DllCallbackRegister("WM_MOUSEACTIVATE", "int", "hwnd;uint;wparam;lparam") Global $pNew_WndProc = DllCallbackGetPtr($hNew_WndProc) Global $pOld_WndProc #Region ### $maingui ### $maingui = GUICreate($appname & ' ' & $appver, $iWidth, $iHeight, @DesktopWidth/2 - $iWidth/2, @DesktopHeight/2 - $iHeight/2, BitOR($WS_POPUP, $WS_BORDER)) GUISetBkColor(0xFFFFFF, $maingui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver, 0, 0, $iWidth - 69, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX = GUICtrlCreateLabel(" X", $iWidth - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 800, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $hMinimize = GUICtrlCreateLabel("__", $iWidth - 43, 0, 21, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS") GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Minimize") $hConfig = GUICtrlCreateLabel('@', $iWidth - 69, 0, 26, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 400, 0, "Webdings") GUICtrlSetBkColor(-1, $dTitleBarColor) $topLabel = GUICtrlCreateLabel('Welcome to ' & $appname, 10, 45, $iWidth - 350, 21) GUICtrlSetFont(-1, 11, 400, -1) #EndRegion ### $maingui ### #Region ### $optionsgui ### $optionsgui = GUICreate('', $optionsgui_W, $optionsgui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $maingui) GUISetBkColor(0xFFFFFF, $optionsgui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - Options', 0, 0, $optionsgui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $hButtonX_optionsgui = GUICtrlCreateLabel(" X", $optionsgui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") $optionsgui_testbutton = GUICtrlCreateButton('Test button', 10, 60, 100, 57, $SS_CENTER) $optionsguicover = GUICreate('', $optionsgui_W + 1, $optionsgui_H + 1, 0, 0, $WS_POPUP, Default, $optionsgui) GUISetBkColor(0x000000, $optionsguicover) WinSetTrans($optionsguicover,"",100) #EndRegion ### $optionsgui ### #Region ### $appmsggui ### $appmsggui = GUICreate('', $appmsggui_W, $appmsggui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $optionsgui) $appmsggui_yes = GUICtrlCreateButton('Yes', 10, 110, 50) $appmsggui_no = GUICtrlCreateButton('No', 10, 110, 50) $appmsggui_cancel = GUICtrlCreateButton('Cancel', 10, 110, 50) $appmsggui_retry = GUICtrlCreateButton('Retry', 10, 110, 50) $appmsggui_okay = GUICtrlCreateButton('Okay', 10, 110, 50) $appmsgparentgui = $optionsgui $appmsgparentguicover = $optionsguicover #EndRegion ### $appmsggui ### GUISetState(@SW_SHOW, $maingui) While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $maingui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX Exit Case $hMinimize GUISetState(@SW_MINIMIZE, $maingui) Case $hConfig ShowOptionsGUI() EndSwitch Case $optionsgui Switch $msg[0] Case $GUI_EVENT_CLOSE, $hButtonX_optionsgui GUISetState(@SW_HIDE, $optionsgui) GUIDelete($mainguicover) $mainguicover = 0 Case $optionsgui_testbutton GenerateAppMsg($optionsgui, $optionsguicover, 'Test message body', 'Test title') EndSwitch Case $appmsggui Switch $msg[0] Case $GUI_EVENT_CLOSE, $appmsggui_hButtonX, $appmsggui_okay GUISetState(@SW_HIDE, $appmsggui) WinActivate($appmsgparentgui) GUIDelete($appmsggui) $activechildwindow = $appmsgparentgui $activechildwindowcover = $appmsgparentguicover EndSwitch EndSwitch WEnd Func WM_MOUSEACTIVATE($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_MOUSEACTIVATE If $clickcover = 0 Then $clickcover = 1 FlashWindow($activechildwindow, $activechildwindowcover) EndIf Return 3 EndSwitch Return _WinAPI_CallWindowProc($pOld_WndProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_MOUSEACTIVATE() Func _SubClass($hWnd, $pNew_WindowProc) Local $iRes = _WinAPI_SetWindowLong($hWnd, -4, $pNew_WindowProc) If @error Then Return SetError(1, 0, 0) If $iRes = 0 Then Return SetError(1, 0, 0) Return SetError(0, 0, $iRes) EndFunc ;==>_SubClass Func MemRelease() _SubClass(WinGetHandle($mainguicover), $pOld_WndProc) DllCallbackFree($hNew_WndProc) EndFunc ;==>MemRelease Func ShowOptionsGUI() If BitAND(WinGetState($optionsgui) <> 7, WinGetState($activechildwindow) <> 7) Then Local $aPos = WinGetPos($maingui) WinMove($optionsgui, '', $aPos[0] + (($aPos[2]/2) - ($optionsgui_W/2)), $aPos[1] + (($aPos[3]/2) - ($optionsgui_H/2))) If WinGetState($mainguicover) = 0 Then ShowMainGUICover() GUISetState(@SW_SHOW, $optionsgui) $activechildwindow = $optionsgui $activechildwindowcover = $optionsguicover ElseIf WinGetState($activechildwindow) = 7 Then FlashWindow($activechildwindow, $activechildwindowcover) Else FlashWindow($optionsgui, $optionsguicover) EndIf EndFunc ;==>ShowOptionsGUI() Func ShowMainGUICover() $aPos = WinGetPos($maingui) $mainguicover = GUICreate('', $iWidth + 1, $iHeight - 22, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $maingui) GUISetBkColor(0x000000, $mainguicover) WinSetTrans($mainguicover,"",100) WinMove($mainguicover, '', $aPos[0], $aPos[1] + 22) GUISetState(@SW_SHOWNOACTIVATE, $mainguicover) $pOld_WndProc = _SubClass(WinGetHandle($mainguicover), $pNew_WndProc) EndFunc ;==>ShowMainGUICover() Func FlashWindow($window, $windowcover) WinActivate($window) Local $aPos = WinGetPos($window) GUISetBkColor(0xFFFFFF, $windowcover) WinSetTrans($windowcover,"",220) WinMove($windowcover, '', $aPos[0], $aPos[1]) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) Sleep(50) GUISetState(@SW_SHOWNOACTIVATE, $windowcover) Sleep(100) GUISetState(@SW_HIDE, $windowcover) GUISetBkColor(0x000000, $windowcover) WinSetTrans($windowcover,"",100) $clickcover = 0 EndFunc ;==>FlashWindow() Func GenerateAppMsg($parentgui, $parentguicover, $windowmsg, $title) GUIDelete($appmsggui) $appmsgparentgui = $parentgui $appmsgparentguicover = $parentguicover $appmsggui = GUICreate('', $appmsggui_W, $appmsggui_H, 0, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_MDICHILD, $maingui) GUISetBkColor(0xFFFFFF, $appmsggui) GUICtrlCreateLabel(' ' & $appname & ' ' & $appver & ' - ' & $title, 0, 0, $appmsggui_W - 22, 21, $SS_NOTIFY + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 11, 500, Default, "Arial") GUICtrlSetBkColor(-1, $dTitleBarColor) $appmsggui_hButtonX = GUICtrlCreateLabel(" X", $appmsggui_W - 22, 0, 22, 21, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 12, 600, -1) GUICtrlSetBkColor(-1, $dTitleBarColor) GUICtrlSetTip(-1, "Close") GUICtrlCreateLabel($windowmsg, 10, 45, $appmsggui_W - 20, 63, $SS_CENTER) GUICtrlSetFont(-1, 11, 400, -1) $iSpacing1 = $appmsggui_W/2 $iSpacing2 = $appmsggui_W/3 $iSpacing3 = $appmsggui_W/4 $ibWidth = 50 $appmsggui_retry = GUICtrlCreateButton('Retry', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_yes = GUICtrlCreateButton('Yes', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_no = GUICtrlCreateButton('No', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_cancel = GUICtrlCreateButton('Cancel', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) $appmsggui_okay = GUICtrlCreateButton('Okay', 10, 105, $ibWidth) GUICtrlSetState(-1, $GUI_HIDE) If $title <> 'Test title' Then GUICtrlSetState($appmsggui_retry, $GUI_SHOW) GUICtrlSetPos($appmsggui_retry, $iSpacing2 - ($ibWidth/2), 105) GUICtrlSetState($appmsggui_cancel, $GUI_SHOW) GUICtrlSetPos($appmsggui_cancel, ($iSpacing2 * 2) - ($ibWidth/2), 105) Else GUICtrlSetState($appmsggui_okay, $GUI_SHOW) GUICtrlSetPos($appmsggui_okay, $iSpacing1 - ($ibWidth/2), 105) EndIf $appmsgguicover = GUICreate('', $appmsggui_W + 1, $appmsggui_H + 1, 0, 0, $WS_POPUP, Default, $appmsggui) GUISetBkColor(0x000000, $appmsgguicover) WinSetTrans($appmsgguicover,"",100) $aPos = WinGetPos($parentgui) _WinAPI_SetWindowPos(WinGetHandle($mainguicover), WinGetHandle($parentgui), 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE)) WinMove($appmsggui, '', $aPos[0] + (($aPos[2]/2) - ($appmsggui_W/2)), $aPos[1] + (($aPos[3]/2) - ($appmsggui_H/2))) GUISetState(@SW_SHOW, $appmsggui) $activechildwindow = $appmsggui $activechildwindowcover = $appmsgguicover EndFunc ;==>GenerateAppMsg() 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