Creazione menu a runtime

Moderator: Enrico Maria Giordano

Creazione menu a runtime

Postby Patrizio » Wed May 21, 2014 4:38 pm

Ciao a tutti,

ho riscontrato un problema costruendo un menu a runtime.

Piccolo esempio: ogni volta che cliccate su test il programma dovrebbe ricreare il menu. Se controllate con il gestione attività vedrete che il numero di GDI objects utilizzati incrementa ogni volta di 20 unità senza mai liberarsi. Togliendo il riferimento all'immagine invece rimane invariato.

Visto che uso una versione di fivewin vecchia, qualcuno può provare sull'ultima se il problema persiste?

Code: Select all  Expand view

#include "FiveWin.ch"
static oWnd
static oSubMenu
//----------------------------------------------------------------------------//

function Main()
   DEFINE WINDOW oWnd TITLE "Test" MENU BuildMenu()
   @ 2, 2 BUTTON "Test" SIZE 120, 25 OF oWnd ACTION TestMenu()
   ACTIVATE WINDOW oWnd
return nil

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

function BuildMenu()
   local oMenu, oItem, n
   MENU oMenu
      MENUITEM "Test"
      MENU oSubMenu
         FOR n := 1 TO 20
            MENUITEM oItem PROMPT Str(n) ACTION ( MsgInfo("Any action!") ) FILE "c:\fwh\bitmaps\16x16\bitmap.bmp" OF oSubMenu
         NEXT
      ENDMENU
   ENDMENU
return oMenu

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

function TestMenu()
   local oItem, n
   oSubMenu:DelItems()
   FOR n := 1 TO 20
      oSubMenu:Add(TMenuItem():New(Str(n),,,.T.,{||MsgInfo("Any action!")},"c:\fwh\bitmaps\16x16\bitmap.bmp",),.T.)
   NEXT
return

//----------------------------------------------------------------------------//
 
Patrizio
 
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy

Re: Creazione menu a runtime

Postby Antonio Linares » Wed May 21, 2014 4:44 pm

Patrizio,

Please change Class TMenuItem Method Destroy this way:

Code: Select all  Expand view
METHOD Destroy() CLASS TMenuItem

   local nAt := AScan( ::oMenu:aItems,;
                       { | oItem | oItem:nId == ::nId } )
   local nResult                    

   if ValType( ::bAction ) == "O"
      ::bAction:End()
   endif

   if nAt != 0
      ADel( ::oMenu:aItems, nAt )
      ASize( ::oMenu:aItems, Len( ::oMenu:aItems ) - 1 )
   endif

   nResult = RemoveMenu( ::oMenu:hMenu, ::nId, MF_BYCOMMAND )
   
   if ! Empty( ::hBitmap )
      DeleteObject( ::hBitmap )
   endif
   
return nResult      
 
regards, saludos

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

Re: Creazione menu a runtime

Postby Patrizio » Wed May 21, 2014 4:57 pm

Antonio, many thanks: with your change it works very well. :D
Patrizio
 
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy

Re: Creazione menu a runtime

Postby Silvio.Falconi » Fri Jun 06, 2014 6:58 pm

scusa patrizio
mi dici per favore ( magari con un test sample) che cosa fa la modifica perchè non l'ho capita ....grazie
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm


Return to All products support

Who is online

Users browsing this forum: No registered users and 3 guests