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

    • 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?
    • smellyfingers
      By smellyfingers
      Hey, i hope someone can point me in the right direction, i have a page with tables, inside i have TD,TR,INPUT tags, the input tags is buttons and i need to click on one of theese buttons but they have the same value and type so the only way that i am going to know that it's the correct button is to find out the name of the innerhtml of the TD before (the parent node) because the input comes after, like this
      <TABLE> <TR> <TD> Name of the td </TD> <TR> <TD colSpan=3<INPUT> value=my button type=button</INPUT></TD> <TR> <TD> Other name of a td </TD> <TR> <TD colSpan=3<INPUT> value=my button type=button</INPUT></TD> <TR> I know how to find all td's and inputs but not (in a loop) look for the td's and once it has found it click on the corresponding or "closest" input, maybe a nested loop?
      I made a for loop using _IETagnameGetCollection($ie,"TD") and after it found the TD i tried looking for nextSibling but that might be impossible with INPUT perhaps?