Sign in to follow this  
Followers 0
AustrianOak

How to tell if my child window is inside its parent?

8 posts in this topic

I created a child window inside a parent window and I sometimes drag the child out. Is there any way I can determine if the child is inside or not?

In need of help. I'm really stumped on this one...

Share this post


Link to post
Share on other sites



I created a child window inside a parent window and I sometimes drag the child out. Is there any way I can determine if the child is inside or not?

In need of help. I'm really stumped on this one...

I imagine you set the parent of the child when you created the child using the last parameter in GuiCreate. You can use WinGetPos to find the positions of the parent and the child and then check if the child is inside the parent. To be sure you might need to guse WinGetClientSize.

If you don't want to be able to drag the child out of the parent then create the child as a normal window and then have

DllCall("user32.dll", "int", "SetParent", "hwnd", $child, "hwnd", $parent)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I created a child window inside a parent window and I sometimes drag the child out. Is there any way I can determine if the child is inside or not?

In need of help. I'm really stumped on this one...

Yep, you can. The point is to set an IF statement if the coords of the top left corner of the parent are both smaller than the coords of the top left corner of the child, AND IF both the coords of the botom right corner of the parent are bigger than the coords of the bottom right coords of the child. I've repeated myself so all would be very clear. I hope you understood. You can eventually set an if statement with 2 conditions OR the other 2, and set the message box to "Partial overlapping". Here it is:

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)


Local $ParentWidth = 250, $ParentHeight = 250
Local $ChildWidth = $ParentWidth - 80, $ChildHeight = $ParentHeight - 80


$ParentWin = GUICreate("Parent GUI", $ParentWidth, $ParentHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "ParentClose")
$ParentWin_Pos = WinGetPos($ParentWin, "")
GUISetState(@SW_SHOW)
$ChildWin = GUICreate("Child GUI", $ChildWidth, $ChildHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
GUISetOnEvent($GUI_EVENT_CLOSE, "ChildClose")

GUISetState(@SW_SHOW)
GUISwitch($ParentWin)


While 1
    $ParentWin_Pos = WinGetPos($ParentWin, "")
    $ChildWin_Pos = WinGetPos($ChildWin, "")
    If $ParentWin_Pos[0] < $ChildWin_Pos[0] And $ParentWin_Pos[1] < $ChildWin_Pos[1] And $ParentWin_Pos[0] + $ParentWidth > $ChildWin_Pos[0] + $ChildWidth And $ParentWin_Pos[1] + $ParentHeight > $ChildWin_Pos[1] + $ChildHeight Then ;Here it's the whole big deal
        MsgBox(262192, "", "Inside!")
    Else
        MsgBox(262192, "", "Outside!")
    EndIf
WEnd

Func ParentClose()
    MsgBox(64, "Test", "Parent GUI will now close.")
    GUISwitch($ParentWin)
    GUIDelete()
    Exit
EndFunc   ;==>ParentClose

Func ChildClose()
    MsgBox(64, "Test", "Child GUI will now close.")
    GUISwitch($ChildWin)
    GUIDelete()
EndFunc   ;==>ChildClose

Tell me if this is what you wanted.

Share this post


Link to post
Share on other sites

I had to modify your code to fit into the way I programmed some things and its giving me an error on the big If line saying "Subscript used with non array variable"

Func Test()
    $ParentWidth = 215
    $ParentHeight = 544
    $ChildWidth = 26
    $ChildHeight = 26
    
    For $i = 0 To ubound($calling)-1
        $ParentWin_Pos = WinGetPos($GUI, "")
        $ChildWin_Pos = WinGetPos($calling[$i], "")
        If $ParentWin_Pos[0] < $ChildWin_Pos[0] And $ParentWin_Pos[1] < $ChildWin_Pos[1] And $ParentWin_Pos[0] + $ParentWidth > $ChildWin_Pos[0] + $ChildWidth And $ParentWin_Pos[1] + $ParentHeight > $ChildWin_Pos[1] + $ChildHeight Then;Here it's the whole big deal
            GUIDelete($calling[$i])
        Else
        EndIf
    Next
EndFunc

Share this post


Link to post
Share on other sites

its giving me an error on the big If line saying "Subscript used with non array variable"

Check if it's an array...

Func Test()
    $ParentWidth = 215
    $ParentHeight = 544
    $ChildWidth = 26
    $ChildHeight = 26
    
    For $i = 0 To ubound($calling)-1
        $ParentWin_Pos = WinGetPos($GUI)
        $ChildWin_Pos = WinGetPos($calling[$i])
        
        If IsArray($ParentWin_Pos) And IsArray($ChildWin_Pos) And $ParentWin_Pos[0] < $ChildWin_Pos[0] And _
            $ParentWin_Pos[1] < $ChildWin_Pos[1] And $ParentWin_Pos[0] + $ParentWidth > $ChildWin_Pos[0] + $ChildWidth And _
            $ParentWin_Pos[1] + $ParentHeight > $ChildWin_Pos[1] + $ChildHeight Then ;Here it's the whole big deal
            
            GUIDelete($calling[$i])
        Else
            
        EndIf
    Next
EndFunc

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

When I put in IsArray it gives me an error saying "Error parsing function call" point to IsArray....

Share this post


Link to post
Share on other sites

When I put in IsArray it gives me an error saying "Error parsing function call" point to IsArray....

What AutoIt version you are using?

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

3.2.11.5

I'm using a different method in my coding so this problem is solved. :)

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