Page 1 of 2

How to set a MENU in MDI Child window?

Posted: Thu Sep 27, 2007 5:05 pm
by Patrick Mast
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

Re: How to set a MENU in MDI Child window?

Posted: Thu Sep 27, 2007 5:18 pm
by Enrico Maria Giordano
You can't, as far as I know.

EMG

Re: How to set a MENU in MDI Child window?

Posted: Thu Sep 27, 2007 6:02 pm
by Patrick Mast
EnricoMaria wrote:You can't, as far as I know.
EMG
What I have so far is:
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

Posted: Thu Sep 27, 2007 8:21 pm
by Antonio Linares
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 :-)

Posted: Fri Sep 28, 2007 5:43 am
by Patrick Mast
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 :-)
Yes, correct, I use:

Code: Select all

SetParent( oWndChild:hWnd, oWndParent:oWndClient:hWnd )
Maybe it's simpler to modify MDIChild.prg class to accept menu?

It looks like SetParent() also does not add the oWndParent:oWndClient:aWnd. Or do I need to add it manually to it?

Patrick.

Posted: Fri Sep 28, 2007 6:52 am
by Antonio Linares
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

Posted: Fri Sep 28, 2007 6:55 am
by Enrico Maria Giordano
Patrick, but at the end, why do you want to do such a non-standard thing?

EMG

Posted: Fri Sep 28, 2007 8:13 am
by Patrick Mast
EnricoMaria wrote:Patrick, but at the end, why do you want to do such a non-standard thing?
EMG
On popular request by my clients.

Patrick

Posted: Fri Sep 28, 2007 8:22 am
by Patrick Mast
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
Ok, so only option is to enhance working with SetParent() correct?

After SetParent(), can I simply do Aadd( oWndParent:oWndClient:aWnd, oWndChild ) ?

Or should SetParent() take care of?

Patrick

Posted: Fri Sep 28, 2007 8:54 am
by Patrick Mast
Antonio,

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 + " ]"
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

Posted: Fri Sep 28, 2007 8:57 am
by Antonio Linares
Patrick,

Why don't you use a toolbar on the MDICHILD window ? The buttons of the toolbar can have dropdown menus.

Posted: Fri Sep 28, 2007 9:07 am
by Patrick Mast
Antonio Linares wrote:Why don't you use a toolbar on the MDICHILD window ? The buttons of the toolbar can have dropdown menus.
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)

But we are close no? Once we can set the coordinates correctly?

Patrick

Posted: Fri Sep 28, 2007 10:57 am
by Antonio Linares
Patrick,

> But we are close no? Once we can set the coordinates correctly?

We are going to review it asap

Posted: Fri Sep 28, 2007 11:19 am
by Patrick Mast
Antonio Linares wrote:> But we are close no? Once we can set the coordinates correctly?

We are going to review it asap
Thank you very much Antonio.

Patrick

Posted: Fri Sep 28, 2007 10:51 pm
by Antonio Linares
Patrick,

Your solution looks fine. Why do you care about the coordinates ?

I would suggest to change the "virtual" MDICHILD position when its maximized, but besides that, it seems ok :-)