|
-
April 29th, 1999, 09:52 PM
#1
Urgent!! Working with CMenu arrays
I'm having quite a lot of trouble with a program, which uses arrays of popup menus.
It creates global arrays of menus, and later when it needs them, it calls CreatePopupMenu() for as many CMenus as needed, in a loop. Here, It gives a Debug Assertion failure, since there's no check for the validity of the CMenu object. This problem is solved only when I test if the m_hMenu member is not NULL (I've tried IsMenu() and GetSafeHmenu()... both use this fundamental check as one of the conditions, and this one alone works well here).
But when I do this, I later get another Assertion Failure when I try to call AppendMenu with the same menu object. On debugging, I find that the particular object has m_hMenu equal to NULL.
Now what do I do? While creating, I have problems because the menu handle IS NOT NULL, and (if I check that) while appending, I have problems if it IS NULL. Is there a better, more reliable way of creating and filling up arrays of CMenus without these problems? This problem does not happen with the simple menu objects, only with the arrays.
Needless to say, when I build the app in Release mode, it runs, but crashes often. I can't give up arrays altogether, since I don't have time to rewrite the whole program, and I'm actually working on a prewritten program, just trying to fix it.
I mentioned that only as many menus are created as required, so the arrays may not be full, but this is not a simple problem of crossing the bounds or accessing some array element outside of the initialized range... I've checked that. the array indices are well within range and the loops begin and end properly.
Whatever the case, this is urgent and I'll really really be grateful if anyone can help me out.
Thanks,
-Hardeep.
-
April 30th, 1999, 05:44 AM
#2
Re: Urgent!! Working with CMenu arrays
How does the program create its global arrays of menus?
Dave
-
April 30th, 1999, 06:10 AM
#3
Re: Urgent!! Working with CMenu arrays
CMenu menu4[20],menu3[20],men,menu,menu0,menu1[60],menu2[60][100];
// Don't curse me, it's not my code!
Please tell me at the earliest if you have any solution to my problem.
-
April 30th, 1999, 06:21 AM
#4
Re: Urgent!! Working with CMenu arrays
> CMenu menu4[20],menu3[20],men,menu,menu0,menu1[60],menu2[60][100];
Yeuch! That is horrible...
However, I can see no reason why you shouldn't be able to use the array elements successfully when creating popup menus. The CMenu constructor doesn't actually do anything except set the hMenu to NULL, so there's no obvious reason why CreatePopupMenu should fail (unless too many menus are created but not destroyed, and you're running out of resources).
My best guess is that invalid array indices are being used somewhere, because when the menu arrays are named like that, it's very easy to access the wrong array with the wrong index, e.g. menu[1].CreatePopupMenu();
Dave
-
April 30th, 1999, 10:16 PM
#5
That one's fixed, but now there's another problem
Yo Dave!
It was as simple as setting the m_hMenu of each CMenu object to NULL explicitly just before calling CreatePopupMenu(). So now the menus are being created, but there's still a problem. I can't see any submenus. I mean, when I move my mouse over a popup, I get an assertion failure. This one is in the window's OnInitPopupMenu() fn. It calls FromHandle which in turn calss ::GetSubMenu(), in which the foll. assertion fails.
ASSERT((pMenu==NULL)||(pMenu->m_hMenu==hMenu))
For details, look at winmenu.cpp, around line 61.
Just see if u can help me out.
-
May 4th, 1999, 05:03 AM
#6
Re: That one's fixed, but now there's another problem
> This one is in the window's OnInitPopupMenu() fn.
I presume you mean OnInitMenuPopup?
I'm sorry, I don't know what's wrong with the code. Are the menu resources all correctly set up?
Dave
-
May 4th, 1999, 07:20 AM
#7
Re: That one's fixed, but now there's another problem
The resources are definitely correctly set up, 'cause the submenus appear (and so do their submenus, in fact the entire hierarchical structure) as expected in RELEASE mode, but give assertion failures in debug mode. The only reason I'm trying to build it in debug mode is that it crashes often in release mode, and I'm trying to find out why and fix the problem. I'm equally puzzled, believe me, but I have to try. If it'll help, let me tell you that most of the time it crashes, it gives an invalid page fault error, but sometimes it gives a GPF.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|