penTa Posted November 17, 2009 Share Posted November 17, 2009 Hi all, I'm really sorry if it is already been asked. I want to create a program to monitor if a program is being closed. For example, if a notepad is being closed, I want some popup msgbox to come up. Is it possible? Link to comment Share on other sites More sharing options...
BuckMaster Posted November 17, 2009 Share Posted November 17, 2009 You can either do something like this: Run("Notepad.exe") $Exists = 0 While 1 If WinExists("Untitled -") Then $Exists = 1 Else If $Exists = 1 Then MsgBox( 0,"Closed","Notepad was closed.") $Exists = 0 EndIf EndIf Sleep(100);~ to make the CPU usage less WEnd or you can do something like this: Run("Notepad.exe") Sleep(50) ;~ to make sure that notepad was opened before it checks WinWaitClose("Untitled -") MsgBox( 0,"Closed","Notepad was closed.") Link to comment Share on other sites More sharing options...
omikron48 Posted November 17, 2009 Share Posted November 17, 2009 ProcessExists using WinGetProcess result? Link to comment Share on other sites More sharing options...
bo8ster Posted November 18, 2009 Share Posted November 18, 2009 Hi all,I'm really sorry if it is already been asked.I want to create a program to monitor if a program is being closed. For example, if a notepad is being closed, I want some popup msgbox to come up. Is it possible?The examples given will tell you if the program has been closed. Its a different thing if you want to know if the program is going to be closed. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
penTa Posted November 18, 2009 Author Share Posted November 18, 2009 (edited) Thanks all. OK, I've got a really bad skill of explaining things. The situation is let's say we have a program (I'll call it in this "X") that have no function on "confirm on exit" and a lot of users misclicked into close button a lot. The reason I don't want it to be closed is because it take likes hour to startup. So I need to create a script to monitor if this "X" is going to be closed. If any user misclicked at close button, a confirmed box will appeared if he really wanna close.Sorry for the wrong explaination at first. The examples given will tell you if the program has been closed. Its a different thing if you want to know if the program is going to be closed.You actually read my mind on the later one. Edited November 18, 2009 by penTa Link to comment Share on other sites More sharing options...
penTa Posted November 18, 2009 Author Share Posted November 18, 2009 bump Link to comment Share on other sites More sharing options...
water Posted November 18, 2009 Share Posted November 18, 2009 You can get the information that the close button for application "x" has been pressed in an AutoIt script. But then it's too late. The button has been pressed and application "x" is closing. What I can think of: Write a script that overlays the close button of "x" with its own button (same screen position and always stays in front). When this button is pressed ask the user if he is sure and then trigger the close button of "x". You will have to write some code that checks when the user moves the window of "x" and you have to disable the windows close icon in the upper right corner. I think educating the user might be easier. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2009 Moderators Share Posted November 18, 2009 penTa, Covering the [X] of another app is not that difficult - here is a proof of concept script using Notepad. Try it and see what you think - I have a number of refinements we could put in place if you think this might help. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $iLast_X = 0 $iLast_Y = 0 Run("Notepad.exe") WinWaitActive("Untitled - Notepad") $hNotePad_Handle = WinGetHandle("Untitled - Notepad") $hGUI = GUICreate("My [X]", 30, 15, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $hPic = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp", 0, 0, 30, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hPic MsgBox(0, "Warning", "Someone is trying to exit!") EndSwitch Local $aNotePad_Pos = WinGetPos($hNotePad_Handle) If $aNotePad_Pos[0] <> $iLast_X Or $aNotePad_Pos[1] <> $iLast_Y Then $iLast_X = $aNotePad_Pos[0] $iLast_Y = $aNotePad_Pos[1] WinMove($hGUI, '', $aNotePad_Pos[0] + $aNotePad_Pos[2] - 40, $aNotePad_Pos[1] + 10) EndIf WEnd M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
boogieoompa Posted November 18, 2009 Share Posted November 18, 2009 Another thing to do is use the MouseSetOnEvent_UDF and basically trap all the primary clicks. Everytime a user clicks the mouse you can have it check the position. Here is a skeletal structure but I didnt test it at all and I did not actually put in a y check or any variance (as is you would have a 1 pixel range to intercept). Hopefully you get the idea. #include <MouseSetOnEvent_UDF.au3> #include <GuiConstants.au3> #include <windowsconstants.au3> HotKeySet("^q", "_Quit") $win = "youapptitle" _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "MousePrimaryDown_Event", "", "", 0, -1) While 1 sleep(50) WEnd Func MousePrimaryDown_Event() If WinExists($win) Then $winpos = WinGetPos($win) $mousepos = MouseGetPos() If $mousepos[0] = $winpos[0]+$winpos[3] Then ;trap and do whatever Return 1 Else Return 0 EndIf Else Return 0 Endif EndFunc Func _Quit() Exit EndFuncMouseSetOnEvent_UDF.au3 Link to comment Share on other sites More sharing options...
penTa Posted November 19, 2009 Author Share Posted November 19, 2009 You can get the information that the close button for application "x" has been pressed in an AutoIt script. But then it's too late. The button has been pressed and application "x" is closing. What I can think of: Write a script that overlays the close button of "x" with its own button (same screen position and always stays in front). When this button is pressed ask the user if he is sure and then trigger the close button of "x". You will have to write some code that checks when the user moves the window of "x" and you have to disable the windows close icon in the upper right corner. Yup, that's what try at first. It's like it's too late and then msgbox will just come up lol. I think educating the user might be easier. Well, I've tried that. But everyone can make mistakes (tho I don't want to happen). It's human's nature ... imperfection. penTa, Covering the [X] of another app is not that difficult - here is a proof of concept script using Notepad. Try it and see what you think - I have a number of refinements we could put in place if you think this might help. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $iLast_X = 0 $iLast_Y = 0 Run("Notepad.exe") WinWaitActive("Untitled - Notepad") $hNotePad_Handle = WinGetHandle("Untitled - Notepad") $hGUI = GUICreate("My [X]", 30, 15, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $hPic = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp", 0, 0, 30, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hPic MsgBox(0, "Warning", "Someone is trying to exit!") EndSwitch Local $aNotePad_Pos = WinGetPos($hNotePad_Handle) If $aNotePad_Pos[0] <> $iLast_X Or $aNotePad_Pos[1] <> $iLast_Y Then $iLast_X = $aNotePad_Pos[0] $iLast_Y = $aNotePad_Pos[1] WinMove($hGUI, '', $aNotePad_Pos[0] + $aNotePad_Pos[2] - 40, $aNotePad_Pos[1] + 10) EndIf WEnd M23 Wow, very nice idea I've tried and liked a lot. Works great, too! Thanks a lot, M23. Another thing to do is use the MouseSetOnEvent_UDF and basically trap all the primary clicks. Everytime a user clicks the mouse you can have it check the position. Here is a skeletal structure but I didnt test it at all and I did not actually put in a y check or any variance (as is you would have a 1 pixel range to intercept). Hopefully you get the idea. #include <MouseSetOnEvent_UDF.au3> #include <GuiConstants.au3> #include <windowsconstants.au3> HotKeySet("^q", "_Quit") $win = "youapptitle" _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "MousePrimaryDown_Event", "", "", 0, -1) While 1 sleep(50) WEnd Func MousePrimaryDown_Event() If WinExists($win) Then $winpos = WinGetPos($win) $mousepos = MouseGetPos() If $mousepos[0] = $winpos[0]+$winpos[3] Then ;trap and do whatever Return 1 Else Return 0 EndIf Else Return 0 Endif EndFunc Func _Quit() Exit EndFunc Thanks, boogieoompa. I've tried this but it's like the msgbox comes out but the app still exiting . However, the MouseSetOnEvent is so much interesting. I'll tried to looked into this more. Link to comment Share on other sites More sharing options...
boogieoompa Posted November 19, 2009 Share Posted November 19, 2009 Well my sample code is probably wrong since I typed it directly into the reply field but it should work in theory since you intercept ALL mouse signals. Good luck Link to comment Share on other sites More sharing options...
bo8ster Posted November 19, 2009 Share Posted November 19, 2009 Well, when they make a mistake, get them to make everyone coffee - ppl learn after that. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] 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