Chimp

How allowing the moving of a window only within another window?

14 posts in this topic

#1 ·  Posted (edited)

If I have a Main Windows and 2 child windows, all those 3 windows can be freely moved on the screen.
Is there a way (some Style or ExStyle ?) to limit the moving of the 2 childs only within the boundaries of the client area of the main window??
Thanks for any suggestion

$hGUI = GUICreate('Main GUI', 500, 500,50,50)

$hGUI_Child1 = GUICreate('#1', 150, 100,80,100,-1,-1,$hGUI)
$hGUI_Child2 = GUICreate('#2', 150, 100,280,100,-1,-1,$hGUI)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child1)
GUISetState(@SW_SHOW, $hGUI_Child2)
MsgBox(0,0,"Pause")

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



?

#include <WindowsConstants.au3>
$hGUI = GUICreate('Main GUI', 300, 300, 300)

$hGUI_Child = GUICreate('#2', 150, 100,100,100,BitOr($WS_CHILD,$WS_BORDER),-1,$hGUI)
GUISetBkColor(0xffffff)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

MsgBox(0,0,"Pause")

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $hGUI_Child) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

Chimp,

Perhaps this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $ahChild[1][2] = [[0, False]], $SC_MOVE = 0xF010

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

GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

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

                    $hChild = _CreateMDIChild($hGUI)
            EndSwitch

        Case Else
            $hChild = _CheckMDIChildren($aMsg)
    EndSwitch

WEnd



Func _CreateMDIChild($hParent)
    ; Create child
    Local $hChild = GUICreate("Child " & $ahChild[0][0] + 1, 300, 300, 10, 0, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    ; Set parent
    _WinAPI_SetParent($hChild, $hParent)
    ; Increase counter
    $ahChild[0][0] += 1
    ; Increase array size
    ReDim $ahChild[$ahChild[0][0] + 1][2]
    ; Set values
    $ahChild[$ahChild[0][0]][0] = $hChild

    $ahChild[$ahChild[0][0]][1] = False
    ; Show child
    GUISetState()
    Return $hChild

EndFunc   ;==>CreateChild



Func _CheckMDIChildren($aMsg)

    Local $fRet = False

    For $i = 1 To $ahChild[0][0]
        If $aMsg[1] = $ahChild[$i][0] Then
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($ahChild[$i][0])
                    $ahChild[$i][1] = False
                Case $GUI_EVENT_MAXIMIZE
                    $ahChild[$i][1] = True
                    $ahChild[0][1] = True
                Case $GUI_EVENT_RESTORE
                    $ahChild[$i][1] = False
                    $ahChild[0][1] = False
            EndSwitch

            $fRet = True
        EndIf

    Next
    Return $fRet

EndFunc



Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)

    If $ahChild[0][1] = True Then
        For $i = 1 To $ahChild[0][0]
            If $ahChild[$i][1] Then
                If $hWnd = $ahChild[$i][0] Then
                    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
                    ExitLoop

                EndIf

            EndIf

        Next
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_SYSCOMMAND

The WM_SYSCOMMAND handler just prevents the maximized child being moved.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

many thanks for the excellent examples :)
Now I have good material with which to work.
thanks again to all


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Got it finally  :)

Credits to Lazycat for the idea

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate('Main GUI', 300, 300, 300, 300)
$hGUI_Child = GUICreate('#2', 150, 100,100,100,-1,BitOr($WS_EX_MDICHILD,$WS_EX_TOPMOST),$hGUI)
GUISetBkColor(0xffffff)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
Global $nGap = 10, $size = WinGetClientSize($hGUI)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
   If $hWnd = $hGUI_Child Then
     Local $pos = WinGetPos($hGUI)
     Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
     Local $border = ($pos[2] - $size[1]) ;/ 2
     Local $nLeft   = $pos[0] + $border
     Local $nTop = $pos[1] + $pos[3] - $size[1] - $border
     Local $nRight  = $pos[0] + $pos[2] - $border - DllStructGetData($stWinPos, 5)
     Local $nBottom = $pos[1] + $pos[3] - $border  - DllStructGetData($stWinPos, 6)
     Local $wLeft = DllStructGetData($stWinPos, 3)
     Local $wTop = DllStructGetData($stWinPos, 4)
     If $wLeft < $nLeft Or Abs($nLeft - $wLeft) < $nGap Then DllStructSetData($stWinPos, 3, $nLeft)
     If $wTop < $nTop Or Abs($nTop - $wTop) < $nGap Then DllStructSetData($stWinPos, 4, $nTop)
     If $wLeft > $nRight Or Abs($nRight - $wLeft) < $nGap Then DllStructSetData($stWinPos, 3, $nRight)
     If $wTop > $nBottom Or Abs($nBottom - $wTop) < $nGap Then DllStructSetData($stWinPos, 4, $nBottom)
  EndIf
  Return 'GUI_RUNDEFMSG'
EndFunc

 

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@mikell thanks for this additional effect,
The effect from the nice example of @Melba23 (thanks melba) was exactly what I had in mind, however, even this more restrictive constraint on moving of child windows may come in handy. Thanks :)

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

@mikell, $tagWINDOWPOS is already used in AutoIt and uses named indexes.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,
You're right, the culprit is my laziness which let me use the code from Lazycat (2006 !) as is  :)

Share this post


Link to post
Share on other sites

A lot has changed in 9 years!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

... but sometimes old recipes keep on being efficient  :)

Share this post


Link to post
Share on other sites

I need more convincing I'm afraid. It's only in the last 5 years or so that AutoIt has move towards a proper programming language.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

This old Lazycat's code uses basic includes, litteral struct and DllStruct* funcs which didn't change for ages
These are particular (I agree with that) circumstances where an old script should still work, why shouldn't it not ?

Share this post


Link to post
Share on other sites

Because MSDN docs are constantly changing the structures as their OS' evolve. Lazycat's structure doesn't change with the time, where as the UDF one does. I know which one I would rather put my money with my application working with future versions of Windows.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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