Ich suche auch eine Moeglichkeit und habe heute etwas experimentiert.
Hier mein Code. Ich nutze GetWindowRect() und muss aber das MDI Fenster verschieben, um so die relativen Koordinaten herauszubekommen.
Code: Alles auswählen
Procedure.l ChildWindowX(hWndMain.l, hWndChild.l)
ChildX.l
ChildY.l
GetWindowRect_(hWndMain, @Main.RECT) ;Position in Screen-Koordinaten
GetWindowRect_(hWndChild, @Child.RECT) ;Position in Screen-Koordinaten
ChildX = Child\left - Main\left ;linke Kante (relativ)
ChildY = Child\top - Main\top ;obere Kante (relativ)
SetWindowPos_(hWndChild, 0, 0, 0, -1, -1, #SWP_NOSIZE | #SWP_NOZORDER) ;hWndChild auf Koordinaten 0,0 setzen
GetWindowRect_(hWndChild, @Child.RECT) ;Position in Screen-Koordinaten (jetzt bei 0,0)
ChildX = ChildX - (Child\left - Main\left) ;Offset berechnen (wegen Menu, ToolBar...)
ChildY = ChildY - (Child\top - Main\top) ;Offset berechnen (wegen Menu, ToolBar...)
SetWindowPos_(hWndChild, 0, ChildX, ChildY, -1, -1, #SWP_NOSIZE | #SWP_NOZORDER) ;hWndChild wieder auf alte Koordinaten setzen (relativ zu hWndMain)
ProcedureReturn ChildX
EndProcedure
;* * * * * * * * * *
;* * * * * * * * * *
Procedure.l ChildWindowY(hWndMain.l, hWndChild.l)
ChildX.l
ChildY.l
GetWindowRect_(hWndMain, @Main.RECT) ;Position in Screen-Koordinaten
GetWindowRect_(hWndChild, @Child.RECT) ;Position in Screen-Koordinaten
ChildX = Child\left - Main\left ;linke Kante (relativ)
ChildY = Child\top - Main\top ;obere Kante (relativ)
SetWindowPos_(hWndChild, 0, 0, 0, -1, -1, #SWP_NOSIZE | #SWP_NOZORDER) ;hWndChild auf Koordinaten 0,0 setzen
GetWindowRect_(hWndChild, @Child.RECT) ;Position in Screen-Koordinaten (jetzt bei 0,0)
ChildX = ChildX - (Child\left - Main\left) ;Offset berechnen (wegen Menu, ToolBar...)
ChildY = ChildY - (Child\top - Main\top) ;Offset berechnen (wegen Menu, ToolBar...)
SetWindowPos_(hWndChild, 0, ChildX, ChildY, -1, -1, #SWP_NOSIZE | #SWP_NOZORDER) ;hWndChild wieder auf alte Koordinaten setzen (relativ zu hWndMain)
ProcedureReturn ChildY
EndProcedure
;* * * * * * * * * *
;* * * * * * * * * *
;zum Testen
;
If OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget,"MDIGadget")
If CreateGadgetList(WindowID(0)) And CreateMenu(0, WindowID(0))
MenuTitle("Menu index 0")
MenuTitle("MDI windows menu")
MenuItem(0, "self created item")
MenuItem(1, "self created item")
MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
mdiChild1 = AddGadgetItem(0, -1, "child window 1")
mdiChild2 = AddGadgetItem(0, -1, "child window 2")
SetWindowPos_(mdiChild1, 0, 25, 10, -1, -1, #SWP_NOSIZE)
SetWindowPos_(mdiChild2, 0, 50, 10, 100, 100, #SWP_NOZORDER)
Debug ChildWindowX(WindowID(0), mdiChild1)
Debug ChildWindowY(WindowID(0), mdiChild1)
EndIf
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf