FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Size of MENUITEM
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Size of MENUITEM
Posted: Fri Oct 18, 2013 09:58 AM

If the text from a menuitem has changed to a longer text, the width from the menu should also be widther! (vis versa on a shorter text!)

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 12:59 PM
Günther,

Unfortunately it is not that simple with the Windows API...

When a MENU is going to be created Windows send us a WM_MEASUREITEM so we report the desired width of the menu:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775925(v=vs.85).aspx

Later on, when we change the text of a menuitem we use the Windows API function ModifyMenu():
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647993(v=vs.85).aspx
in fact Microsoft suggests to use SetMenuItemInfo() as "The ModifyMenu function has been superseded by the SetMenuItemInfo function" but reviewing the params used by SetMenuItemInfo() I don't see any param related to the width of the new text.

And when the menuitem text is changed then Windows sends us a WM_DRAWITEM message:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775923(v=vs.85).aspx
in FiveWin we route that message to METHOD DrawItem( nIdCtl, pItemStruct ) CLASS TWindow.

continues...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 01:08 PM

From METHOD DrawItem( nIdCtl, pItemStruct ) CLASS TWindow we call MenuDrawItem() and we supply the pItemStruct that we receive from Windows.

In such structure there is a value for the right coordinate of the menuitem:
lpdis->rcItem.right

so there we could try to modify it and see if it expands the whole menu size, in example:
lpdis->rcItem.right + 200;
in fact this should be calculated regarding the length of the new text and also the used font.

Will the whole menu repaint just because we modify the size of an item ? I have never tested it.

continues...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 01:11 PM

Günther,

And what it should had been my first answer to you:

How are you changing the text of the menuitem ? Could you provide a small example ? thanks :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 03:24 PM

Antonio, thanks for your explanation! I use ::SetPrompt( cPrompt ). The text is changed, but the lenght are the same as before! Should i use refresh()?

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 03:30 PM

Günther,

Do you want that the menu width changes meanwhile the menu is shown ? Or next time is shown ?

Have you considered to provide the menu items an initial longer width so the next text will fit in ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Size of MENUITEM
Posted: Fri Oct 18, 2013 04:08 PM
Antonio,
Do you want that the menu width changes meanwhile the menu is shown ?

If i set the initial size longer, this shows ugly and also the text become shorter.
Yes on runtime without leaving the window.
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Size of MENUITEM
Posted: Mon Oct 21, 2013 05:55 PM

Günther

I am thinking that changing the menu text is not a good user interface design. Users get used to menu items and changing them would be confusing--it would be to me.

I don't recall ever having seen this on an off-the-shelf program before.

Perhaps it would be better to have two menu items where one item is always disabled? Or, some similar approach rather than changing the text.

Just a thought.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Mon Oct 21, 2013 07:16 PM

Günther,

Could you provide a small PRG example to show how you are doing it ? thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Size of MENUITEM
Posted: Wed Oct 23, 2013 10:10 AM
Antonio, please try this example:

Code (fw): Select all Collapse
local cName := cName1 := "Test" , cName2 := "Long Long Long Long Long Long Long Long Long Test"
    MENU oMenu POPUP 2007
    MENUITEM "Wettbewerb auswählen" ;
        ACTION (cName := if(cName==cName1,cName2,cName1) , oMenu:aMenuItems[2]:setprompt(cName))
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size of MENUITEM
Posted: Wed Oct 23, 2013 04:21 PM

Günther,

Could you provide a complete PRG ?

Because in your code you are changing the text of a menuitem, but that menuitem is only "alive" meanwhile the popup is in use.

Are you using ACTIVATE POPUP ... SAVE ?

Where are you using such popup from ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Size of MENUITEM
Posted: Wed Oct 23, 2013 07:24 PM
Gunther

Este ejemplo funciona correcto para mi
He entendido bien su problema?

This example works right for me
I understand your problem?

Code (fw): Select all Collapse
#include "Fivewin.ch"

Static cName1 


FUNCTION MAIN()

    LOCAL oWnd

    cName1 := "Test"


    DEFINE WINDOW oWnd


    oWnd:bRClicked  := { |nRow, nCol, nFlags| MiMenu( oWnd, nRow, nCol ) }

    ACTIVATE WINDOW oWnd 

    RETURN NIL

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

Function MiMenu( oWnd, nRow, nCol )
Local oMenu
Local oItem1
Local oItem2
Local oItem3
local cName := "Test" 
Local cName2 := "Long Long Long Long Long Long Long Long Long Test"
   
    MENU oMenu POPUP //2007 

    MENUITEM oItem1 PROMPT "Wettbewerb auswählen" ;
        ACTION ( cName1 := if( cName == cName1, cName2, cName ) ,;
                oItem2:SetPrompt( cName1 ) ) //oMenu:aMenuItems[2]:setprompt(cName)  )
    MENUITEM oItem2 PROMPT cName1
    SEPARATOR
    MENUITEM oITem3 PROMPT "Y OTRO" ACTION MsgInfo( Len( oMenu:aMenuItems ) )
    ENDMENU

    ACTIVATE POPUP oMenu WINDOW oWnd  AT 140, 10
Return oMenu

//----------------------------------------------------------------------------//
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: Size of MENUITEM
Posted: Wed Oct 23, 2013 09:17 PM
Antonio,
Where are you using such popup from ?

This popup-menu i use from a button in ribbonbar! And the text from one of the items are changed in accordance of the last selection.
Regards,
Günther
---------------------------------
office@byte-one.com

Continue the discussion