How to set a MENU in MDI Child window?

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

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
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 » Sat Sep 29, 2007 7:15 am

Antonio Linares wrote:Your solution looks fine. Why do you care about the coordinates ?
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:I would suggest to change the "virtual" MDICHILD position when its maximized, but besides that, it seems ok :-)
But than the user still can move the window out of the MDI Parent window. But this is not the problem :)

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

//-------------------------------------------------------------//

User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Patrick Mast » Sat Sep 29, 2007 7:33 am

Antonio 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
Hmm, interesting idea :)
But it did not work. :(

This is what I tried:
Code: Select all  Expand view  RUN
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


Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Sat Sep 29, 2007 8:44 am

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 :-)
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 » Sat Sep 29, 2007 9:30 am

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.

Sorry I don't understand, can you give me a sample?

Or better, can you try in my sample?

Thanks!

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Sat Sep 29, 2007 10:33 am

Patrick,

This way you get the right coordinates for the "virtual" MDICHILD window:
Code: Select all  Expand view  RUN
   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 ) + " ]" )
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 » Sat Sep 29, 2007 11:58 am

Antonio Linares wrote:Patrick,

This way you get the right coordinates for the "virtual" MDICHILD window:
Code: Select all  Expand view  RUN
   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 ) + " ]" )


Wow, works perfect!! ;-)

Thanks!!!

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 82 guests