Sorry, I didnt understand what you wanted, here you go.
You can trim it down to size, there's a lot of debug/testing in there. The problem is that you need to remember the old position as you dont know how far to keep it away from the new size of the window.
The +6 is probably due to border size, you can find
Code: Select all
#FenetrePrincipale = 0
#FenetreFille = 1
#MdiGadget = 2
;MACROS from http://forums.purebasic.com/english/viewtopic.php?p=439919&sid=8e97d5aba0e4678f3e64140ee1846d83#p439919
Macro LOWORD(dwValue) : dwValue & $FFFF : EndMacro;
Macro HIWORD(dwValue) : dwValue >> 16 : EndMacro;
Macro MAKELPARAM( loWord, hiWord) : (hiWord << 16 | loWord) : EndMacro;
Macro MAKEWPARAM( loWord, hiWord) : (hiWord << 16 | loWord) : EndMacro;
Global IdChild
Global Old_ParentWindowRect.RECT, Old_ParentClientRect.RECT
Global Old_ChildWindowRect.RECT, Old_ChildClientRect.RECT
Procedure CalcDiff(*new.RECT, *old.RECT, *out.RECT)
*out\left = *new\left - *old\left
*out\right = *new\right - *old\right
*out\top = *new\top - *old\top
*out\bottom = *new\bottom - *old\bottom
EndProcedure
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
If uMsg = #WM_SIZING And hWnd = WindowID(#FenetrePrincipale)
GetWindowRect_(WindowID(#FenetrePrincipale), Old_ParentWindowRect)
GetClientRect_(WindowID(#FenetrePrincipale), Old_ParentClientRect)
;Debug "Old_ParentWindowRect l=" + Old_ParentWindowRect\left + " t=" + Old_ParentWindowRect\top + " r=" + Old_ParentWindowRect\right + " b=" + Old_ParentWindowRect\bottom
;Debug "Old_ParentClientRect l=" + Old_ParentClientRect\left + " t=" + Old_ParentClientRect\top + " h=" + Old_ParentClientRect\right + " h=" + Old_ParentClientRect\bottom
GetWindowRect_(WindowID(IdChild), Old_ChildWindowRect)
GetClientRect_(WindowID(IdChild), Old_ChildClientRect)
;Debug "ChildWindowRect l=" + Old_ChildWindowRect\left + " t=" + Old_ChildWindowRect\top + " r=" + Old_ChildWindowRect\right + " b=" + Old_ChildWindowRect\bottom
;Debug "ChildClientRect l=" + Old_ChildClientRect\left + " t=" + Old_ChildClientRect\top + " w=" + Old_ChildClientRect\right + " h=" + Old_ChildClientRect\bottom
EndIf
If uMsg = #WM_SIZE And hWnd = WindowID(#FenetrePrincipale)
w = LOWORD(lparam)
h = HIWORD(lparam)
WindowRect.RECT
;
; GetWindowRect_(WindowID(IdChild), WindowRect)
; Debug "l=" + WindowRect\left + " t=" + WindowRect\top + " r=" + WindowRect\right + " b=" + WindowRect\bottom
; GetClientRect_(WindowID(IdChild), WindowRect)
; Debug "l=" + WindowRect\left + " t=" + WindowRect\top + " w=" + WindowRect\right + " h=" + WindowRect\bottom
;
ParentWindowRect.RECT
ParentClientRect.RECT
GetWindowRect_(WindowID(#FenetrePrincipale), ParentWindowRect)
GetClientRect_(WindowID(#FenetrePrincipale), ParentClientRect)
Debug "AFTER ParentWindowRect l=" + ParentWindowRect\left + " t=" + ParentWindowRect\top + " r=" + ParentWindowRect\right + " b=" + ParentWindowRect\bottom
Debug "AFTER ParentClientRect l=" + ParentClientRect\left + " t=" + ParentClientRect\top + " h=" + ParentClientRect\right + " h=" + ParentClientRect\bottom
ChildWindowRect.RECT
ChildClientRect.RECT
GetWindowRect_(WindowID(IdChild), ChildWindowRect)
GetClientRect_(WindowID(IdChild), ChildClientRect)
Debug "ChildWindowRect l=" + ChildWindowRect\left + " t=" + ChildWindowRect\top + " r=" + ChildWindowRect\right + " b=" + ChildWindowRect\bottom
Debug "ChildClientRect l=" + ChildClientRect\left + " t=" + ChildClientRect\top + " w=" + ChildClientRect\right + " h=" + ChildClientRect\bottom
ParentWindowMovement.RECT
ParentClientMovement.RECT
CalcDiff(ParentWindowRect, Old_ParentWindowRect, ParentWindowMovement)
CalcDiff(ParentClientRect, Old_ParentClientRect, ParentClientMovement)
Debug "ParentWindowMovement l=" + ParentWindowMovement\left + " t=" + ParentWindowMovement\top + " r=" + ParentWindowMovement\right + " b=" + ParentWindowMovement\bottom
ChildWindowMovement.RECT
ChildClientMovement.RECT
CalcDiff(ChildWindowRect, Old_ChildWindowRect, ChildWindowMovement)
CalcDiff(ChildClientRect, Old_ChildClientRect, ChildClientMovement)
Debug "ChildWindowMovement l=" + ChildWindowMovement\left + " t=" + ChildWindowMovement\top + " r=" + ChildWindowMovement\right + " b=" + ChildWindowMovement\bottom
ResizeGadget(#MdiGadget, 0, 0, WindowWidth(#FenetrePrincipale), WindowHeight(#FenetrePrincipale))
ChildNewTop = ((ChildWindowRect\top - ParentWindowRect\top) + ParentWindowMovement\bottom) - ((ChildWindowRect\bottom - ChildWindowRect\top) - ChildClientRect\bottom) + 6
;FromTop = ChildWindowRect\top - ParentWindowRect\top
Debug "ChildNewTop=" + ChildNewTop
;Debug "FromTop=" + FromTop
;ResizeWindow(IdChild, #PB_Ignore, GadgetHeight(#MdiGadget) - (WindowY(IdChild, #PB_Window_InnerCoordinate) + 19), #PB_Ignore, #PB_Ignore)
;Debug "WindowY(IdChild, #PB_Window_InnerCoordinate)=" + WindowY(IdChild, #PB_Window_InnerCoordinate)
ResizeWindow(IdChild, #PB_Ignore, ChildNewTop, #PB_Ignore, #PB_Ignore)
ProcedureReturn 0
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#FenetrePrincipale, 0, 0, 600, 400, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
MDIGadget(#MdiGadget, 0, 0, 600, 400, 0, 0, #PB_MDI_NoScrollBars)
IdChild = AddGadgetItem(#MdiGadget, #PB_Any, "Fenêtre fille")
ShowWindow_(WindowID(IdChild), #SW_SHOWMINIMIZED)
ResizeWindow(IdChild, 100, 100, #PB_Ignore, #PB_Ignore)
UseGadgetList(WindowID(#FenetrePrincipale))
SetWindowCallback(@WinCallback())
Repeat
Event = WaitWindowEvent()
Until Event=#PB_Event_CloseWindow