How to set a MENU in MDI Child window?

How to set a MENU in MDI Child window?

Postby Patrick Mast » Thu Sep 27, 2007 5:05 pm

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm


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

Postby Patrick Mast » Thu Sep 27, 2007 6:02 pm

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Thu Sep 27, 2007 8:21 pm

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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Patrick Mast » Fri Sep 28, 2007 5:43 am

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  Expand view  RUN
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.
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Fri Sep 28, 2007 6:52 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Fri Sep 28, 2007 6:55 am

Patrick, but at the end, why do you want to do such a non-standard thing?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Patrick Mast » Fri Sep 28, 2007 8:13 am

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Patrick Mast » Fri Sep 28, 2007 8:22 am

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Patrick Mast » Fri Sep 28, 2007 8:54 am

Antonio,

This is a reduced sample that shows the Setparent() coordinatio problem:

Code: Select all  Expand view  RUN
#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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Fri Sep 28, 2007 8:57 am

Patrick,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Patrick Mast » Fri Sep 28, 2007 9:07 am

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Fri Sep 28, 2007 10:57 am

Patrick,

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

We are going to review it asap
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Patrick Mast » Fri Sep 28, 2007 11:19 am

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
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Fri Sep 28, 2007 10:51 pm

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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Marc Venken and 81 guests