GetMenuString() is not working for sub-menuitems in WINXP

GetMenuString() is not working for sub-menuitems in WINXP

Postby RAMESHBABU » Thu Dec 07, 2006 3:46 am

Hello Friends

The following code is working Ok in Win98 and generating
Menustrings of all main menu and sub-menu items.

Whereas the same code is not working in WinXP and generating
Menustrings only for main menu items.

When bitmaps are used alongwith text in sub-menu items, no
Menustrings (in text) are generated either in Win98 or in WinXp.

This is very essential for me to develop a mechanism to allot
menuitem-wise rights to different users.

I am using these generated menu strings in a tree as shown below and
allowing the superuser to allot rights to his sub-ordinate users by clicking
on the tree items.


Image

Please help.

Regards to you

- Ramesh Babu P


Code: Select all  Expand view  RUN
#include "FiveWin.ch"

******

#define MF_ENABLED       0
#define MF_GRAYED        1
#define MF_DISABLED      2
#define MF_BITMAP        4
#define MF_CHECKED       8
#define MF_POPUP        16  // 0x0010
#define MF_BREAK        64
#define MF_BYPOSITION 1024  // 0x0400
#define MF_SEPARATOR  2048  // 0x0800
#define MF_HELP      16384  // 0x4000
#define MF_HILITE      128  // 0x0080
#define MF_UNHILITE      0
#define MF_OWNERDRAW   256  // 0x0100

******

STATIC oWnd

FUNCTION main()

LOCAL oIco, oBar, oBmp

DEFINE WINDOW oWnd FROM 1, 1 TO 22, 75 ;
       TITLE "Testing to Get Menu Items" ;
       MENU  BuildMenu() ;
       ICON oIco

ACTIVATE WINDOW oWnd ;
       VALID MsgYesNo( "Do you want to quit ?" )

RETURN nil

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

FUNCTION BuildMenu()

LOCAL oMenu
LOCAL n

MENU oMenu
     MENUITEM "Information"
     MENU
       MENUITEM "&About..." ;
       ACTION MsgInfo( FWDESCRIPTION )
       //FILENAME "..\bitmaps\16x16\info.bmp"
       SEPARATOR
       MENUITEM "&End..."  ;
       ACTION oWnd:End() //FILENAME "..\bitmaps\16x16\exit.bmp"
     ENDMENU
     MENUITEM "&Clients"
     MENU
       MENUITEM "&New..." ;
       ACTION ( MsgStop( "New Clients" ),;
                oWnd:Say( 5, 5, "New Clients...", "GR+/G" ) )
       //FILENAME "..\bitmaps\16x16\faces.bmp"
       MENUITEM "&Modify..."  ACTION MsgInfo( "Modif. Clients" )
       //FILENAME "..\bitmaps\edit.bmp"
       MENUITEM "&Delete..."  ACTION MsgAlert( "Del Clients" )
       //FILENAME "..\bitmaps\16x16\delete.bmp"
       SEPARATOR
       MENUITEM "&Browse..."  ACTION MsgInfo( "Browse Clients" )
       //FILENAME "..\bitmaps\16x16\browse.bmp"
     ENDMENU
     MENUITEM "&Utilities"
     MENU
       MENUITEM "&Calculator..." ACTION WinExec( "Calc" )
       //FILENAME "..\bitmaps\16x16\calc.bmp"
       MENUITEM "&Internet..." ;
       ACTION WinExec( "start iexplore www.fivetech.com", 0 )
       //FILENAME "..\bitmaps\16x16\explorer.bmp"
     ENDMENU
ENDMENU

ResBuild( oMenu )

RETURN oMenu

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

FUNCTION ResBuild( oMenu )

LOCAL n
LOCAL hMenu := oMenu:hMenu
LOCAL hSubMenu
LOCAL oSubMenu, oMenuItem

FOR n = 1 to GetMItemCount( hMenu )

    oMenuItem          = TMenuItem():New()
    oMenuItem:nId      = GetMItemID( hMenu, n - 1 )
    oMenuItem:cPrompt  = GetMenuString( hMenu, n - 1, MF_BYPOSITION )
    oMenuItem:cMsg     = ""
    oMenuItem:lChecked = lAnd( GetMenuState( hMenu, n - 1, MF_BYPOSITION ), MF_CHECKED )
    oMenuItem:lActive  = ! lAnd( GetMenuState( hMenu, n - 1,;
                         MF_BYPOSITION ), nOr( MF_DISABLED, MF_GRAYED ) )
    oMenuItem:oMenu    = oMenu
    oMenuItem:hBitmap  = 0
    oMenuItem:lHelp    = .F.
    oMenuItem:lBreak   = lAnd( GetMenuState( hMenu, n - 1, MF_BYPOSITION ), MF_BREAK )

    AAdd( oMenu:aItems, oMenuItem )

?oMenu:aItems[n]:cPrompt

    IF ( hSubMenu := GetSubMenu( hMenu, n - 1 ) ) != 0
       oSubMenu          = TMenu():New()
       oSubMenu:hMenu    = hSubMenu
       oSubMenu:lSysMenu = .F.
       oSubMenu:aItems   = {}
       oMenuItem:bAction = oSubMenu
       ResBuild( oSubMenu )
    ENDIF

NEXT

RETURN nil

**********

User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Thu Dec 07, 2006 5:37 pm

Ramesh,

Do you build your menu from source code or from resources ?

If you build it from source code then you can inspect the Class TMenu DATA aItems to get all the menuitems prompts.

I may not understand what you are trying to do.
regards, saludos

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

Postby RAMESHBABU » Fri Dec 08, 2006 4:52 am

Mr.Antonio

Thank you very much for your attention.

Do you build your menu from source code or from resources ?


As I have shown in the above code, I am building menu from source code.

If you build it from source code then you can inspect the Class TMenu DATA aItems to get all the menuitems prompts.


Using the Resbuild function shown above, I am
getting the menuitems and their submenu items prompts very well in
Win98. But the same code is not working in Winxp !.

Please test the above code in Win98. You will get all menu item prompts
and their sub-menu item prompts very well. But if you test it in WinXp,
you will get only the prompts of main menu items, not submenu-items
prompts.

I need it to work in winxp also with the same result.

I may not understand what you are trying to do.


I am building a mechanism to allot access rights of each menu/sub-menu
items of the application by the super-user to his subordinate users.

To develop such mechanism, I am reading automatically the complete
menu/sub-menu items, once the oMenu is populated in Buildmenu()
function, and building a treeview with all the main/sub-menu items
prompts. When the super-user clicks on a tree item, a pop-up dialog
appears, as shown in the picture, with all sub-ordinate user names, and
permisson check box, allowing the superuser to grant rights of the selected
item.

I believe that I could explain my requirement clearly now.

Regards to you

- Ramesh Babu P

Image
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Fri Dec 08, 2006 5:53 am

Ramesh,
Code: Select all  Expand view  RUN
FUNCTION ResBuild( oMenu )

   LOCAL n

   FOR n = 1 to Len( oMenu:aItems )
      ? oMenu:aItems[n]:cPrompt
     
      if ValType( oMenu:aItems[ n ]:bAction ) == "O"
         ResBuild( oMenu:aItems[ n ]:bAction )
      endif   
   NEXT

RETURN nil
regards, saludos

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

Postby RAMESHBABU » Fri Dec 08, 2006 9:34 am

Hello Mr.Antonio

Your solution has servered my purpose 100% in Win98 and WinXp.

Thank you very much once again.

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 625
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests