How to set a MENU in MDI Child window?
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
How to set a MENU in MDI Child window?
Hello,
I have a MDI parent window with a menu. How can I have a different menu IN the MDI child window?
If I set a MENU to a MDI Child, the menu shows up in the MDI Parent window, and no menu is visible in the MDI child window.
Thank you.
Patrick
I have a MDI parent window with a menu. How can I have a different menu IN the MDI child window?
If I set a MENU to a MDI Child, the menu shows up in the MDI Parent window, and no menu is visible in the MDI child window.
Thank you.
Patrick
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Re: How to set a MENU in MDI Child window?
What I have so far is:EnricoMaria wrote:You can't, as far as I know.
EMG
1. Create MDI Parent with menu
2. Create window with menu
3. Use SetParent() to transform the regular window to a MDI child
This works as far as the menu. But, if I try to retrieve the coordinates of the newly MDI child window, they are not correct. It seems that the coordinates from the MDI child is calculated from left, top from SCREEN instead of left, top from the MDI parent. I'm not sure yet, but it seems like that.
"Normal" MDI child window coordinates are form left, top from MDI Parent.
Patrick
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Patrick,
> 3. Use SetParent() to transform the regular window to a MDI child
Good idea
But, what window are you using as the parent ? Keep in mind that a MDI window contains a "ghost" window at DATA oWndClient, so SetParent() should be used this way:
SetParent( oWndChild:hWnd, oWnd:oWndClient:hWnd )
Please let us know the results, thanks
> 3. Use SetParent() to transform the regular window to a MDI child
Good idea
But, what window are you using as the parent ? Keep in mind that a MDI window contains a "ghost" window at DATA oWndClient, so SetParent() should be used this way:
SetParent( oWndChild:hWnd, oWnd:oWndClient:hWnd )
Please let us know the results, thanks
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Yes, correct, I use:Antonio Linares wrote:> 3. Use SetParent() to transform the regular window to a MDI child
Good idea
But, what window are you using as the parent ? Keep in mind that a MDI window contains a "ghost" window at DATA oWndClient, so SetParent() should be used this way:
SetParent( oWndChild:hWnd, oWnd:oWndClient:hWnd )
Please let us know the results, thanks
Code: Select all
SetParent( oWndChild:hWnd, oWndParent:oWndClient:hWnd )
It looks like SetParent() also does not add the oWndParent:oWndClient:aWnd. Or do I need to add it manually to it?
Patrick.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Ok, so only option is to enhance working with SetParent() correct?Antonio Linares wrote:Patrick,
> Maybe it's simpler to modify MDIChild.prg class to accept menu?
We can't as it is a Windows built-in class, and it manages the menu automatically
>
It looks like SetParent() also does not add the oWndParent:oWndClient:aWnd. Or do I need to add it manually to it?
>
yes, add it manually
After SetParent(), can I simply do Aadd( oWndParent:oWndClient:aWnd, oWndChild ) ?
Or should SetParent() take care of?
Patrick
- Patrick Mast
- Posts: 244
- Joined: Sat Mar 03, 2007 8:42 pm
Antonio,
This is a reduced sample that shows the Setparent() coordinatio problem:
This sample shows the coordinates of the window dynamically in the title of the window. The coordinates of the "Regular MDI window" are form base 0,0 from left top of MDI Parent.
The coordinates of the "MDI Child window via Setparent()" are from base 0,0 from left top of Windows Desktop. Also Width and Height are not the same as the "Regular MDI Window"
Thanks for looking into this Antonio.
Patrick
This is a reduced sample that shows the Setparent() coordinatio problem:
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 + " ]"
The coordinates of the "MDI Child window via Setparent()" are from base 0,0 from left top of Windows Desktop. Also Width and Height are not the same as the "Regular MDI Window"
Thanks for looking into this Antonio.
Patrick
- 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
This is what I have now. But clients are asking for a real menu in the MDI child window. And they don't want SDI windows.. (Windows outside the main applications window)Antonio Linares wrote:Why don't you use a toolbar on the MDICHILD window ? The buttons of the toolbar can have dropdown menus.
But we are close no? Once we can set the coordinates correctly?
Patrick
- 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
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: