Jump to content

MDI Child Window Position


Recommended Posts

How would I go about keeping a child window in the same position it was closed inside the parent window. 

 

I use WinMove to move it back to the previous location recorded into ini but each time it saves the previous coodinates it multiplys the result and the child window is restored off-screen.

Func _RecordIni($ChildWin)
    If WinExists("UNPRODUCTIVE TECHNICIANS") Then
        Local $TechStatWinPos = WinGetPos(ControlGetHandle($WMTCLiveFeed, "", $ChildWin))
        IniWrite(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSposX", INT($TechStatWinPos[0]))
        IniWrite(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSposY", INT($TechStatWinPos[1]))
        IniWrite(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSsizeW", INT($TechStatWinPos[2]))
        IniWrite(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSsizeH", INT($TechStatWinPos[3]))
    EndIf
EndFunc

#REGION====NEWBORNS=====================================
Func CreateChildTechStats($wintitle)
    Local $Winx = IniRead(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSposX", "DEFAULT VALUE")
    Local $Winy = IniRead(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSposy", "DEFAULT VALUE")
    Local $WinW = IniRead(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSsizeW", "DEFAULT VALUE")
    Local $WinH = IniRead(@ScriptDir & "\LFConfig.ini", "TechStatsWinPos", "TECHSTATSsizeH", "DEFAULT VALUE")

    If Not WinExists($wintitle) Then
        Global $hNew_ChildTech = GUICreate($wintitle, 405, 210, 10, 100, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_TABSTOP))
        Global $TechStatusFeed = GuiCtrlCreateListView("TECH #|STATUS|First Name|Last Name ", 5, 5, 393, 200)
        _GUICtrlListView_SetColumnWidth($TechStatusFeed, 0, 55)
        _GUICtrlListView_SetColumnWidth($TechStatusFeed, 1, 117)
        _GUICtrlListView_SetColumnWidth($TechStatusFeed, 2, 100)
        _GUICtrlListView_SetColumnWidth($TechStatusFeed, 3, 150)
        _WinAPI_SetParent($hNew_ChildTech, $WMTCLiveFeed)
        Add($ahChild, $hNew_ChildTech)
        GUISetOnEvent($GUI_EVENT_CLOSE, "CloseTechStats", $hNew_ChildTech)
        GUISetState()
        Sleep(1000)
        If WinExists($hNew_ChildTech) Then WinMove($hNew_ChildTech, "", $WinX, $WinY, $WinW, $WinH)
    Else
        CloseTechStats()
        _GUICtrlToolbar_CheckButton($Maintoolbar, $e_idTStats, True)
    EndIf
EndFunc   ;==>CreateChild
Func CloseTechStats()
    _RecordIni($hNew_ChildTech)
    GUIDelete($hNew_ChildTech)
    _GUICtrlToolbar_CheckButton($Maintoolbar, $e_idTStats, False)
EndFunc

 

Link to comment
Share on other sites

  • Moderators

CodeTinkerer,

You need to convert the child GUI coordinates from absolute screen values to those inside the parent GUI client area. I massaged another script to show you how you might do it:

#include <GUIConstantsEx.au3>
#include <WinApi.au3>

Local $hChild

Local $iX = 10, $iY = 10 ; Simulate ini

Local $tPoint = DllStructCreate("int X;int Y")

$hGUI = GUICreate("Parent Window", 633, 447, 192, 200)
GUICtrlCreateLabel("", 0, 0, 0, 0)
$mMain = GUICtrlCreateMenu("Child")
$mChild = GUICtrlCreateMenuItem("Create", $mMain)
GUISetState(@SW_SHOW)

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI ; Main GUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $mChild

                    ; Create child - read coords from ini if required
                    Local $hChild = GUICreate("Child", 300, 300, $iX, $iY)
                    ; Set parent
                    _WinAPI_SetParent($hChild, $hGUI)
                    GUISetState()
                    ; Disable menu
                    GUICtrlSetState($mChild, $GUI_DISABLE)
            EndSwitch

        Case Else
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    ; Gte Window position on screen
                    $aPos = WinGetPos($hChild)
                    ; Convert to position inside main GUI client area
                    DllStructSetData($tPoint, "X", $aPos[0])
                    DllStructSetData($tPoint, "Y", $aPos[1])
                    _WinAPI_ScreenToClient($hGUI, $tPoint)
                    $iX = DllStructGetData($tPoint, "X")
                    $iY = DllStructGetData($tPoint, "Y")
                    ; Now save to ini if required.....
                    ; Delete child
                    GUIDelete($hChild)
                    ; Re-enable menu
                    GUICtrlSetState($mChild, $GUI_ENABLE)
            EndSwitch

    EndSwitch

WEnd

You need to store the cords if you want to preserve them once the script has ended - if you are just re-creating the child in the same instance (as in the example), why not just take the easy route and simply hide/show it?

#include <GUIConstantsEx.au3>
#include <WinApi.au3>

Local $hChild



$hGUI = GUICreate("Parent Window", 633, 447, 192, 200)
GUICtrlCreateLabel("", 0, 0, 0, 0)
$mMain = GUICtrlCreateMenu("Child")
$mChild = GUICtrlCreateMenuItem("Create", $mMain)
GUISetState(@SW_SHOW)

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI ; Main GUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $mChild

                    If $hChild Then
                        ; Show hidden child
                        GUISetState(@SW_SHOW, $hChild)
                    Else
                        ; Create child
                        Local $hChild = GUICreate("Child", 300, 300, 10, 10)
                        ; Set parent
                        _WinAPI_SetParent($hChild, $hGUI)
                        GUISetState()
                    EndIf

                    ; Disable menu
                    GUICtrlSetState($mChild, $GUI_DISABLE)
            EndSwitch

        Case Else
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    ; Hide child
                    GUISetState(@SW_HIDE, $hChild)
                    ; Re-enable menu
                    GUICtrlSetState($mChild, $GUI_ENABLE)
            EndSwitch

    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...