Patrick,
It may be interesting to test it the other way round:
Create a MDICHILD window, change its parent to the desktop, set it a menu, and change back its parent. I am curious to know how Windows will behave
To avoid flickering, the window could be hiden and shown later on
How to set a MENU in MDI Child window?
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Because the position (together with Height and Width) are saved on closing, so when the MDICHILD opens again, it's openend on the same position on the screen as where it was last closed. Same goes for height and width.Antonio Linares wrote:Your solution looks fine. Why do you care about the coordinates ?
But than the user still can move the window out of the MDI Parent window. But this is not the problemAntonio Linares wrote:I would suggest to change the "virtual" MDICHILD position when its maximized, but besides that, it seems ok
These are the 3 things I would like the "virtual" MDICHILD to do, just like the "real MDICHILD" :
1. User can not move MDICHILD outside of the MDIParent (It's 'captured' in the MDIParent window)
(That's OK with 'SetParent()')
2. Save MDICHILD's position together with its Height and Width
(This is what does not work)
3. Count with oWndParent:aWnd if there are MDICHILD's open
(Can we add the window manually to oWndParent:oWndClient:aWnd?)
Patrick
PS. I'm thinking.. Would it not be more simple to change MDI- and/or Window class so a real MDICHILD accepts its own menu?
PS2. This code shows the Cordination problems even more clear. The Top, Left, Width and Height vallues are shown in the Windows title bar:
Code: Select all
#include "fivewin.ch"
STATIC oWndParent
PROCEDURE Main
LOCAL oMenu
MENU oMenu
MENUITEM "Menu"
MENU
MENUITEM "New Regular window" ;
ACTION NewWindow2(.F.,"Regular window")
MENUITEM "New regular MDI Child window" ;
ACTION NewWindow1("Regular MDI Child window")
MENUITEM "New MDI Child window via Setparent()" ;
ACTION NewWindow2(.T.,"MDI Child window via Setparent()")
SEPARATOR
MENUITEM "Show Len(oWndParent:oWndClient:aWnd)" ;
ACTION MsgInfo( Len(oWndParent:oWndClient:aWnd) )
ENDMENU
ENDMENU
DEFINE WINDOW oWndParent ;
MENU oMenu ;
FROM 10,10 TO 50,99 ;
TITLE "Test MDI Child with Setparent()" ;
MDI
ACTIVATE WINDOW oWndParent
RETURN
//-------------------------------------------------------------//
PROCEDURE NewWindow1(cTitle)
LOCAL oWndChild
DEFINE WINDOW oWndChild;
MDICHILD;
OF oWndParent
ACTIVATE WINDOW oWndChild;
ON MOVE ShowCoordinates(oWndChild,cTitle) ;
ON RESIZE ShowCoordinates(oWndChild, cTitle) ;
ON PAINT ShowCoordinates(oWndChild, cTitle)
RETURN NIL
//-------------------------------------------------------------//
PROCEDURE NewWindow2(lMDIChild,cTitle)
LOCAL oWndChild,oMenu
MENU oMenu
MENUITEM "File"
MENU
MENUITEM "Show coordinates";
ACTION MsgInfo( ShowCoordinates(oWndChild, cTitle) )
ENDMENU
ENDMENU
DEFINE WINDOW oWndChild;
MENU oMenu
ACTIVATE WINDOW oWndChild;
ON MOVE ShowCoordinates(oWndChild, cTitle) ;
ON RESIZE ShowCoordinates(oWndChild, cTitle) ;
ON PAINT ShowCoordinates(oWndChild, cTitle)
IF lMDIChild
SetParent( oWndChild:hWnd, oWndParent:oWndClient:hWnd )
//Aadd( oWndParent:oWndClient:aWnd, oWndChild )
ENDIF
RETURN NIL
//-------------------------------------------------------------//
FUNCTION ShowCoordinates(oWndChild,cTitle)
LOCAL aStart, cPos, aClntArea
aClntArea:=GetClientRect(oWndParent:hWnd)
oWndChild:Normal()
aStart:={aClntArea[ 1],aClntArea[ 2]}
ClientToScreen(oWndParent:hWnd,aStart)
oWndChild:CoorsUpdate()
cPos:=LTrim(Str(oWndChild:nTop ,4,0))+","+;
LTrim(Str(oWndChild:nLeft ,4,0))+","+;
LTrim(Str(oWndChild:nBottom ,4,0))+","+;
LTrim(Str(oWndChild:nRight ,4,0))
oWndChild:SetText( cTitle + " [ " + cPos + " ]" )
RETURN cTitle + " [ " + cPos + " ]"
//-------------------------------------------------------------//
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Hmm, interesting ideaAntonio Linares wrote:Patrick,
It may be interesting to test it the other way round:
Create a MDICHILD window, change its parent to the desktop, set it a menu, and change back its parent. I am curious to know how Windows will behave
To avoid flickering, the window could be hiden and shown later on
But it did not work.
This is what I tried:
Code: Select all
PROCEDURE NewWindow1(cTitle)
LOCAL oWndChild,oMenu
MENU oMenu
MENUITEM "File"
MENU
MENUITEM "Show coordinates";
ACTION MsgInfo( ShowCoordinates(oWndChild, cTitle) )
ENDMENU
ENDMENU
DEFINE WINDOW oWndChild;
MDICHILD;
OF oWndParent
ACTIVATE WINDOW oWndChild;
ON MOVE ShowCoordinates(oWndChild,cTitle) ;
ON RESIZE ShowCoordinates(oWndChild, cTitle) ;
ON PAINT ShowCoordinates(oWndChild, cTitle)
SetParent( oWndChild:hWnd )
oWndChild:SetMenu( oMenu )
SetParent( oWndChild:hWnd, oWndParent:oWndClient:hWnd )
RETURN NIL
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Patrick,
>
2. Save MDICHILD's position together with its Height and Width
(This is what does not work)
>
Have you tried to combine ScreenToClient() and ClientToScreen() ? Based on the (right) used hWnd, you may get the correct coordinates.
>
3. Count with oWndParent:aWnd if there are MDICHILD's open
(Can we add the window manually to oWndParent:oWndClient:aWnd?)
>
Yes, you can manually add to :aWnd
>
PS. I'm thinking.. Would it not be more simple to change MDI- and/or Window class so a real MDICHILD accepts its own menu?
>
We can't because the MDI global behavior is built-in in Windows. It has certain limitations (same as it provides some extra functionalities) and one of them is that a MDICHILD can't have its own pulldown menu (well, it can, but its shown on the main MDIFRAME window).
But your solution is fine
>
2. Save MDICHILD's position together with its Height and Width
(This is what does not work)
>
Have you tried to combine ScreenToClient() and ClientToScreen() ? Based on the (right) used hWnd, you may get the correct coordinates.
>
3. Count with oWndParent:aWnd if there are MDICHILD's open
(Can we add the window manually to oWndParent:oWndClient:aWnd?)
>
Yes, you can manually add to :aWnd
>
PS. I'm thinking.. Would it not be more simple to change MDI- and/or Window class so a real MDICHILD accepts its own menu?
>
We can't because the MDI global behavior is built-in in Windows. It has certain limitations (same as it provides some extra functionalities) and one of them is that a MDICHILD can't have its own pulldown menu (well, it can, but its shown on the main MDIFRAME window).
But your solution is fine
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Sorry I don't understand, can you give me a sample?Antonio Linares wrote:>
2. Save MDICHILD's position together with its Height and Width
(This is what does not work)
>
Have you tried to combine ScreenToClient() and ClientToScreen() ? Based on the (right) used hWnd, you may get the correct coordinates.
Or better, can you try in my sample?
Thanks!
Patrick
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Patrick,
This way you get the right coordinates for the "virtual" MDICHILD window:
This way you get the right coordinates for the "virtual" MDICHILD window:
Code: Select all
local aPos := { oWndChild:nTop, oWndChild:nLeft }
ScreenToClient( oWndParent:oWndClient:hWnd, aPos )
oWndChild:SetText( cTitle + " [ " + Str( aPos[ 1 ] ) + ", " + ;
Str( aPos[ 2 ] ) + ", " + Str( aPos[ 1 ] + oWndChild:nHeight ) + ;
", " + Str( aPos[ 2 ] + oWndChild:nWidth ) + " ]" )
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Wow, works perfect!!Antonio Linares wrote:Patrick,
This way you get the right coordinates for the "virtual" MDICHILD window:Code: Select all
local aPos := { oWndChild:nTop, oWndChild:nLeft } ScreenToClient( oWndParent:oWndClient:hWnd, aPos ) oWndChild:SetText( cTitle + " [ " + Str( aPos[ 1 ] ) + ", " + ; Str( aPos[ 2 ] ) + ", " + Str( aPos[ 1 ] + oWndChild:nHeight ) + ; ", " + Str( aPos[ 2 ] + oWndChild:nWidth ) + " ]" )
Thanks!!!
Patrick