FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Menu stops working after several hours working in applicatio
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Menu stops working after several hours working in applicatio
Posted: Wed Jan 07, 2009 02:13 PM

Hello,

We are working with fwh808 and after working several hours in our application, the menus stop working. They still appear, but if you click an item there happens nothing. Only closing the application will work, just minimizing won't help. This happens with normal menus and also with contextmenu. Has anyone experienced something similar and found a solution?

Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Menu stops working after several hours working in applicatio
Posted: Wed Jan 07, 2009 06:29 PM
I noticed the same problem but I also noticed that it only happens if
oWnd:SetMenu(oMenu)
is often used.

It this function is not used, the menus will continue to work.

Could that be the reason ?

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Wed Jan 07, 2009 07:34 PM

Gilbert,

Class TMenuItem uses a CLASSDATA nInitId that holds a growing numeric value used to set a numeric ID to every menuitem.

As Michel has pointed, if you keep building menus, again and again, this CLASSDATA could reach an out of range value. To check it from your app, simply do MsgInfo( TMenuItem():New():nInitId )

If there are no running menus in your app, and prior to create a new menu, you could do:

TMenuItem():New():nInitId := 20000

to reset nInitId to its initial value

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Menu stops working after several hours working in applicatio
Posted: Thu Jan 08, 2009 01:57 PM

Antonio,

the problem indeed shows up if the ID of a menu item raises above 32.768 (2^15). In our application there is always running a menu, so it won't be possible to reset this value to 20.000. Is there another option? Maybe raising the value range for the ID's to a higher number?

Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Menu stops working after several hours working in applicatio
Posted: Thu Jan 08, 2009 04:53 PM
Hello Antonio,

I never noticed this problem but could you please explain what you mean by:
if you keep building menus, again and again, t
Thanks in advance
Otto
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Thu Jan 08, 2009 06:26 PM

Gilbert,

Once you build your main menu, please check whats the nInitID value and reset it to that value, not to 20000.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Thu Jan 08, 2009 06:32 PM

Otto,

If you are using a MDI main window and you create different puldown menus for each MDICHILD window, then everytime you create a menu for a MDICHILD window nInitID will be increasing its value, until 32768 and more. And then you may experience such problem, if nInitID is not reset.

Another case is building POPUP menus, again and again, as nInitID will be increased.

This may happen if the application is working for many days without stop.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 03:04 AM

Antonio,

Is there no way to automically decrement the counter when a menu is closed?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 10:24 AM
James,

We could do it and see if there are some side effects.

Gilbert, would you mind to test it and see how it goes ? thanks :-)

This would be the required fix in Class TMenuItem:
   METHOD End() INLINE If( ::hBitmap != 0, DeleteObject( ::hBitmap ),), ::nInitId--
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1446
Joined: Mon Oct 10, 2005 02:38 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 11:37 AM
Antonio Linares wrote:James,

We could do it and see if there are some side effects.

Gilbert, would you mind to test it and see how it goes ? thanks :-)

This would be the required fix in Class TMenuItem:
   METHOD End() INLINE If( ::hBitmap != 0, DeleteObject( ::hBitmap ),), ::nInitId--


Antonio,

No sería mejor colocar algo así en el New():

::nInitId++
If ::nInitId > 32768 .or. IsMenu( ::nInitId )
::nInitId := 20000
while IsMenu( ::nInitId )
::nInitId++
If(::nInitId > 32768, MsgAlert("Salga de la aplicación, sinó los menús no funcionan.","Ea!"),)
end
EndIf
::nId = ::nInitId

Saludos
Carlos G.

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 11:57 AM

Carlos,

La idea es no usar IDs que ya esten en uso

The idea is not to use already in use IDs

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 01:40 PM

Antonio,

>The idea is not to use already in use IDs

Ah, it seems this is not just a counter but rather a unique ID. Is that correct?

If so, then it would seem that decrementing the ID is going to have fatal effects. If the menu being ended is not the last one created then the a duplicate ID will be created when the next menu is created.

I think we would have to use an array that was CLASS DATA and then remove the ID of the menu being ended. Then whenever a new menu is created, the class could look in the array for an unused number, or if not found, then use the next available ID.

I think this would be quick because the array would never be longer than the number of menus in use.

Does this sound reasonable?

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 05:13 PM

James,

You are right, it is not a counter, it is a unique ID, but:

There can be different menuitems using the same IDs, as long as they don't belong to the same menu.
The IDs are used to send a WM_COMMAND with the ID as parameter to its container window or dialog.

Same as we can have controls with the same ID in different dialogs.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 09:37 PM

Can the number be checked and if it gets above a certain size then it can be reset back to 1.

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Menu stops working after several hours working in applicatio
Posted: Fri Jan 09, 2009 11:14 PM

Gale,

1 should not be used as it may conflict with a control ID that you may be using (i.e. a pushbutton OK)

Better use higher values

Anyhow the fix that I have proposed should work fine. Just waiting for Gilbert feedback :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com