Sign in to follow this  
Followers 0
InunoTaishou

_WinApi_SetParent and Event Close

2 posts in this topic

#1 ·  Posted (edited)

When creating an mdi child using _WinApi_SetParent the close event for the parent is not run until the child window is closed. Is there any way to close the child windows when the parent's close button is pressed? It seems that when you close from the task bar the parent close function is run first.

#include <WinAPI.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $hParent = GUICreate("Parent", 800, 600)
Global $hChild = GUICreate("Child", 300, 200, 0, 0)

_WinAPI_SetParent($hChild, $hParent)

GUISetState(@SW_SHOW, $hParent)
GUISetState(@SW_SHOW, $hChild)

GUISetOnEvent($GUI_EVENT_CLOSE, CloseWinParent, $hParent)
GUISetOnEvent($GUI_EVENT_CLOSE, CloseWinChild, $hChild)

While (True)
    Sleep(100)
WEnd

Func CloseWinParent()
    ConsoleWrite("CloseWinParent" & @LF)
    GUIDelete($hParent)
    Exit 0
EndFunc

Func CloseWinChild()
    ConsoleWrite("CloseWinChild" & @LF)
    GUIDelete($hChild)
EndFunc

Also, looking at the help file

Quote

An application can use the SetParent function to set the parent window of a pop-up, overlapped, or child
window. The new parent window and the child window must belong to the same application.

This is wrong. I've used _WinApi_SetParent in the past to set autoit created programs to the child of other programs. Perhaps it was like this in the past but Windows 7 and greater different applications can be child and parent.

Edited by InunoTaishou

Share this post


Link to post
Share on other sites



I guess I jumped the gun on posting for help. I noticed that the parent window always looked like it was losing focus when clicking the title and the minimize button. After a quick test it was losing focus so the event was never being sent to the parent. Using the styles BitOR($WS_CAPTION, $WS_CHILD, $WS_SYSMENU, $WS_MINIMIZEBOX) accomplishes the same thing but it greys out the child title bar (I'm guessing because it never actually gains focus).

#include <WinAPI.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $hParent = GUICreate("Parent", 800, 600)
Global $hChild = GUICreate("Child", 300, 200, 0, 0, BitOR($WS_CAPTION, $WS_CHILD, $WS_SYSMENU, $WS_MINIMIZEBOX), -1, $hParent)

GUISetState(@SW_SHOW, $hParent)
GUISetState(@SW_SHOW, $hChild)

GUISetOnEvent($GUI_EVENT_CLOSE, CloseWinParent, $hParent)
GUISetOnEvent($GUI_EVENT_CLOSE, CloseWinChild, $hChild)

While (True)
    Sleep(100)
WEnd

Func CloseWinParent()
    ConsoleWrite("CloseWinParent" & @LF)
    GUIDelete($hParent)
    Exit 0
EndFunc

Func CloseWinChild()
    ConsoleWrite("CloseWinChild" & @LF)
    GUIDelete($hChild)
EndFunc

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to not open another post, writing here my little issue, but seems that no one cares about, and so, I'm opening another post
      What I'm trying to do, is detect the event close sent from the virtual keyboard.
      Why?
      Because, I have an application which, when I set the focus on a textbox, if the virtual keyboard does not exist, then it is created, else, it's not created
      But, everytime I try to close the virtual keyboard, the focus remains on the textbox, and another $EN_FOCUS event it's launched and detected from my WM_COMMAND, and so, the virtual keyboard is opened again. 
      How can I solve this little "issue"? 
      I was trying to detect the event sent from the virtual keyboard, storing the handle of it in a variable, and setting:
      GUISetOnEvent($GUI_EVENT_CLOSE, "CloseVK", $hVirtualKeyboard) without any result.
      Can someone please help me?
      Thanks  
      EDIT:
      Here I'd like to see @Melba23, @water, @Danyfirex...
       
    • salah kai
      By salah kai
      Hey everyone
      i wanna close a process by  path like
      C:\Users\salah\AppData\Local\Temp\a.exe
      processclose(C:\Users\salah\AppData\Local\Temp\a.exe)
      i tried to split the path but i don't know how to know last loop
      and thanks 
       
    • siva1612
      By siva1612
      I would like to create a window like the one shown below. The requirements are as below
      1. The title bar should be opaque.
      2. The parent window/Main screen will be below the side menu/child window
      3. The left side of the side menu window should be opaque.
      4. The right side should be semi-transparent. 

       
      Any idea to help?
    • ur
      By ur
      I have created below code to run the python file.
      #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=icon.ico #AutoIt3Wrapper_Outfile=RunTaskRun.Exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.0 Author: Uday Kiran Reddy(ur) Script Function: To log python data to a file. #ce ---------------------------------------------------------------------------- #include <MsgBoxConstants.au3> #include "C:\Automation\ISMBuild\Library.au3" #include "ProcessEx_AddedNewEntryForLogging.au3" #include "CheckChangeinCommit.au3" If not NoChangesRequired() Then SendMail("Changes are in commit of erwin-main Repo","Will intimate once binaries are copied to Installshield machine") $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "C:\Python27\python.exe C:\BuildServer\AutoBuildServer\TaskRun.py") ; Capture the Process Handle $iPID = @extended ; Note the PID $returncode = _Process_DebugLogRunCommand($hProcessHandle, $iPID) ; Display the results in real-time Logging("Completed with ReturnCode "&$returncode) Else SendMail("No Changes are not there in commit of erwin-main Repo","So no Binaries for today.If it is needed, please remove the text file from location: "& @TempDir&"\git_erwin_commit.txt") EndIf When I kill the autoit execution exe in the middle of execution, it is not terminating the python.exe launched from script.
      Can you suggest how to do this?